double gauss_gradients(float *y, int n_points, double mu, double sig,
                       double scale, int which) {
  int i;
  double xi_mu;
  double fi, gi;
  double one_over_two_sig_squared;
  double grad;
  if (sig <= 0.0) {
    printf("Tried to fit Gaussian with non-positive sigma: %e\n", sig);
    return -1.0e30;
  }
  if (scale <= 0.0) {
    printf("Tried to fit Gaussian with non-positive scale factor: %e\n", scale);
    return -1.0e30;
  }
  grad = 0.0;
  one_over_two_sig_squared = 1.0 / 2.0 / sig / sig;
  if (which == 0) {
    for (i = 0; i < n_points; i++) {
      xi_mu = ((double)i) - mu;
      fi = scale * exp(-(xi_mu) * (xi_mu)*one_over_two_sig_squared);
      gi = ((double)(y[i])) - fi;
      grad += ((xi_mu)*fi * gi);
    }
    grad *= (-2.0 / sig / sig);
  } else if (which == 1) {
    for (i = 0; i < n_points; i++) {
      xi_mu = ((double)i) - mu;
      fi = scale * exp(-(xi_mu) * (xi_mu)*one_over_two_sig_squared);
      gi = ((double)(y[i])) - fi;
      grad += ((xi_mu) * (xi_mu)*fi * gi);
    }
    grad *= (-2.0 / sig / sig / sig);
  } else if (which == 2) {
    for (i = 0; i < n_points; i++) {
      xi_mu = ((double)i) - mu;
      fi = scale * exp(-(xi_mu) * (xi_mu)*one_over_two_sig_squared);
      gi = ((double)(y[i])) - fi;
      grad += (fi * gi);
    }
    grad *= (-2.0 / scale);
  } else if (which == 3) {
    for (i = 0; i < n_points; i++) {
      xi_mu = ((double)i) - mu;
      fi = scale * exp(-(xi_mu) * (xi_mu)*one_over_two_sig_squared);
      gi = ((double)(y[i])) - fi;
      grad += (gi * gi);
    }
  } else {
    printf("Didn't choose any of the gradient options in\n");
    printf("gauss_gradients: %i.\n", which);
    return 1.0e30;
  }
  return grad;
}


