def simplify_ranges(range_list, level):
    """
    Simplify the HTM ranges in `range_list` by an effective level of
    `level`.
    """
    if not range_list or level <= 0:
        raise ValueError
    mask = (1 << 2 * level) - 1
    i = 0
    j = 0
    while i < len(range_list):
        id_min = range_list[i][0] & ~mask
        id_max = range_list[i][1] | mask
        while i < len(range_list) - 1:
            next_ = range_list[i + 1][0] & ~mask
            if next_ > id_max + 1:
                break
            id_max = range_list[i + 1][1] | mask
            i += 1
        range_list[j] = id_min, id_max
        i += 1
        j += 1
    range_list[:] = range_list[0:j]
