code: def _get_program_gates(prog):
      
      return sorted({i for i in prog if isinstance(i, Gate)}, key=lambda g: g.out())
docs: Get all gate applications appearing in prog.
  
      :param Program prog: The program
      :return: A list of all Gates in prog (without duplicates).
      :rtype: List[Gate]