public boolean prune(@Nonnull ClassNode node, @Nonnull MethodNode method) throws TransformationException {
		InsnList instructions = method.instructions;
		if (instructions == null || instructions.size() == 0)
			return false;
		boolean dirty = false;
		try {
			// Compute which instructions are visited by walking the method's control flow.
			Set<AbstractInsnNode> visited = Collections.newSetFromMap(new IdentityHashMap<>());
			List<AbstractInsnNode> flowStarts = new ArrayList<>();
			flowStarts.add(instructions.getFirst());
			for (TryCatchBlockNode block : method.tryCatchBlocks)
				flowStarts.add(block.handler);
			visit(visited, flowStarts);

			// Prune any instructions not visited.
			int end = instructions.size() - 1;
			for (int i = end; i >= 0; i--) {
				AbstractInsnNode insn = instructions.get(i);
				if (!visited.contains(insn) || insn.getOpcode() == NOP) {
					// Don't prune the tail label even if it is "dead" because the last method instruction
					// is terminal like 'return' or 'athrow'. The label will just get added back automatically
					// and cause the transform process to loop on repeat.
					if (i == end && insn.getType() == AbstractInsnNode.LABEL)
						continue;

					instructions.remove(insn);

					// Remove try-catch ranges if their labels are within the dead-code range.
					if (insn.getType() == AbstractInsnNode.LABEL)
						method.tryCatchBlocks.removeIf(tryCatch -> {
							if (insn == tryCatch.start) return true;
							if (insn == tryCatch.end) return true;
							return insn == tryCatch.handler;
						});

					// Mark as dirty.
					dirty = true;
				}
			}

			// Ensure that after dead code removal (or any other transformers not cleaning up)
			// that all variables have labels that reside in the method code list.
			List<LocalVariableNode> variables = method.localVariables;
			if (variables != null && variables.stream().anyMatch(l -> !instructions.contains(l.start) || !instructions.contains(l.end))) {
				fixMissingVariableLabels(method);
				dirty = true;
			}
		} catch (Throwable t) {
			throw new TransformationException("Error encountered when removing dead code", t);
		}
		return dirty;
	}
A transformer that removes dead code.

@author Matt Coley
recaf-core/src/main/java/software/coley/recaf/services/deobfuscation/transform/generic/DeadCodeRemovingTransformer.java