That code is very long and repetitive and many parts do nothing. I suspect it works only if you press the buttons very briefly (<200ms). If you press them for longer than that, the led might flash briefly and stay off, or will flash rapidly until you release the button.
The explanation for why it works, I think, is mostly because you are using the "^=" operator, which means "bitwise exclusive-or and assignment". This operation is being used here to 'toggle' one bit of the variable "leds" which is then sent to the shift register, very similar to my previous suggestion.
For help with that code, post it.