def count_bits_set_kernighan(n: int) -> int:
    """
    https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan

    >>> count_bits_set_kernighan(0b101010101)
    5
    >>> count_bits_set_kernighan(2 << 63)
    1
    >>> count_bits_set_kernighan((2 << 63) - 1)
    64
    """
    c = 0
    while n:
        n &= n - 1
        c += 1
    return c