# 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

    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,
                              keyfunc=lambda r: r if type(r) in (int, long) else r.vaddr + r.memsize)
        if pos >= len(self._sorted_list):
            return None
        region = self._sorted_list[pos]
        if region.contains_addr(addr):
            return region
        return None

    def find_region_next_to(self, addr):
        """
        Find the next region after the given address.

        :param int addr: The address to test.
        :return:         The next region that goes after the given address, or None if there is no section after the
                         address,
        :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


    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,
                              keyfunc=lambda r: r if type(r) in (int, long) else r.vaddr + r.memsize)
        if pos >= len(self._sorted_list):
            return None
        region = self._sorted_list[pos]
        if region.contains_addr(addr):
            return region
        return None

    def find_region_next_to(self, addr):
        """
        Find the next region after the given address.

        :param int addr: The address to test.
        :return:         The next region that goes after the given address, or None if there is no section after the
                         address,
        :rtype: Region or None
        """


        pos = key_bisect_find(self._sorted_list, addr,