def count_pairs(arr, target):
    """
    Counts the number of ordered pairs of integers in arr that sum to target.
    """
    comp_count = {}  # Counts the number of times each complement occurs in arr.
    for num in arr:
        comp = target - num
        comp_count[comp] = comp_count.get(comp, 0) + 1
    return sum(comp_count.get(num, 0) for num in arr)