-Ofast breaks isnan so we use -O3 instead