List<Instruction> (@NotNull List<Instruction> instructions) { List<Instruction> simplified = new ArrayList<>(); Instruction prev = null; for (Instruction instruction : instructions) { Return ret = tryCast(instruction, Return.class); if (ret != null) { Return merged = mergeReturn(ret, prev); if (merged != null) { simplified.set(simplified.size() - 1, merged); prev = merged; continue; } } else { Check check = tryCast(instruction, Check.class); if (check != null && !check.hasElseBranch()) check.myInstructions = run(check.myInstructions); } simplified.add(instruction); prev = instruction; } return simplified; }