double ComputeMarginalizedLikelihood(double value, double mean1, double mean2,
                                     double var1, double var2,
                                     unsigned int nof_intervals) {
  double lh, tmean, tvar, delta, step;
  step = 1.0 / (double)nof_intervals;
  lh = 0;
  for (delta = 0.0; delta <= 1.0; delta += step) {
    tmean = delta * mean1 + (1 - delta) * mean2;
    tvar = ((delta) * (delta)) * var1 + ((1 - delta) * (1 - delta)) * var2;
    lh += ComputeGaussianLikelihood(value, tmean, tvar) * step;
  }
  return (lh);
}


x86 assembly (clang, -O0):
<ComputeMarginalizedLikelihood>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
mov    %edi,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xebc(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe9b(%rip),%xmm0
ucomisd -0x50(%rbp),%xmm0
jb     121d <ComputeMarginalizedLikelihood+0x10d>
movsd  -0x50(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xe7e(%rip),%xmm1
subsd  -0x50(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  0xe50(%rip),%xmm1
subsd  -0x50(%rbp),%xmm1
movsd  0xe43(%rip),%xmm3
subsd  -0x50(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
mov    $0x3,%al
call   1030 <ComputeGaussianLikelihood@plt>
cvtsi2sd %eax,%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    115d <ComputeMarginalizedLikelihood+0x4d>
movsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputeMarginalizedLikelihood>:
sub    $0x48,%rsp
movsd  %xmm4,0x40(%rsp)
movsd  %xmm3,0x38(%rsp)
movsd  %xmm2,0x30(%rsp)
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x20(%rsp)
mov    %edi,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xebc(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  0xe8c(%rip),%xmm0
subsd  %xmm1,%xmm0
movapd %xmm0,%xmm2
mulsd  0x30(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  0x28(%rsp),%xmm1
addsd  %xmm2,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm2,%xmm2
mulsd  %xmm0,%xmm0
mulsd  0x40(%rsp),%xmm0
mulsd  0x38(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  0x20(%rsp),%xmm0
mov    $0x3,%al
call   1030 <ComputeGaussianLikelihood@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  0xdfe(%rip),%xmm2
ucomisd %xmm1,%xmm2
jae    1160 <ComputeMarginalizedLikelihood+0x50>
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @ComputeMarginalizedLikelihood(double %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store i32 %5, i32* %12
%18 = load i32, i32* %12
%19 = uitofp i32 %18 to double
%20 = fdiv double 1.000000e+00, %19
store double %20, double* %17
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %16
br label %21
21: ; preds = %52, %6
%22 = load double, double* %16
%23 = fcmp ole double %22, 1.000000e+00
br i1 %23, label %24, label %56
24: ; preds = %21
%25 = load double, double* %16
%26 = load double, double* %8
%27 = load double, double* %16
%28 = fsub double 1.000000e+00, %27
%29 = load double, double* %9
%30 = fmul double %28, %29
%31 = call double @llvm.fmuladd.f64(double %25, double %26, double %30)
store double %31, double* %14
%32 = load double, double* %16
%33 = load double, double* %16
%34 = fmul double %32, %33
%35 = load double, double* %10
%36 = load double, double* %16
%37 = fsub double 1.000000e+00, %36
%38 = load double, double* %16
%39 = fsub double 1.000000e+00, %38
%40 = fmul double %37, %39
%41 = load double, double* %11
%42 = fmul double %40, %41
%43 = call double @llvm.fmuladd.f64(double %34, double %35, double %42)
store double %43, double* %15
%44 = load double, double* %7
%45 = load double, double* %14
%46 = load double, double* %15
%47 = call i32 (double, double, double, ...) bitcast (i32 (...)* @ComputeGaussianLikelihood to i32 (double, double, double, ...)*)(double %44, double %45, double %46)
%48 = sitofp i32 %47 to double
%49 = load double, double* %17
%50 = load double, double* %13
%51 = call double @llvm.fmuladd.f64(double %48, double %49, double %50)
store double %51, double* %13
br label %52
52: ; preds = %24
%53 = load double, double* %17
%54 = load double, double* %16
%55 = fadd double %54, %53
store double %55, double* %16
br label %21
56: ; preds = %21
%57 = load double, double* %13
ret double %57
}

LLVM IR (-O2):
define double @ComputeMarginalizedLikelihood(double %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = uitofp i32 %5 to double
%8 = fdiv double 1.000000e+00, %7
br label %9
9: ; preds = %6, %9
%10 = phi double [ 0.000000e+00, %6 ], [ %21, %9 ]
%11 = phi double [ 0.000000e+00, %6 ], [ %22, %9 ]
%12 = fsub double 1.000000e+00, %11
%13 = fmul double %12, %2
%14 = tail call double @llvm.fmuladd.f64(double %11, double %1, double %13)
%15 = fmul double %11, %11
%16 = fmul double %12, %12
%17 = fmul double %16, %4
%18 = tail call double @llvm.fmuladd.f64(double %15, double %3, double %17)
%19 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @ComputeGaussianLikelihood to i32 (double, double, double, ...)*)(double %0, double %14, double %18)
%20 = sitofp i32 %19 to double
%21 = tail call double @llvm.fmuladd.f64(double %20, double %8, double %10)
%22 = fadd double %8, %11
%23 = fcmp ugt double %22, 1.000000e+00
br i1 %23, label %24, label %9
24: ; preds = %9
ret double %21
}