def _camel_case_to_snake_case(s: str) -> str:
    """Converts a CamelCase string to snake_case."""
    out = []
    last_was_uppercase = False
    for c in s:
        if c.isupper():
            out.append(c.lower())
        else:
            if last_was_uppercase and len(out) > 1:
                out[-1] = "_" + out[-1]
            out.append(c)
        last_was_uppercase = c.isupper()
    return "".join(out)