If the program fails without warning and runs different lengths of time between failures, then:
Compile with minimal optimization (–O1). If the program then works, compile only selective routines with higher optimization levels.
Understand that optimizers must make assumptions about the program. Nonstandard coding or constructs can cause problems. Almost no optimizer handles all programs at all levels of optimization. (See 7.6.2 Aliasing and the -xalias Option)