Removed duplicate operand checks
Print only the assignments that actually mean something
Split one code generation from the loop