x86 assembly (clang, -O0):
<gauss_gradients>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
mov    %edx,-0x34(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     1177 <gauss_gradients+0x57>
movsd  -0x28(%rbp),%xmm0
lea    0xec2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xeab(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1566 <gauss_gradients+0x446>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     11aa <gauss_gradients+0x8a>
movsd  -0x30(%rbp),%xmm0
lea    0xec2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0xe78(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1566 <gauss_gradients+0x446>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xe46(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    12a6 <gauss_gradients+0x186>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1285 <gauss_gradients+0x165>
cvtsi2sdl -0x38(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11da <gauss_gradients+0xba>
movsd  0xd83(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    155c <gauss_gradients+0x43c>
cmpl   $0x1,-0x34(%rbp)
jne    138d <gauss_gradients+0x26d>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1367 <gauss_gradients+0x247>
cvtsi2sdl -0x38(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12b7 <gauss_gradients+0x197>
movsd  0xca1(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1557 <gauss_gradients+0x437>
cmpl   $0x2,-0x34(%rbp)
jne    1460 <gauss_gradients+0x340>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1444 <gauss_gradients+0x324>
cvtsi2sdl -0x38(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    139e <gauss_gradients+0x27e>
movsd  0xbc4(%rip),%xmm0
divsd  -0x30(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1552 <gauss_gradients+0x432>
cmpl   $0x3,-0x34(%rbp)
jne    151c <gauss_gradients+0x3fc>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1517 <gauss_gradients+0x3f7>
cvtsi2sdl -0x38(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1471 <gauss_gradients+0x351>
jmp    154d <gauss_gradients+0x42d>
lea    0xb6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xb87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xac5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1566 <gauss_gradients+0x446>
jmp    1552 <gauss_gradients+0x432>
jmp    1557 <gauss_gradients+0x437>
jmp    155c <gauss_gradients+0x43c>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss_gradients>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1221 <gauss_gradients+0xf1>
ucomisd %xmm2,%xmm0
jae    122e <gauss_gradients+0xfe>
mov    %edx,%ebp
cmp    $0x3,%edx
ja     1251 <gauss_gradients+0x121>
mov    %rdi,%rbx
movsd  0xe9e(%rip),%xmm4
divsd  %xmm1,%xmm4
divsd  %xmm1,%xmm4
mov    %ebp,%eax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm4,0x10(%rsp)
jmp    *%rax
movsd  %xmm1,0x28(%rsp)
test   %esi,%esi
jle    1421 <gauss_gradients+0x2f1>
mov    %esi,%r14d
xorpd  %xmm2,%xmm2
xor    %ebp,%ebp
nopl   (%rax)
movsd  %xmm2,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
subsd  %xmm3,%xmm1
movapd %xmm1,0x30(%rsp)
movapd %xmm1,%xmm0
xorpd  0xe4d(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm4,%xmm0
call   1050 <exp@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm3
mulsd  0x20(%rsp),%xmm0
movss  (%rbx,%rbp,4),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm0,%xmm1
mulsd  0x30(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm0,%xmm2
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11b0 <gauss_gradients+0x80>
jmp    1425 <gauss_gradients+0x2f5>
lea    0xe18(%rip),%rdi
movapd %xmm1,%xmm0
jmp    1239 <gauss_gradients+0x109>
lea    0xe3e(%rip),%rdi
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0xdb8(%rip),%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe49(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0xda3(%rip),%xmm0
jmp    1248 <gauss_gradients+0x118>
movsd  %xmm1,0x28(%rsp)
test   %esi,%esi
jle    1435 <gauss_gradients+0x305>
mov    %esi,%r14d
xorpd  %xmm2,%xmm2
xor    %ebp,%ebp
xchg   %ax,%ax
movsd  %xmm2,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
subsd  %xmm3,%xmm1
movapd %xmm1,0x30(%rsp)
movapd %xmm1,%xmm0
xorpd  0xd6d(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm4,%xmm0
call   1050 <exp@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm3
mulsd  0x20(%rsp),%xmm0
movss  (%rbx,%rbp,4),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm0,%xmm1
movapd 0x30(%rsp),%xmm5
mulsd  %xmm5,%xmm5
mulsd  %xmm0,%xmm5
mulsd  %xmm1,%xmm5
addsd  %xmm5,%xmm2
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1290 <gauss_gradients+0x160>
jmp    1439 <gauss_gradients+0x309>
test   %esi,%esi
jle    145c <gauss_gradients+0x32c>
mov    %esi,%r14d
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
subsd  %xmm3,%xmm1
movapd %xmm1,%xmm0
xorpd  0xce3(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm4,%xmm0
call   1050 <exp@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
mulsd  %xmm2,%xmm0
movss  (%rbx,%rbp,4),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1320 <gauss_gradients+0x1f0>
jmp    1460 <gauss_gradients+0x330>
test   %esi,%esi
jle    1475 <gauss_gradients+0x345>
mov    %esi,%r14d
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
subsd  %xmm3,%xmm1
movapd %xmm1,%xmm0
xorpd  0xc53(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm4,%xmm0
call   1050 <exp@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm3
mulsd  0x20(%rsp),%xmm0
movss  (%rbx,%rbp,4),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbp
cmp    %rbp,%r14
jne    13b0 <gauss_gradients+0x280>
jmp    1248 <gauss_gradients+0x118>
xorpd  %xmm2,%xmm2
movsd  0xbe3(%rip),%xmm0
movsd  0x28(%rsp),%xmm1
jmp    144b <gauss_gradients+0x31b>
xorpd  %xmm2,%xmm2
movsd  0xbcf(%rip),%xmm0
movsd  0x28(%rsp),%xmm1
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
jmp    1248 <gauss_gradients+0x118>
xorpd  %xmm1,%xmm1
movsd  0xba8(%rip),%xmm0
divsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
jmp    1248 <gauss_gradients+0x118>
xorpd  %xmm0,%xmm0
jmp    1248 <gauss_gradients+0x118>

LLVM IR (-O0):
@.str = [51 x i8] c"Tried to fit Gaussian with non-positive sigma: %e\0A\00"
@.str.1 = [58 x i8] c"Tried to fit Gaussian with non-positive scale factor: %e\0A\00"
@.str.2 = [46 x i8] c"Didn't choose any of the gradient options in\0A\00"
@.str.3 = [22 x i8] c"gauss_gradients: %i.\0A\00"
define double @gauss_gradients(float* %0, i32 %1, double %2, double %3, double %4, i32 %5) {
%7 = alloca double
%8 = alloca float*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store float* %0, float** %8
store i32 %1, i32* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store i32 %5, i32* %13
%20 = load double, double* %11
%21 = fcmp ole double %20, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %6
%23 = load double, double* %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double %23)
store double -1.000000e+30, double* %7
br label %220
25: ; preds = %6
%26 = load double, double* %12
%27 = fcmp ole double %26, 0.000000e+00
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load double, double* %12
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), double %29)
store double -1.000000e+30, double* %7
br label %220
31: ; preds = %25
store double 0.000000e+00, double* %19
%32 = load double, double* %11
%33 = fdiv double 5.000000e-01, %32
%34 = load double, double* %11
%35 = fdiv double %33, %34
store double %35, double* %18
%36 = load i32, i32* %13
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %81
38: ; preds = %31
store i32 0, i32* %14
br label %39
39: ; preds = %71, %38
%40 = load i32, i32* %14
%41 = load i32, i32* %9
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %74
43: ; preds = %39
%44 = load i32, i32* %14
%45 = sitofp i32 %44 to double
%46 = load double, double* %10
%47 = fsub double %45, %46
store double %47, double* %15
%48 = load double, double* %12
%49 = load double, double* %15
%50 = fneg double %49
%51 = load double, double* %15
%52 = fmul double %50, %51
%53 = load double, double* %18
%54 = fmul double %52, %53
%55 = call double @exp(double %54)
%56 = fmul double %48, %55
store double %56, double* %16
%57 = load float*, float** %8
%58 = load i32, i32* %14
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds float, float* %57, i64 %59
%61 = load float, float* %60
%62 = fpext float %61 to double
%63 = load double, double* %16
%64 = fsub double %62, %63
store double %64, double* %17
%65 = load double, double* %15
%66 = load double, double* %16
%67 = fmul double %65, %66
%68 = load double, double* %17
%69 = load double, double* %19
%70 = call double @llvm.fmuladd.f64(double %67, double %68, double %69)
store double %70, double* %19
br label %71
71: ; preds = %43
%72 = load i32, i32* %14
%73 = add nsw i32 %72, 1
store i32 %73, i32* %14
br label %39
74: ; preds = %39
%75 = load double, double* %11
%76 = fdiv double -2.000000e+00, %75
%77 = load double, double* %11
%78 = fdiv double %76, %77
%79 = load double, double* %19
%80 = fmul double %79, %78
store double %80, double* %19
br label %218
81: ; preds = %31
%82 = load i32, i32* %13
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %131
84: ; preds = %81
store i32 0, i32* %14
br label %85
85: ; preds = %119, %84
%86 = load i32, i32* %14
%87 = load i32, i32* %9
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %122
89: ; preds = %85
%90 = load i32, i32* %14
%91 = sitofp i32 %90 to double
%92 = load double, double* %10
%93 = fsub double %91, %92
store double %93, double* %15
%94 = load double, double* %12
%95 = load double, double* %15
%96 = fneg double %95
%97 = load double, double* %15
%98 = fmul double %96, %97
%99 = load double, double* %18
%100 = fmul double %98, %99
%101 = call double @exp(double %100)
%102 = fmul double %94, %101
store double %102, double* %16
%103 = load float*, float** %8
%104 = load i32, i32* %14
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds float, float* %103, i64 %105
%107 = load float, float* %106
%108 = fpext float %107 to double
%109 = load double, double* %16
%110 = fsub double %108, %109
store double %110, double* %17
%111 = load double, double* %15
%112 = load double, double* %15
%113 = fmul double %111, %112
%114 = load double, double* %16
%115 = fmul double %113, %114
%116 = load double, double* %17
%117 = load double, double* %19
%118 = call double @llvm.fmuladd.f64(double %115, double %116, double %117)
store double %118, double* %19
br label %119
119: ; preds = %89
%120 = load i32, i32* %14
%121 = add nsw i32 %120, 1
store i32 %121, i32* %14
br label %85
122: ; preds = %85
%123 = load double, double* %11
%124 = fdiv double -2.000000e+00, %123
%125 = load double, double* %11
%126 = fdiv double %124, %125
%127 = load double, double* %11
%128 = fdiv double %126, %127
%129 = load double, double* %19
%130 = fmul double %129, %128
store double %130, double* %19
br label %217
131: ; preds = %81
%132 = load i32, i32* %13
%133 = icmp eq i32 %132, 2
br i1 %133, label %134, label %173
134: ; preds = %131
store i32 0, i32* %14
br label %135
135: ; preds = %165, %134
%136 = load i32, i32* %14
%137 = load i32, i32* %9
%138 = icmp slt i32 %136, %137
br i1 %138, label %139, label %168
139: ; preds = %135
%140 = load i32, i32* %14
%141 = sitofp i32 %140 to double
%142 = load double, double* %10
%143 = fsub double %141, %142
store double %143, double* %15
%144 = load double, double* %12
%145 = load double, double* %15
%146 = fneg double %145
%147 = load double, double* %15
%148 = fmul double %146, %147
%149 = load double, double* %18
%150 = fmul double %148, %149
%151 = call double @exp(double %150)
%152 = fmul double %144, %151
store double %152, double* %16
%153 = load float*, float** %8
%154 = load i32, i32* %14
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds float, float* %153, i64 %155
%157 = load float, float* %156
%158 = fpext float %157 to double
%159 = load double, double* %16
%160 = fsub double %158, %159
store double %160, double* %17
%161 = load double, double* %16
%162 = load double, double* %17
%163 = load double, double* %19
%164 = call double @llvm.fmuladd.f64(double %161, double %162, double %163)
store double %164, double* %19
br label %165
165: ; preds = %139
%166 = load i32, i32* %14
%167 = add nsw i32 %166, 1
store i32 %167, i32* %14
br label %135
168: ; preds = %135
%169 = load double, double* %12
%170 = fdiv double -2.000000e+00, %169
%171 = load double, double* %19
%172 = fmul double %171, %170
store double %172, double* %19
br label %216
173: ; preds = %131
%174 = load i32, i32* %13
%175 = icmp eq i32 %174, 3
br i1 %175, label %176, label %211
176: ; preds = %173
store i32 0, i32* %14
br label %177
177: ; preds = %207, %176
%178 = load i32, i32* %14
%179 = load i32, i32* %9
%180 = icmp slt i32 %178, %179
br i1 %180, label %181, label %210
181: ; preds = %177
%182 = load i32, i32* %14
%183 = sitofp i32 %182 to double
%184 = load double, double* %10
%185 = fsub double %183, %184
store double %185, double* %15
%186 = load double, double* %12
%187 = load double, double* %15
%188 = fneg double %187
%189 = load double, double* %15
%190 = fmul double %188, %189
%191 = load double, double* %18
%192 = fmul double %190, %191
%193 = call double @exp(double %192)
%194 = fmul double %186, %193
store double %194, double* %16
%195 = load float*, float** %8
%196 = load i32, i32* %14
%197 = sext i32 %196 to i64
%198 = getelementptr inbounds float, float* %195, i64 %197
%199 = load float, float* %198
%200 = fpext float %199 to double
%201 = load double, double* %16
%202 = fsub double %200, %201
store double %202, double* %17
%203 = load double, double* %17
%204 = load double, double* %17
%205 = load double, double* %19
%206 = call double @llvm.fmuladd.f64(double %203, double %204, double %205)
store double %206, double* %19
br label %207
207: ; preds = %181
%208 = load i32, i32* %14
%209 = add nsw i32 %208, 1
store i32 %209, i32* %14
br label %177
210: ; preds = %177
br label %215
211: ; preds = %173
%212 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%213 = load i32, i32* %13
%214 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %213)
store double 1.000000e+30, double* %7
br label %220
215: ; preds = %210
br label %216
216: ; preds = %215, %168
br label %217
217: ; preds = %216, %122
br label %218
218: ; preds = %217, %74
%219 = load double, double* %19
store double %219, double* %7
br label %220
220: ; preds = %218, %211, %28, %22
%221 = load double, double* %7
ret double %221
}

LLVM IR (-O2):
@.str = [51 x i8] c"Tried to fit Gaussian with non-positive sigma: %e\0A\00"
@.str.1 = [58 x i8] c"Tried to fit Gaussian with non-positive scale factor: %e\0A\00"
@.str.3 = [22 x i8] c"gauss_gradients: %i.\0A\00"
@str = [45 x i8] c"Didn't choose any of the gradient options in\00"
define double @gauss_gradients(float* nocapture %0, i32 %1, double %2, double %3, double %4, i32 %5) {
%7 = fcmp ugt double %3, 0.000000e+00
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double %3)
br label %126
10: ; preds = %6
%11 = fcmp ugt double %4, 0.000000e+00
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), double %4)
br label %126
14: ; preds = %10
%15 = fdiv double 5.000000e-01, %3
%16 = fdiv double %15, %3
switch i32 %5, label %123 [
i32 0, label %29
i32 1, label %25
i32 2, label %21
i32 3, label %17
]
17: ; preds = %14
%18 = icmp sgt i32 %1, 0
br i1 %18, label %19, label %126
19: ; preds = %17
%20 = zext i32 %1 to i64
br label %105
21: ; preds = %14
%22 = icmp sgt i32 %1, 0
br i1 %22, label %23, label %101
23: ; preds = %21
%24 = zext i32 %1 to i64
br label %83
25: ; preds = %14
%26 = icmp sgt i32 %1, 0
br i1 %26, label %27, label %77
27: ; preds = %25
%28 = zext i32 %1 to i64
br label %57
29: ; preds = %14
%30 = icmp sgt i32 %1, 0
br i1 %30, label %31, label %52
31: ; preds = %29
%32 = zext i32 %1 to i64
br label %33
33: ; preds = %31, %33
%34 = phi i64 [ 0, %31 ], [ %50, %33 ]
%35 = phi double [ 0.000000e+00, %31 ], [ %49, %33 ]
%36 = trunc i64 %34 to i32
%37 = sitofp i32 %36 to double
%38 = fsub double %37, %2
%39 = fneg double %38
%40 = fmul double %38, %39
%41 = fmul double %16, %40
%42 = tail call double @exp(double %41)
%43 = fmul double %42, %4
%44 = getelementptr inbounds float, float* %0, i64 %34
%45 = load float, float* %44
%46 = fpext float %45 to double
%47 = fsub double %46, %43
%48 = fmul double %38, %43
%49 = tail call double @llvm.fmuladd.f64(double %48, double %47, double %35)
%50 = add nuw nsw i64 %34, 1
%51 = icmp eq i64 %50, %32
br i1 %51, label %52, label %33
52: ; preds = %33, %29
%53 = phi double [ 0.000000e+00, %29 ], [ %49, %33 ]
%54 = fdiv double -2.000000e+00, %3
%55 = fdiv double %54, %3
%56 = fmul double %55, %53
br label %126
57: ; preds = %27, %57
%58 = phi i64 [ 0, %27 ], [ %75, %57 ]
%59 = phi double [ 0.000000e+00, %27 ], [ %74, %57 ]
%60 = trunc i64 %58 to i32
%61 = sitofp i32 %60 to double
%62 = fsub double %61, %2
%63 = fneg double %62
%64 = fmul double %62, %63
%65 = fmul double %16, %64
%66 = tail call double @exp(double %65)
%67 = fmul double %66, %4
%68 = getelementptr inbounds float, float* %0, i64 %58
%69 = load float, float* %68
%70 = fpext float %69 to double
%71 = fsub double %70, %67
%72 = fmul double %62, %62
%73 = fmul double %72, %67
%74 = tail call double @llvm.fmuladd.f64(double %73, double %71, double %59)
%75 = add nuw nsw i64 %58, 1
%76 = icmp eq i64 %75, %28
br i1 %76, label %77, label %57
77: ; preds = %57, %25
%78 = phi double [ 0.000000e+00, %25 ], [ %74, %57 ]
%79 = fdiv double -2.000000e+00, %3
%80 = fdiv double %79, %3
%81 = fdiv double %80, %3
%82 = fmul double %81, %78
br label %126
83: ; preds = %23, %83
%84 = phi i64 [ 0, %23 ], [ %99, %83 ]
%85 = phi double [ 0.000000e+00, %23 ], [ %98, %83 ]
%86 = trunc i64 %84 to i32
%87 = sitofp i32 %86 to double
%88 = fsub double %87, %2
%89 = fneg double %88
%90 = fmul double %88, %89
%91 = fmul double %16, %90
%92 = tail call double @exp(double %91)
%93 = fmul double %92, %4
%94 = getelementptr inbounds float, float* %0, i64 %84
%95 = load float, float* %94
%96 = fpext float %95 to double
%97 = fsub double %96, %93
%98 = tail call double @llvm.fmuladd.f64(double %93, double %97, double %85)
%99 = add nuw nsw i64 %84, 1
%100 = icmp eq i64 %99, %24
br i1 %100, label %101, label %83
101: ; preds = %83, %21
%102 = phi double [ 0.000000e+00, %21 ], [ %98, %83 ]
%103 = fdiv double -2.000000e+00, %4
%104 = fmul double %103, %102
br label %126
105: ; preds = %19, %105
%106 = phi i64 [ 0, %19 ], [ %121, %105 ]
%107 = phi double [ 0.000000e+00, %19 ], [ %120, %105 ]
%108 = trunc i64 %106 to i32
%109 = sitofp i32 %108 to double
%110 = fsub double %109, %2
%111 = fneg double %110
%112 = fmul double %110, %111
%113 = fmul double %16, %112
%114 = tail call double @exp(double %113)
%115 = fmul double %114, %4
%116 = getelementptr inbounds float, float* %0, i64 %106
%117 = load float, float* %116
%118 = fpext float %117 to double
%119 = fsub double %118, %115
%120 = tail call double @llvm.fmuladd.f64(double %119, double %119, double %107)
%121 = add nuw nsw i64 %106, 1
%122 = icmp eq i64 %121, %20
br i1 %122, label %126, label %105
123: ; preds = %14
%124 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%125 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %126
126: ; preds = %105, %17, %52, %101, %77, %123, %12, %8
%127 = phi double [ -1.000000e+30, %8 ], [ -1.000000e+30, %12 ], [ 1.000000e+30, %123 ], [ %56, %52 ], [ %82, %77 ], [ %104, %101 ], [ 0.000000e+00, %17 ], [ %120, %105 ]
ret double %127
}