Delay is calculated wrong in embedded C
The delay function is broken.

First of all, you should avoid writing delays with busy-loops. Such delays are unstable, unreliable and non-portable. They create a tight coupling to the system clock frequency. Also in case of sleep modes, they make the CPU consume current needlessly. Always use on-chip hardware timers instead. 

Now if you insist on writing such a delay loop, you must declare the actual loop iterator volatile. Otherwise the compiler might remove the whole loop, since it contains no side effects. 
It isn't enough to make the variable in the caller volatile, since the function is using a local copy of the passed variable. The variable inside the function must be volatile. 
Another issue here is the lack of switch de-bouncing. You can only get away without it if you have a hardware RC filter on the switch. 
Also, does the switch have an external pull resistor or does it assume that you enable one internally? You need to share the schematics.