double gaussian_cache(double dm, double scatter, double *g_cache) {
  int b;
  dm = dm / scatter * 256 + 2048;
  b = dm;
  if (b < 0 || b >= 4097 - 1)
    return 0;
  dm -= b;
  return (g_cache[b] + dm * (g_cache[b + 1] - g_cache[b])) / scatter;
}


x86 assembly (clang, -O0):
<gaussian_cache>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xedc(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xed8(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1158 <gaussian_cache+0x58>
cmpl   $0x1000,-0x24(%rbp)
jl     1165 <gaussian_cache+0x65>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11bb <gaussian_cache+0xbb>
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian_cache>:
divsd  %xmm1,%xmm0
mulsd  0xef4(%rip),%xmm0
addsd  0xef4(%rip),%xmm0
cvttsd2si %xmm0,%eax
xorpd  %xmm2,%xmm2
cmp    $0xfff,%eax
ja     114b <gaussian_cache+0x4b>
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
subsd  %xmm2,%xmm0
mov    %eax,%eax
movsd  (%rdi,%rax,8),%xmm3
movsd  0x8(%rdi,%rax,8),%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm3,%xmm2
divsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @gaussian_cache(double %0, double %1, double* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double* %2, double** %7
%9 = load double, double* %5
%10 = load double, double* %6
%11 = fdiv double %9, %10
%12 = call double @llvm.fmuladd.f64(double %11, double 2.560000e+02, double 2.048000e+03)
store double %12, double* %5
%13 = load double, double* %5
%14 = fptosi double %13 to i32
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i32, i32* %8
%19 = icmp sge i32 %18, 4096
br i1 %19, label %20, label %21
20: ; preds = %17, %3
store double 0.000000e+00, double* %4
br label %47
21: ; preds = %17
%22 = load i32, i32* %8
%23 = sitofp i32 %22 to double
%24 = load double, double* %5
%25 = fsub double %24, %23
store double %25, double* %5
%26 = load double*, double** %7
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double, double* %5
%32 = load double*, double** %7
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %32, i64 %35
%37 = load double, double* %36
%38 = load double*, double** %7
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = fsub double %37, %42
%44 = call double @llvm.fmuladd.f64(double %31, double %43, double %30)
%45 = load double, double* %6
%46 = fdiv double %44, %45
store double %46, double* %4
br label %47
47: ; preds = %21, %20
%48 = load double, double* %4
ret double %48
}

LLVM IR (-O2):
define double @gaussian_cache(double %0, double %1, double* nocapture %2) {
%4 = fdiv double %0, %1
%5 = tail call double @llvm.fmuladd.f64(double %4, double 2.560000e+02, double 2.048000e+03)
%6 = fptosi double %5 to i32
%7 = icmp ugt i32 %6, 4095
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = sitofp i32 %6 to double
%10 = fsub double %5, %9
%11 = zext i32 %6 to i64
%12 = getelementptr inbounds double, double* %2, i64 %11
%13 = load double, double* %12
%14 = add nuw nsw i32 %6, 1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds double, double* %2, i64 %15
%17 = load double, double* %16
%18 = fsub double %17, %13
%19 = tail call double @llvm.fmuladd.f64(double %10, double %18, double %13)
%20 = fdiv double %19, %1
br label %21
21: ; preds = %3, %8
%22 = phi double [ %20, %8 ], [ 0.000000e+00, %3 ]
ret double %22
}