double expShulen(double T, double M, double d, double p,
                 unsigned long subjectLength, double *ln_n_fac, double *s1,
                 unsigned long n_s) {
  unsigned long i;
  int thresholdReached = 0;
  double prob_i, probOld, delta, factor;
  double e = 0.0;
  double t = 1.0 - d;
  double p_t = t;
  probOld = 0.0;
  for (i = 1LU; i < subjectLength; i++) {
    factor = 1.0 - p_t;
    if (!thresholdReached) {
      prob_i = factor * pmax(M, i, p, subjectLength, &thresholdReached,
                             ln_n_fac, s1, n_s);
    } else {
      prob_i = factor;
    }
    delta = (prob_i - probOld) * i;
    e += delta;
    if (1.0 <= e && delta / e <= T) {
      break;
    }
    p_t *= t;
    probOld = prob_i;
  }
  return e;
}


x86 assembly (clang, -O0):
<expShulen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rcx,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xeaa(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movq   $0x1,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12b6 <expShulen+0x1a6>
movsd  0xe6d(%rip),%xmm0
subsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x70(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    11fa <expShulen+0xea>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x10(%rbp),%xmm0
mov    -0x48(%rbp),%rdi
movsd  -0x20(%rbp),%xmm1
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
lea    -0x4c(%rbp),%rdx
mov    $0x2,%al
call   1030 <pmax@plt>
movsd  -0x90(%rbp),%xmm0
ff
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1204 <expShulen+0xf4>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
subsd  %xmm1,%xmm0
movaps 0xdf7(%rip),%xmm2
movq   -0x48(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xdf6(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  0xda2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1286 <expShulen+0x176>
movsd  -0x68(%rbp),%xmm1
divsd  -0x78(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1286 <expShulen+0x176>
jmp    12b6 <expShulen+0x1a6>
movsd  -0x80(%rbp),%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    117d <expShulen+0x6d>
movsd  -0x78(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expShulen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movsd  %xmm3,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
movl   $0x0,0x4(%rsp)
xorpd  %xmm3,%xmm3
cmp    $0x2,%rdi
jb     1293 <expShulen+0x183>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
movsd  0xea6(%rip),%xmm4
movapd %xmm4,%xmm8
subsd  %xmm2,%xmm8
mov    $0x2,%ebp
sub    %rdi,%rbp
xorpd  %xmm3,%xmm3
mov    $0x1,%ebx
xor    %eax,%eax
movdqa 0xe91(%rip),%xmm6
movapd 0xe99(%rip),%xmm7
movapd %xmm8,%xmm9
xorpd  %xmm0,%xmm0
movsd  %xmm8,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
movapd %xmm4,%xmm5
subsd  %xmm9,%xmm5
test   %eax,%eax
jne    1234 <expShulen+0x124>
movsd  %xmm0,0x28(%rsp)
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
movsd  0x18(%rsp),%xmm1
mov    %r13,%rsi
lea    0x4(%rsp),%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14,%r9
mov    $0x2,%al
movsd  %xmm3,0x40(%rsp)
movsd  %xmm9,0x38(%rsp)
movsd  %xmm5,0x30(%rsp)
call   1030 <pmax@plt>
movsd  0x30(%rsp),%xmm5
movsd  0x38(%rsp),%xmm9
movapd 0xe1a(%rip),%xmm7
movdqa 0xe02(%rip),%xmm6
movsd  0x8(%rsp),%xmm8
movsd  0xde3(%rip),%xmm4
movsd  0x40(%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm0,%xmm5
movsd  0x28(%rsp),%xmm0
movapd %xmm5,%xmm1
subsd  %xmm0,%xmm1
movq   %rbx,%xmm2
punpckldq %xmm6,%xmm2
subpd  %xmm7,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm0,%xmm3
ucomisd %xmm4,%xmm3
jb     1273 <expShulen+0x163>
divsd  %xmm3,%xmm0
movsd  0x20(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    1293 <expShulen+0x183>
lea    (%rbx,%rbp,1),%rax
cmp    $0x1,%rax
je     1293 <expShulen+0x183>
mulsd  %xmm8,%xmm9
mov    0x4(%rsp),%eax
add    $0x1,%rbx
movapd %xmm5,%xmm0
jmp    11a0 <expShulen+0x90>
movapd %xmm3,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @expShulen(double %0, double %1, double %2, double %3, i64 %4, double* %5, double* %6, i64 %7) {
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i64
%14 = alloca double*
%15 = alloca double*
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
store double %0, double* %9
store double %1, double* %10
store double %2, double* %11
store double %3, double* %12
store i64 %4, i64* %13
store double* %5, double** %14
store double* %6, double** %15
store i64 %7, i64* %16
store i32 0, i32* %18
store double 0.000000e+00, double* %23
%26 = load double, double* %11
%27 = fsub double 1.000000e+00, %26
store double %27, double* %24
%28 = load double, double* %24
store double %28, double* %25
store double 0.000000e+00, double* %20
store i64 1, i64* %17
br label %29
29: ; preds = %76, %8
%30 = load i64, i64* %17
%31 = load i64, i64* %13
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %79
33: ; preds = %29
%34 = load double, double* %25
%35 = fsub double 1.000000e+00, %34
store double %35, double* %22
%36 = load i32, i32* %18
%37 = icmp ne i32 %36, 0
br i1 %37, label %50, label %38
38: ; preds = %33
%39 = load double, double* %22
%40 = load double, double* %10
%41 = load i64, i64* %17
%42 = load double, double* %12
%43 = load i64, i64* %13
%44 = load double*, double** %14
%45 = load double*, double** %15
%46 = load i64, i64* %16
%47 = call i32 (double, i64, double, i64, i32*, double*, double*, i64, ...) bitcast (i32 (...)* @pmax to i32 (double, i64, double, i64, i32*, double*, double*, i64, ...)*)(double %40, i64 %41, double %42, i64 %43, i32* %18, double* %44, double* %45, i64 %46)
%48 = sitofp i32 %47 to double
%49 = fmul double %39, %48
store double %49, double* %19
br label %52
50: ; preds = %33
%51 = load double, double* %22
store double %51, double* %19
br label %52
52: ; preds = %50, %38
%53 = load double, double* %19
%54 = load double, double* %20
%55 = fsub double %53, %54
%56 = load i64, i64* %17
%57 = uitofp i64 %56 to double
%58 = fmul double %55, %57
store double %58, double* %21
%59 = load double, double* %21
%60 = load double, double* %23
%61 = fadd double %60, %59
store double %61, double* %23
%62 = load double, double* %23
%63 = fcmp ole double 1.000000e+00, %62
br i1 %63, label %64, label %71
64: ; preds = %52
%65 = load double, double* %21
%66 = load double, double* %23
%67 = fdiv double %65, %66
%68 = load double, double* %9
%69 = fcmp ole double %67, %68
br i1 %69, label %70, label %71
70: ; preds = %64
br label %79
71: ; preds = %64, %52
%72 = load double, double* %24
%73 = load double, double* %25
%74 = fmul double %73, %72
store double %74, double* %25
%75 = load double, double* %19
store double %75, double* %20
br label %76
76: ; preds = %71
%77 = load i64, i64* %17
%78 = add i64 %77, 1
store i64 %78, i64* %17
br label %29
79: ; preds = %70, %29
%80 = load double, double* %23
ret double %80
}

LLVM IR (-O2):
define double @expShulen(double %0, double %1, double %2, double %3, i64 %4, double* %5, double* %6, i64 %7) {
%9 = alloca i32
%10 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%11 = fsub double 1.000000e+00, %2
%12 = icmp ugt i64 %4, 1
br i1 %12, label %13, label %41
13: ; preds = %8, %38
%14 = phi i32 [ %40, %38 ], [ 0, %8 ]
%15 = phi double [ %39, %38 ], [ %11, %8 ]
%16 = phi i64 [ %36, %38 ], [ 1, %8 ]
%17 = phi double [ %30, %38 ], [ 0.000000e+00, %8 ]
%18 = phi double [ %26, %38 ], [ 0.000000e+00, %8 ]
%19 = fsub double 1.000000e+00, %15
%20 = icmp eq i32 %14, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = call i32 (double, i64, double, i64, i32*, double*, double*, i64, ...) bitcast (i32 (...)* @pmax to i32 (double, i64, double, i64, i32*, double*, double*, i64, ...)*)(double %1, i64 %16, double %3, i64 %4, i32* %9, double* %5, double* %6, i64 %7)
%23 = sitofp i32 %22 to double
%24 = fmul double %19, %23
br label %25
25: ; preds = %13, %21
%26 = phi double [ %24, %21 ], [ %19, %13 ]
%27 = fsub double %26, %18
%28 = uitofp i64 %16 to double
%29 = fmul double %27, %28
%30 = fadd double %17, %29
%31 = fcmp ult double %30, 1.000000e+00
%32 = fdiv double %29, %30
%33 = fcmp ugt double %32, %0
%34 = or i1 %31, %33
br i1 %34, label %35, label %41
35: ; preds = %25
%36 = add nuw i64 %16, 1
%37 = icmp eq i64 %36, %4
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = fmul double %11, %15
%40 = load i32, i32* %9
br label %13
41: ; preds = %35, %25, %8
%42 = phi double [ 0.000000e+00, %8 ], [ %30, %25 ], [ %30, %35 ]
ret double %42
}