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