private static RootStatement graphToStatement(ControlFlowGraph graph) {

    VBStyleCollection<Statement, Integer> stats = new VBStyleCollection<>();
    VBStyleCollection<BasicBlock, Integer> blocks = graph.getBlocks();

    for (BasicBlock block : blocks) {
      stats.addWithKey(new BasicBlockStatement(block), block.id);
    }

    BasicBlock firstblock = graph.getFirst();
    // head statement
    Statement firstst = stats.getWithKey(firstblock.id);
    // dummy exit statement
    DummyExitStatement dummyexit = new DummyExitStatement();

    Statement general;
    if (stats.size() > 1 || firstblock.isSuccessor(firstblock)) { // multiple basic blocks or an infinite loop of one block
      general = new GeneralStatement(firstst, stats, null);
    }
    else { // one straightforward basic block
      RootStatement root = new RootStatement(firstst, dummyexit);
      firstst.addSuccessor(new StatEdge(EdgeType.BREAK, firstst, dummyexit, root));

      return root;
    }

    for (BasicBlock block : blocks) {
      Statement stat = stats.getWithKey(block.id);

      for (BasicBlock succ : block.getSuccessors()) {
        Statement stsucc = stats.getWithKey(succ.id);

        EdgeType type;
        if (stsucc == firstst) {
          type = EdgeType.CONTINUE;
        }
        else if (graph.getFinallyExits().contains(block)) {
          type = EdgeType.FINALLY_EXIT;
          stsucc = dummyexit;
        }
        else if (succ.id == graph.getLast().id) {
          type = EdgeType.BREAK;
          stsucc = dummyexit;
        }
        else {
          type = EdgeType.REGULAR;
        }

        stat.addSuccessor(new StatEdge(type, stat, (type == EdgeType.CONTINUE) ? general : stsucc,
                                       (type == EdgeType.REGULAR) ? null : general));
      }

      // exceptions edges
      for (BasicBlock succex : block.getSuccessorExceptions()) {
        Statement stsuccex = stats.getWithKey(succex.id);

        ExceptionRangeCFG range = graph.getExceptionRange(succex, block);
        if (!range.isCircular()) {
          stat.addSuccessor(new StatEdge(stat, stsuccex, range.getExceptionTypes()));
        }
      }
    }

    general.buildContinueSet();
    general.buildMonitorFlags();
    return new RootStatement(general, dummyexit);
  }
private static RootStatement graphToStatement(ControlFlowGraph graph)