Dead code removal and addition of cycle protection code