Overflow errors in optimized code