def _get_program_gates(prog):
    """
    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]
    """
    return sorted({i for i in prog if isinstance(i, Gate)}, key=lambda g: g.out())