input: Write a function to count the number of pairs in an array that sum to a given value x. The function should use a two-pointer approach to efficiently find the pairs.
  
  assert count_pairs([3, 4, 5, 1, 2], 6) == 1
  assert count_pairs([1, 9, 5, 0, 20, -4, 12, 16, 7], 12) == 2
  assert count_pairs([1, 2, 3, 4, 5, 6], 8) == 2
  assert count_pairs([1, 3, 9, 2], 5) == 1
  assert count_pairs([], 5) == 0
output: def count_pairs(arr, x):
      arr.sort()
      left, right = 0, len(arr) - 1
      count = 0
      while left < right:
          if arr[left] + arr[right] == x:
              count += 1
              left += 1
              right -= 1
          elif arr[left] + arr[right] < x:
              left += 1
          else:
              right -= 1
      return count