public static void removeDeadBlocks(ControlFlowGraph graph) {
    LinkedList<BasicBlock> stack = new LinkedList<>();
    Set<BasicBlock> setStacked = new HashSet<>();

    stack.add(graph.getFirst());
    setStacked.add(graph.getFirst());

    while (!stack.isEmpty()) {
      BasicBlock block = stack.removeFirst();

      List<BasicBlock> successors = new ArrayList<>(block.getSuccessors());
      successors.addAll(block.getSuccessorExceptions());

      for (BasicBlock successor : successors) {
        if (!setStacked.contains(successor)) {
          stack.add(successor);
          setStacked.add(successor);
        }
      }
    }

    Set<BasicBlock> setAllBlocks = new HashSet<>(graph.getBlocks());
    setAllBlocks.removeAll(setStacked);

    for (BasicBlock block : setAllBlocks) {
      graph.removeBlock(block);
    }
  }
public static void removeDeadBlocks(ControlFlowGraph graph)