double c45_pruning_bin_p(double N, double p, double x1, double x2) {
  double q = p / (1 - p);
  double k = 0.0;
  double v = 1.0;
  double s = 0.0;
  double tot = 0.0;
  double l_val = 1.0e30;
  while (k <= N) {
    tot += v;
    if (x1 <= k && k <= x2) {
      s += v;
    }
    if (tot > l_val) {
      s = s / l_val;
      tot = tot / l_val;
      v = v / l_val;
    }
    k += 1.0;
    v = v * q * (N + 1 - k) / k;
  }
  return s / tot;
}


x86 assembly (clang, -O0):
<c45_pruning_bin_p>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xee3(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xea0(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     123d <c45_pruning_bin_p+0x13d>
movsd  -0x38(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11bf <c45_pruning_bin_p+0xbf>
movsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11bf <c45_pruning_bin_p+0xbf>
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    11fc <c45_pruning_bin_p+0xfc>
movsd  -0x40(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe04(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xde8(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1165 <c45_pruning_bin_p+0x65>
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<c45_pruning_bin_p>:
xorpd  %xmm13,%xmm13
ucomisd %xmm13,%xmm0
jae    1115 <c45_pruning_bin_p+0x15>
movsd  0xef4(%rip),%xmm0
ret
movsd  0xee2(%rip),%xmm8
movapd %xmm8,%xmm4
subsd  %xmm1,%xmm4
divsd  %xmm4,%xmm1
movapd %xmm0,%xmm12
addsd  %xmm8,%xmm12
xorpd  %xmm6,%xmm6
unpcklpd %xmm8,%xmm6
movsd  0xec9(%rip),%xmm11
movsd  0xec8(%rip),%xmm9
movapd 0xec7(%rip),%xmm10
xorpd  %xmm5,%xmm5
jmp    1195 <c45_pruning_bin_p+0x95>
nop
mulsd  %xmm1,%xmm14
addsd  %xmm8,%xmm13
movapd %xmm12,%xmm5
subsd  %xmm13,%xmm5
mulsd  %xmm14,%xmm5
divsd  %xmm13,%xmm5
ucomisd %xmm13,%xmm0
movapd %xmm4,%xmm6
unpcklpd %xmm5,%xmm6
movapd %xmm4,%xmm5
unpckhpd %xmm4,%xmm5
jb     1203 <c45_pruning_bin_p+0x103>
movapd %xmm6,%xmm14
unpckhpd %xmm6,%xmm14
movapd %xmm13,%xmm7
cmpnlesd %xmm3,%xmm7
movapd %xmm7,%xmm4
andpd  %xmm11,%xmm4
andnpd %xmm14,%xmm7
orpd   %xmm4,%xmm7
movapd %xmm2,%xmm4
cmpnlesd %xmm13,%xmm4
movapd %xmm4,%xmm15
andnpd %xmm7,%xmm15
andpd  %xmm11,%xmm4
orpd   %xmm15,%xmm4
unpcklpd %xmm5,%xmm4
addpd  %xmm6,%xmm4
movapd %xmm4,%xmm5
unpckhpd %xmm4,%xmm5
ucomisd %xmm9,%xmm5
jbe    1160 <c45_pruning_bin_p+0x60>
divpd  %xmm10,%xmm4
divsd  %xmm9,%xmm14
jmp    1160 <c45_pruning_bin_p+0x60>
divsd  %xmm5,%xmm4
movapd %xmm4,%xmm0
ret

LLVM IR (-O0):
define double @c45_pruning_bin_p(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%15 = load double, double* %6
%16 = load double, double* %6
%17 = fsub double 1.000000e+00, %16
%18 = fdiv double %15, %17
store double %18, double* %9
store double 0.000000e+00, double* %10
store double 1.000000e+00, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store double 1.000000e+30, double* %14
br label %19
19: ; preds = %52, %4
%20 = load double, double* %10
%21 = load double, double* %5
%22 = fcmp ole double %20, %21
br i1 %22, label %23, label %65
23: ; preds = %19
%24 = load double, double* %11
%25 = load double, double* %13
%26 = fadd double %25, %24
store double %26, double* %13
%27 = load double, double* %7
%28 = load double, double* %10
%29 = fcmp ole double %27, %28
br i1 %29, label %30, label %38
30: ; preds = %23
%31 = load double, double* %10
%32 = load double, double* %8
%33 = fcmp ole double %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load double, double* %11
%36 = load double, double* %12
%37 = fadd double %36, %35
store double %37, double* %12
br label %38
38: ; preds = %34, %30, %23
%39 = load double, double* %13
%40 = load double, double* %14
%41 = fcmp ogt double %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load double, double* %12
%44 = load double, double* %14
%45 = fdiv double %43, %44
store double %45, double* %12
%46 = load double, double* %13
%47 = load double, double* %14
%48 = fdiv double %46, %47
store double %48, double* %13
%49 = load double, double* %11
%50 = load double, double* %14
%51 = fdiv double %49, %50
store double %51, double* %11
br label %52
52: ; preds = %42, %38
%53 = load double, double* %10
%54 = fadd double %53, 1.000000e+00
store double %54, double* %10
%55 = load double, double* %11
%56 = load double, double* %9
%57 = fmul double %55, %56
%58 = load double, double* %5
%59 = fadd double %58, 1.000000e+00
%60 = load double, double* %10
%61 = fsub double %59, %60
%62 = fmul double %57, %61
%63 = load double, double* %10
%64 = fdiv double %62, %63
store double %64, double* %11
br label %19
65: ; preds = %19
%66 = load double, double* %12
%67 = load double, double* %13
%68 = fdiv double %66, %67
ret double %68
}

LLVM IR (-O2):
define double @c45_pruning_bin_p(double %0, double %1, double %2, double %3) {
%5 = fsub double 1.000000e+00, %1
%6 = fdiv double %1, %5
%7 = fcmp ult double %0, 0.000000e+00
br i1 %7, label %41, label %8
8: ; preds = %4
%9 = fadd double %0, 1.000000e+00
br label %10
10: ; preds = %8, %27
%11 = phi double [ 0.000000e+00, %8 ], [ %30, %27 ]
%12 = phi double [ 0.000000e+00, %8 ], [ %37, %27 ]
%13 = phi <2 x double> [ <double 0.000000e+00, double 1.000000e+00>, %8 ], [ %36, %27 ]
%14 = fcmp ult double %11, %2
%15 = fcmp ugt double %11, %3
%16 = or i1 %14, %15
%17 = extractelement <2 x double> %13, i64 1
%18 = select i1 %16, double -0.000000e+00, double %17
%19 = insertelement <2 x double> poison, double %18, i64 0
%20 = insertelement <2 x double> %19, double %12, i64 1
%21 = fadd <2 x double> %13, %20
%22 = extractelement <2 x double> %21, i64 1
%23 = fcmp ogt double %22, 1.000000e+30
br i1 %23, label %24, label %27
24: ; preds = %10
%25 = fdiv <2 x double> %21, <double 1.000000e+30, double 1.000000e+30>
%26 = fdiv double %17, 1.000000e+30
br label %27
27: ; preds = %24, %10
%28 = phi double [ %26, %24 ], [ %17, %10 ]
%29 = phi <2 x double> [ %25, %24 ], [ %21, %10 ]
%30 = fadd double %11, 1.000000e+00
%31 = fmul double %6, %28
%32 = fsub double %9, %30
%33 = fmul double %32, %31
%34 = fdiv double %33, %30
%35 = fcmp ugt double %30, %0
%36 = insertelement <2 x double> %29, double %34, i64 1
%37 = extractelement <2 x double> %29, i64 1
br i1 %35, label %38, label %10
38: ; preds = %27
%39 = extractelement <2 x double> %29, i64 0
%40 = fdiv double %39, %37
br label %41
41: ; preds = %38, %4
%42 = phi double [ %40, %38 ], [ 0x7FF8000000000000, %4 ]
ret double %42
}