https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85593
--- Comment #4 from Austin Morton <austinpmorton at gmail dot com> --- In my particular case I was able to work around the issue by removing the naked attribute and using extended assembly with a clobbers list. The resulting code is nearly identical (allowing GCC to generate the correct pro/epilog instead of hand writing it), and gcc correctly allocates R4 instead of R3. This still feels like a bug in GCC. In the example I gave, if you compiled the naked function in a separate C file and linked them it would generate the correct code. The issue is that GCC is able to "see" the naked function and is performing optimizations that it shouldn't as a result. I believe that GCC should treat naked functions as opaque as far as optimizations are concerned. At the very least, there should be a note about this kind of issue included in the documentation of the naked attribute.