code: def collapseDuplicateSubtrees(ast):
      
      seen = {}
      aliases = []
      for a in ast.allOf('op'):
          if a in seen:
              target = seen[a]
              a.astType = 'alias'
              a.value = target
              a.children = ()
              aliases.append(a)
          else:
              seen[a] = a
      # Set values and registers so optimizeTemporariesAllocation
      # doesn't get confused
      for a in aliases:
          while a.value.astType == 'alias':
              a.value = a.value.value
      return aliases
docs: Common subexpression elimination.