And then that code you wrote now silently becomes deadly a few years down the line.
(That said, I think TheLoneWolfling is being too strong with his/her claims. You can get modern compilers to avoid dangerous optimizations; it's just not for the faint of heart.)
I am saying that it's impossible to do so and remain in the realm of portable C / C++.
There is a distinction.
And as for the second part... Meh. I don't see any optimizations that hard-coding calling something named "memcpy" (or whatever) does that cannot be enabled by looking at the actual code that gets linked. Albeit with more difficulty.
Remember: there is nothing that specifies that C / C++ needs to be compiled.
Also: you could have said the same twenty years ago about many of the optimizations that currently compilers do.
(IoT security is doom for other reasons though, mostly UI, updatability and cloud services)