nodes: 0, module; 1, function_definition; 2, function_name:get_classical_addresses_from_program; 3, parameters; 4, type; 5, block; 6, identifier:program; 7, generic_type; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# Required to use the `classical_reg.address` int attribute.; 12, comment:# See https://github.com/rigetti/pyquil/issues/388.; 13, for_statement; 14, comment:# flatten duplicates; 15, for_statement; 16, return_statement; 17, identifier:Dict; 18, type_parameter; 19, comment:"""
      Returns a sorted list of classical addresses found in the MEASURE instructions in the program.
  
      :param Program program: The program from which to get the classical addresses.
      :return: A mapping from memory region names to lists of offsets appearing in the program.
      """; 20, assignment; 21, assignment; 22, identifier:instr; 23, identifier:program; 24, block; 25, pattern_list; 26, call; 27, block; 28, identifier:flattened_addresses; 29, type; 30, type; 31, identifier:addresses; 32, type; 33, call; 34, identifier:flattened_addresses; 35, dictionary; 36, if_statement; 37, identifier:k; 38, identifier:v; 39, attribute; 40, argument_list; 41, expression_statement; 42, expression_statement; 43, expression_statement; 44, identifier:str; 45, generic_type; 46, generic_type; 47, identifier:defaultdict; 48, argument_list; 49, boolean_operator; 50, block; 51, identifier:addresses; 52, identifier:items; 53, assignment; 54, call; 55, assignment; 56, identifier:List; 57, type_parameter; 58, identifier:Dict; 59, type_parameter; 60, identifier:list; 61, call; 62, attribute; 63, expression_statement; 64, identifier:reduced_list; 65, call; 66, attribute; 67, argument_list; 68, subscript; 69, identifier:reduced_list; 70, type; 71, type; 72, type; 73, identifier:isinstance; 74, argument_list; 75, identifier:instr; 76, identifier:classical_reg; 77, call; 78, identifier:list; 79, argument_list; 80, identifier:reduced_list; 81, identifier:sort; 82, identifier:flattened_addresses; 83, identifier:k; 84, identifier:int; 85, identifier:str; 86, generic_type; 87, identifier:instr; 88, identifier:Measurement; 89, attribute; 90, argument_list; 91, call; 92, identifier:List; 93, type_parameter; 94, subscript; 95, identifier:append; 96, attribute; 97, identifier:set; 98, argument_list; 99, type; 100, identifier:addresses; 101, attribute; 102, attribute; 103, identifier:offset; 104, identifier:v; 105, identifier:int; 106, attribute; 107, identifier:name; 108, identifier:instr; 109, identifier:classical_reg; 110, identifier:instr; 111, identifier:classical_reg
code: def get_classical_addresses_from_program(program) -> Dict[str, List[int]]:
      """
      Returns a sorted list of classical addresses found in the MEASURE instructions in the program.
  
      :param Program program: The program from which to get the classical addresses.
      :return: A mapping from memory region names to lists of offsets appearing in the program.
      """
      addresses: Dict[str, List[int]] = defaultdict(list)
      flattened_addresses = {}
  
      # Required to use the `classical_reg.address` int attribute.
      # See https://github.com/rigetti/pyquil/issues/388.
      for instr in program:
          if isinstance(instr, Measurement) and instr.classical_reg:
              addresses[instr.classical_reg.name].append(instr.classical_reg.offset)
  
      # flatten duplicates
      for k, v in addresses.items():
          reduced_list = list(set(v))
          reduced_list.sort()
          flattened_addresses[k] = reduced_list
  
      return flattened_addresses