Enable -O2 for GCC and fix resulting warnings