2560 Behaving strangely. What am I doing wrong?

Here is a test case.

http://pastebin.com/HSp6b0xR

note that in loop() there are two pieces of code with //* piece_a // piece_b /// around them. each is one of the cases. piece_a does not work. piece_b does work.