# Path: cle/utils.py
# def key_bisect_find(lst, item, lo=0, hi=None, keyfunc=lambda x: x):
#     if lo < 0:
#         raise ValueError('lo must be non-negative')
#     if hi is None:
#         hi = len(lst)
#     while lo < hi:
#         mid = (lo + hi) // 2
#         if keyfunc(lst[mid]) <= keyfunc(item):
#             lo = mid + 1
#         else:
#             hi = mid
#     return lo
# 
# def key_bisect_insort_left(lst, item, lo=0, hi=None, keyfunc=lambda x: x):
#     if lo < 0:
#         raise ValueError('lo must be non-negative')
#     if hi is None:
#         hi = len(lst)
#     while lo < hi:
#         mid = (lo + hi) // 2
#         if keyfunc(lst[mid]) < keyfunc(item):
#             lo = mid + 1
#         else:
#             hi = mid
#     lst.insert(lo, item)


from typing import List, Optional, TYPE_CHECKING
    from .. import Region
from ..utils import key_bisect_find, key_bisect_insort_left
        from .elf.regions import ELFSection
        """
        Append a new Region instance into the list.

        :param Region region: The region to append.
        """
        self._list.append(region)

        if self._is_region_mapped(region):
            key_bisect_insort_left(self._sorted_list, region, keyfunc=lambda r: r.vaddr)

    def remove(self, region: 'Region') -> None:
        """
        Remove an existing Region instance from the list.

        :param Region region: The region to remove.
        """
        if self._is_region_mapped(region):
            self._sorted_list.remove(region)
        self._list.remove(region)

    def find_region_containing(self, addr) -> Optional['Region']:
        """
        Find the region that contains a specific address. Returns None if none of the regions covers the address.

        :param addr:    The address.
        :type addr:     int
        :return:        The region that covers the specific address, or None if no such region is found.
        :rtype:         Region or None
        """


# Path: cle/utils.py
# def key_bisect_find(lst, item, lo=0, hi=None, keyfunc=lambda x: x):
#     if lo < 0:
#         raise ValueError('lo must be non-negative')
#     if hi is None:
#         hi = len(lst)
#     while lo < hi:
#         mid = (lo + hi) // 2
#         if keyfunc(lst[mid]) <= keyfunc(item):
#             lo = mid + 1
#         else:
#             hi = mid
#     return lo
# 
# def key_bisect_insort_left(lst, item, lo=0, hi=None, keyfunc=lambda x: x):
#     if lo < 0:
#         raise ValueError('lo must be non-negative')
#     if hi is None:
#         hi = len(lst)
#     while lo < hi:
#         mid = (lo + hi) // 2
#         if keyfunc(lst[mid]) < keyfunc(item):
#             lo = mid + 1
#         else:
#             hi = mid
#     lst.insert(lo, item)


# Path: cle/backends/regions.py
from typing import List, Optional, TYPE_CHECKING
    from .. import Region
from ..utils import key_bisect_find, key_bisect_insort_left
        from .elf.regions import ELFSection

        """
        Append a new Region instance into the list.

        :param Region region: The region to append.
        """
        self._list.append(region)

        if self._is_region_mapped(region):
            key_bisect_insort_left(self._sorted_list, region, keyfunc=lambda r: r.vaddr)

    def remove(self, region: 'Region') -> None:
        """
        Remove an existing Region instance from the list.

        :param Region region: The region to remove.
        """
        if self._is_region_mapped(region):
            self._sorted_list.remove(region)
        self._list.remove(region)

    def find_region_containing(self, addr) -> Optional['Region']:
        """
        Find the region that contains a specific address. Returns None if none of the regions covers the address.

        :param addr:    The address.
        :type addr:     int
        :return:        The region that covers the specific address, or None if no such region is found.
        :rtype:         Region or None
        """


        pos = key_bisect_find(self._sorted_list, addr,