import re


def camel_to_underline(name):
    """
    Converts CamelCase to underline. As for example CamelCase --> camel_case.

    :param name: (str) Name to be converted
    :return: Converted name in lower caps and underline
    :rtype: str
    """
    s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
    return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()