I have always been told that compiler is sufficient smart to eliminate dead code. Much of the code that I am writing has a lot of information known at compile time but the c
Your example focuses on dead code elimination inside functions.
Another type of dead code elimination, is removal of entire unused symbols (functions or variables) which can be achieved with:
-fdata-sections -ffunction-sections -Wl,--gc-sections
as mentioned at: How to remove unused C/C++ symbols with GCC and ld?
These flags are not enabled in the various GCC -O levels (-O1, -O2, etc) by default.