fix some bug so we can reenable -O optimization for gcc again