def camel_to_snake(camel):
    """Convert camelCase to snake_case."""
    ret = []
    last_lower = False
    for char in camel:
        current_upper = char.upper() == char
        if current_upper and last_lower:
            ret.append('_')
            ret.append(char.lower())
        else:
            ret.append(char.lower())
        last_lower = not current_upper
    return ''.join(ret)
