void (List<@Nullable Statement> nodes, @NotNull List<List<Integer>> edgeIndices) { for (int i = 0; i < edgeIndices.size() - 1; i++) { for (int j = edgeIndices.size() - 1; j > i; j--) { if (edgeIndices.get(j - 1).get(0) > edgeIndices.get(j).get(0)) { edgeIndices.set(j, edgeIndices.set(j - 1, edgeIndices.get(j))); nodes.set(j, nodes.set(j - 1, nodes.get(j))); } } } for (int index = 0; index < nodes.size(); index++) { Statement node = nodes.get(index); if (node == null) continue; HashSet<Statement> nodePredecessors = new HashSet<>(node.getNeighbours(EdgeType.REGULAR, EdgeDirection.BACKWARD)); nodePredecessors.remove(first); if (nodePredecessors.isEmpty()) continue; // assumption: at most one predecessor node besides the head. May not hold true for obfuscated code. Statement predecessor = nodePredecessors.iterator().next(); for (int j = 0; j < nodes.size(); j++) { if (j != (index - 1) && nodes.get(j) == predecessor) { nodes.add(j + 1, node); edgeIndices.add(j + 1, edgeIndices.get(index)); if (j > index) { nodes.remove(index); edgeIndices.remove(index); index--; } else { nodes.remove(index + 1); edgeIndices.remove(index + 1); } break; } } } }