def mask_address(ip, prefix):
    """
    Reduce a 32-bit integer to its first prefix bits
    :param ip: 32-bit integer
    :param prefix: integer, 0 <= prefix <= 32
    :return: integer corresponding to ip where bits [prefix+1..32] are 0
    """
    return ip & (0xffffffff << (32 - prefix))