arduino code works slower than arduino code generated by ldmicro

Use unsigned integers for time variables, not signed values. I see you use type long which will take almost 24 days to affect the sketch.

I don't think that you can/are debouncing all the switches with the code I see.