Why does the compiler allocate more than needed in the stack?

Solution 1:

Compilers may indeed reserve additional memory for themselves.

Gcc has a flag, -mpreferred-stack-boundary, to set the alignment it will maintain. According to the documentation, the default is 4, which should produce 16-byte alignment, which needed for SSE instructions.

As VermillionAzure noted in a comment, you should provide your gcc version and compile-time options (use gcc -v to show these).

Solution 2:

Because you haven't enabled optimization.

Without optimization, the compiler makes no attempt to minimize the amount of space or time it needs for anything in the generated code -- it just generates code in the most straight-forward way possible.

Add -O2 (or even just -O1) or -Os if you want the compiler to produce decent code.