The Arm compiler 6.x does not support changing optimization options within a C-source file. Instead these must be set on a per-file basis using command-line options. If you have functions that absolutely need different optimization levels, you need to put them into different C-source files.