private static void addToReversePostOrderListIterative(BasicBlock root, List<? super BasicBlock> lst) {

    LinkedList<BasicBlock> stackNode = new LinkedList<>();
    LinkedList<Integer> stackIndex = new LinkedList<>();

    Set<BasicBlock> setVisited = new HashSet<>();

    stackNode.add(root);
    stackIndex.add(0);

    while (!stackNode.isEmpty()) {

      BasicBlock node = stackNode.getLast();
      int index = stackIndex.removeLast();

      setVisited.add(node);

      List<BasicBlock> lstSuccs = new ArrayList<>(node.getSuccs());
      lstSuccs.addAll(node.getSuccExceptions());

      for (; index < lstSuccs.size(); index++) {
        BasicBlock succ = lstSuccs.get(index);

        if (!setVisited.contains(succ)) {
          stackIndex.add(index + 1);

          stackNode.add(succ);
          stackIndex.add(0);

          break;
        }
      }

      if (index == lstSuccs.size()) {
        lst.add(0, node);

        stackNode.removeLast();
      }
    }
  }
@param mapInstrBlocks mapping of instruction -> block
src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java