Raymond Chen has this to say on his recent post on code optimizations... Obvious optimizations - one that begs to be optimized - tend to be "de-optimizations" if you consider all that need to be considered...
I'm sure you must have come across / even coded optimizations you were embarrassed about after you learnt more...
Care to share?
My favourite is
Yes, all of a sudden, that's magically faster!!
</sarcasm>
My favorite example would be the XOR swap algorithm:
Yes, it uses no temporary variable, and can usually be done in three processor cycles, but it sure isn't obvious what it does!
See also this question.
Duff's Device, which is so twisted that it looks like it shouldn't even compile in ISO C: