Earlier quoted context omitted.
Here's my fix: for (i = 0; i This way, for every row/column, the loop acts on all but the last cell, which is actually the first cell of some other column/row.
I feel like for the each side you could actually handle two items per iteration, one forwards _and_ one backwards. That way your iteration count could be halved.
And furthermore why split in two? Why not split the range into three sections, or four, or N and completely unroll the loop?
Probably not a good-tasting construct at all.