After some research, I see that -g disables some optimizations even with -O3, so disabling it again.