import ctypes
from typing import Optional


def _aligned_ptr_offset_in_object(obj: object, referent: object) -> Optional[int]:
    """Return the byte offset in the C representation of *obj* (an
    arbitrary Python object) at which is found a naturally-aligned
    pointer that points to *referent*.  If *search_for*
    can't be found, return None.
    """

    size = obj.__sizeof__()
    arraytype = ctypes.c_size_t * (size // ctypes.sizeof(ctypes.c_size_t))
    for idx, value in enumerate(arraytype.from_address(id(obj))):
        if value == id(referent):
            return idx * ctypes.sizeof(ctypes.c_size_t)
    return None