code: def _dump_graph(outputs):
      fan_out = collections.defaultdict(int)
      cand_funcs = []
  
      def add_cand_to_check(cands):
          for cand in cands:
              x = cand.creator
              if x is None:
                  continue
              if x not in fan_out:
                  # `len(fan_out)` is in order to avoid comparing `x`
                  heapq.heappush(cand_funcs, (-x.rank, len(fan_out), x))
              fan_out[x] += 1
  
      add_cand_to_check(outputs)
      while cand_funcs:
          _, _, func = heapq.heappop(cand_funcs)
          assert isinstance(func, _function_types)
          add_cand_to_check(func.inputs)
  
      ret = []
      cand_funcs = []
      seen_set = set()
  
      def add_cand(cands):
          cands = [
              cand.creator for cand in cands if cand.creator is not None
          ]
          for x in cands:
              if x in seen_set:
                  continue
              order = 1
              if fan_out[x] == 1 and len(cands) == 1:
                  order = -len(seen_set)
              # Negate since heapq is min-heap
              # `len(seen_set)` is in order to avoid comparing `x`
              heapq.heappush(
                  cand_funcs, (order, -x.rank, -len(seen_set), x)
              )
              seen_set.add(x)
  
      add_cand(outputs)
      while cand_funcs:
          _, _, _, func = heapq.heappop(cand_funcs)
          ret.append(func)
          add_cand(func.inputs)
  
      return ret[::-1]
  
imports: import collections
  import heapq
  import os
  import numpy
  import six
  import chainer
  from chainer import function
  from chainer import function_node
  from chainer.links.caffe.protobuf3 import caffe_pb2
  from chainer import variable
label_desc: Use image node_id 2 for calling a global function with example usage: _dump_graph(outputs) and returns: ret