#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double KSPlusbarAsymp(int, double);
double exp(int);
double getLogFactorial(int);
double log(double);
int log1p(double);
double KSPlusbarUpper(int n, double x) {
  const double EPSILON = 1.0E-12;
  double q;
  double Sum = 0.0;
  double term;
  double t;
  double LogCom;
  double LOGJMAX;
  int j;
  int jdiv;
  int jmax = (int)(n * (1.0 - x));
  if (n > 200000)
    return KSPlusbarAsymp(n, x);
  if ((1.0 - x - (double)jmax / n) <= 0.0)
    jmax--;
  if (n > 3000)
    jdiv = 2;
  else
    jdiv = 3;
  j = jmax / jdiv + 1;
  LogCom = getLogFactorial(n) - getLogFactorial(j) - getLogFactorial(n - j);
  LOGJMAX = LogCom;
  while (j <= jmax) {
    q = (double)j / n + x;
    term = LogCom + (j - 1) * log(q) + (n - j) * log1p(-q);
    t = exp(term);
    Sum += t;
    LogCom += log((double)(n - j) / (j + 1));
    if (t <= Sum * EPSILON)
      break;
    j++;
  }
  j = jmax / jdiv;
  LogCom = LOGJMAX + log((double)(j + 1) / (n - j));
  while (j > 0) {
    q = (double)j / n + x;
    term = LogCom + (j - 1) * log(q) + (n - j) * log1p(-q);
    t = exp(term);
    Sum += t;
    LogCom += log((double)j / (n - j + 1));
    if (t <= Sum * EPSILON)
      break;
    j--;
  }
  Sum *= x;
  Sum += exp(n * log1p(-x));
  return Sum;
}


x86 assembly (clang, -O0):
<KSPlusbarUpper>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe7b(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x30d40,-0xc(%rbp)
jle    11b9 <KSPlusbarUpper+0x69>
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   1040 <KSPlusbarAsymp@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    155c <KSPlusbarUpper+0x40c>
movsd  0xe3f(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x5c(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm2
divsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jb     11ee <KSPlusbarUpper+0x9e>
mov    -0x5c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0xbb8,-0xc(%rbp)
jle    1207 <KSPlusbarUpper+0xb7>
movl   $0x2,-0x58(%rbp)
jmp    120e <KSPlusbarUpper+0xbe>
movl   $0x3,-0x58(%rbp)
mov    -0x5c(%rbp),%eax
cltd
idivl  -0x58(%rbp)
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getLogFactorial@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x54(%rbp),%edi
call   1030 <getLogFactorial@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0xc(%rbp),%edi
sub    -0x54(%rbp),%edi
call   1030 <getLogFactorial@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jg     138c <KSPlusbarUpper+0x23c>
cvtsi2sdl -0x54(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x90(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x88(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x54(%rbp),%eax
mov    %eax,-0x74(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1070 <log1p@plt>
movsd  -0x80(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%edi
call   1050 <exp@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x54(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x54(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1060 <log@plt>
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  0xc9e(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     137e <KSPlusbarUpper+0x22e>
jmp    138c <KSPlusbarUpper+0x23c>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1267 <KSPlusbarUpper+0x117>
mov    -0x5c(%rbp),%eax
cltd
idivl  -0x58(%rbp)
mov    %eax,-0x54(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x54(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0xc(%rbp),%eax
sub    -0x54(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x0,-0x54(%rbp)
jle    1501 <KSPlusbarUpper+0x3b1>
cvtsi2sdl -0x54(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0xb8(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0xb0(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
mov    -0xc(%rbp),%eax
sub    -0x54(%rbp),%eax
mov    %eax,-0x9c(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1070 <log1p@plt>
movsd  -0xa8(%rbp),%xmm0
ff
mov    %eax,%ecx
mov    -0x9c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%edi
call   1050 <exp@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x54(%rbp),%xmm0
mov    -0xc(%rbp),%eax
sub    -0x54(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1060 <log@plt>
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  0xb29(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     14f3 <KSPlusbarUpper+0x3a3>
jmp    1501 <KSPlusbarUpper+0x3b1>
mov    -0x54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x54(%rbp)
jmp    13d4 <KSPlusbarUpper+0x284>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0xbc(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1070 <log1p@plt>
mov    -0xbc(%rbp),%edi
imul   %eax,%edi
call   1050 <exp@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KSPlusbarUpper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edi,%r14d
cmp    $0x30d41,%edi
jl     117f <KSPlusbarUpper+0x2f>
mov    %r14d,%edi
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <KSPlusbarAsymp@plt>
cvtsi2sd %r14d,%xmm2
movapd %xmm0,%xmm1
movsd  0xe70(%rip),%xmm0
movapd %xmm1,0x30(%rsp)
subsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm2,%xmm1
cvttsd2si %xmm1,%r12d
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
movsd  %xmm2,0x48(%rsp)
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x10(%rsp)
ucomisd %xmm0,%xmm2
adc    $0xffffffff,%r12d
xor    %ecx,%ecx
cmp    $0xbb9,%r14d
setge  %cl
xor    $0x3,%ecx
mov    %r12d,%eax
cltd
idiv   %ecx
mov    %eax,%r13d
lea    0x1(%r13),%ebx
mov    %r14d,%edi
call   1030 <getLogFactorial@plt>
movsd  %xmm0,0x18(%rsp)
mov    %ebx,%edi
call   1030 <getLogFactorial@plt>
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
mov    %r14d,%edi
mov    %ebx,0x2c(%rsp)
sub    %ebx,%edi
call   1030 <getLogFactorial@plt>
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
cmp    %r12d,%r13d
jge    1331 <KSPlusbarUpper+0x1e1>
mov    %r13d,%ebp
not    %ebp
add    %r14d,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    0x2c(%rsp),%eax
mov    %eax,%ebx
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
nop
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0x48(%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
movapd %xmm0,0x50(%rsp)
lea    -0x1(%rbx),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1060 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movaps 0x50(%rsp),%xmm0
xorps  0xd64(%rip),%xmm0
call   1070 <log1p@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <exp@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
lea    0x1(%rbx),%r15d
xorps  %xmm1,%xmm1
cvtsi2sd %r15d,%xmm1
divsd  %xmm1,%xmm0
call   1060 <log@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0xcfe(%rip),%xmm1
ucomisd 0x8(%rsp),%xmm1
jae    1331 <KSPlusbarUpper+0x1e1>
add    $0xffffffff,%ebp
movsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
cmp    %r12d,%ebx
mov    %r15d,%ebx
jl     1260 <KSPlusbarUpper+0x110>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x2c(%rsp),%xmm0
mov    %r14d,%ebp
sub    %r13d,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
call   1060 <log@plt>
test   %r13d,%r13d
jle    144e <KSPlusbarUpper+0x2fe>
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd 0x30(%rsp),%xmm0
nopl   0x0(%rax)
movsd  %xmm1,0x18(%rsp)
xorps  %xmm2,%xmm2
cvtsi2sd %r13d,%xmm2
movsd  %xmm2,0x20(%rsp)
divsd  0x48(%rsp),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,0x50(%rsp)
lea    -0x1(%r13),%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm2,%xmm0
call   1060 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movaps 0x50(%rsp),%xmm0
xorps  0xc44(%rip),%xmm0
call   1070 <log1p@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <exp@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
add    $0x1,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0x20(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1060 <log@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0xbe1(%rip),%xmm1
ucomisd 0x8(%rsp),%xmm1
jae    144e <KSPlusbarUpper+0x2fe>
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
cmp    $0x1,%r13d
mov    %ebx,%r13d
movapd 0x30(%rsp),%xmm0
ja     1370 <KSPlusbarUpper+0x220>
jmp    1453 <KSPlusbarUpper+0x303>
movaps 0x30(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xorpd  0xba5(%rip),%xmm0
call   1070 <log1p@plt>
imul   %eax,%r14d
mov    %r14d,%edi
call   1050 <exp@plt>
addsd  0x10(%rsp),%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @KSPlusbarUpper(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%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 i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
store double 0x3D719799812DEA11, double* %6
store double 0.000000e+00, double* %8
%16 = load i32, i32* %4
%17 = sitofp i32 %16 to double
%18 = load double, double* %5
%19 = fsub double 1.000000e+00, %18
%20 = fmul double %17, %19
%21 = fptosi double %20 to i32
store i32 %21, i32* %15
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 200000
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load i32, i32* %4
%26 = load double, double* %5
%27 = call double @KSPlusbarAsymp(i32 %25, double %26)
store double %27, double* %3
br label %195
28: ; preds = %2
%29 = load double, double* %5
%30 = fsub double 1.000000e+00, %29
%31 = load i32, i32* %15
%32 = sitofp i32 %31 to double
%33 = load i32, i32* %4
%34 = sitofp i32 %33 to double
%35 = fdiv double %32, %34
%36 = fsub double %30, %35
%37 = fcmp ole double %36, 0.000000e+00
br i1 %37, label %38, label %41
38: ; preds = %28
%39 = load i32, i32* %15
%40 = add nsw i32 %39, -1
store i32 %40, i32* %15
br label %41
41: ; preds = %38, %28
%42 = load i32, i32* %4
%43 = icmp sgt i32 %42, 3000
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 2, i32* %14
br label %46
45: ; preds = %41
store i32 3, i32* %14
br label %46
46: ; preds = %45, %44
%47 = load i32, i32* %15
%48 = load i32, i32* %14
%49 = sdiv i32 %47, %48
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
%51 = load i32, i32* %4
%52 = call double @getLogFactorial(i32 %51)
%53 = load i32, i32* %13
%54 = call double @getLogFactorial(i32 %53)
%55 = fsub double %52, %54
%56 = load i32, i32* %4
%57 = load i32, i32* %13
%58 = sub nsw i32 %56, %57
%59 = call double @getLogFactorial(i32 %58)
%60 = fsub double %55, %59
store double %60, double* %11
%61 = load double, double* %11
store double %61, double* %12
br label %62
62: ; preds = %112, %46
%63 = load i32, i32* %13
%64 = load i32, i32* %15
%65 = icmp sle i32 %63, %64
br i1 %65, label %66, label %115
66: ; preds = %62
%67 = load i32, i32* %13
%68 = sitofp i32 %67 to double
%69 = load i32, i32* %4
%70 = sitofp i32 %69 to double
%71 = fdiv double %68, %70
%72 = load double, double* %5
%73 = fadd double %71, %72
store double %73, double* %7
%74 = load double, double* %11
%75 = load i32, i32* %13
%76 = sub nsw i32 %75, 1
%77 = sitofp i32 %76 to double
%78 = load double, double* %7
%79 = call double @log(double %78)
%80 = call double @llvm.fmuladd.f64(double %77, double %79, double %74)
%81 = load i32, i32* %4
%82 = load i32, i32* %13
%83 = sub nsw i32 %81, %82
%84 = load double, double* %7
%85 = fneg double %84
%86 = call i32 @log1p(double %85)
%87 = mul nsw i32 %83, %86
%88 = sitofp i32 %87 to double
%89 = fadd double %80, %88
store double %89, double* %9
%90 = load double, double* %9
%91 = fptosi double %90 to i32
%92 = call double @exp(i32 %91)
store double %92, double* %10
%93 = load double, double* %10
%94 = load double, double* %8
%95 = fadd double %94, %93
store double %95, double* %8
%96 = load i32, i32* %4
%97 = load i32, i32* %13
%98 = sub nsw i32 %96, %97
%99 = sitofp i32 %98 to double
%100 = load i32, i32* %13
%101 = add nsw i32 %100, 1
%102 = sitofp i32 %101 to double
%103 = fdiv double %99, %102
%104 = call double @log(double %103)
%105 = load double, double* %11
%106 = fadd double %105, %104
store double %106, double* %11
%107 = load double, double* %10
%108 = load double, double* %8
%109 = fmul double %108, 0x3D719799812DEA11
%110 = fcmp ole double %107, %109
br i1 %110, label %111, label %112
111: ; preds = %66
br label %115
112: ; preds = %66
%113 = load i32, i32* %13
%114 = add nsw i32 %113, 1
store i32 %114, i32* %13
br label %62
115: ; preds = %111, %62
%116 = load i32, i32* %15
%117 = load i32, i32* %14
%118 = sdiv i32 %116, %117
store i32 %118, i32* %13
%119 = load double, double* %12
%120 = load i32, i32* %13
%121 = add nsw i32 %120, 1
%122 = sitofp i32 %121 to double
%123 = load i32, i32* %4
%124 = load i32, i32* %13
%125 = sub nsw i32 %123, %124
%126 = sitofp i32 %125 to double
%127 = fdiv double %122, %126
%128 = call double @log(double %127)
%129 = fadd double %119, %128
store double %129, double* %11
br label %130
130: ; preds = %179, %115
%131 = load i32, i32* %13
%132 = icmp sgt i32 %131, 0
br i1 %132, label %133, label %182
133: ; preds = %130
%134 = load i32, i32* %13
%135 = sitofp i32 %134 to double
%136 = load i32, i32* %4
%137 = sitofp i32 %136 to double
%138 = fdiv double %135, %137
%139 = load double, double* %5
%140 = fadd double %138, %139
store double %140, double* %7
%141 = load double, double* %11
%142 = load i32, i32* %13
%143 = sub nsw i32 %142, 1
%144 = sitofp i32 %143 to double
%145 = load double, double* %7
%146 = call double @log(double %145)
%147 = call double @llvm.fmuladd.f64(double %144, double %146, double %141)
%148 = load i32, i32* %4
%149 = load i32, i32* %13
%150 = sub nsw i32 %148, %149
%151 = load double, double* %7
%152 = fneg double %151
%153 = call i32 @log1p(double %152)
%154 = mul nsw i32 %150, %153
%155 = sitofp i32 %154 to double
%156 = fadd double %147, %155
store double %156, double* %9
%157 = load double, double* %9
%158 = fptosi double %157 to i32
%159 = call double @exp(i32 %158)
store double %159, double* %10
%160 = load double, double* %10
%161 = load double, double* %8
%162 = fadd double %161, %160
store double %162, double* %8
%163 = load i32, i32* %13
%164 = sitofp i32 %163 to double
%165 = load i32, i32* %4
%166 = load i32, i32* %13
%167 = sub nsw i32 %165, %166
%168 = add nsw i32 %167, 1
%169 = sitofp i32 %168 to double
%170 = fdiv double %164, %169
%171 = call double @log(double %170)
%172 = load double, double* %11
%173 = fadd double %172, %171
store double %173, double* %11
%174 = load double, double* %10
%175 = load double, double* %8
%176 = fmul double %175, 0x3D719799812DEA11
%177 = fcmp ole double %174, %176
br i1 %177, label %178, label %179
178: ; preds = %133
br label %182
179: ; preds = %133
%180 = load i32, i32* %13
%181 = add nsw i32 %180, -1
store i32 %181, i32* %13
br label %130
182: ; preds = %178, %130
%183 = load double, double* %5
%184 = load double, double* %8
%185 = fmul double %184, %183
store double %185, double* %8
%186 = load i32, i32* %4
%187 = load double, double* %5
%188 = fneg double %187
%189 = call i32 @log1p(double %188)
%190 = mul nsw i32 %186, %189
%191 = call double @exp(i32 %190)
%192 = load double, double* %8
%193 = fadd double %192, %191
store double %193, double* %8
%194 = load double, double* %8
store double %194, double* %3
br label %195
195: ; preds = %182, %24
%196 = load double, double* %3
ret double %196
}

LLVM IR (-O2):
define double @KSPlusbarUpper(i32 %0, double %1) {
%3 = sitofp i32 %0 to double
%4 = fsub double 1.000000e+00, %1
%5 = fmul double %4, %3
%6 = fptosi double %5 to i32
%7 = icmp sgt i32 %0, 200000
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call double @KSPlusbarAsymp(i32 %0, double %1)
br label %105
10: ; preds = %2
%11 = sitofp i32 %6 to double
%12 = fdiv double %11, %3
%13 = fsub double %4, %12
%14 = fcmp ole double %13, 0.000000e+00
%15 = sext i1 %14 to i32
%16 = add nsw i32 %15, %6
%17 = icmp sgt i32 %0, 3000
%18 = select i1 %17, i32 2, i32 3
%19 = sdiv i32 %16, %18
%20 = add nsw i32 %19, 1
%21 = tail call double @getLogFactorial(i32 %0)
%22 = tail call double @getLogFactorial(i32 %20)
%23 = fsub double %21, %22
%24 = sub nsw i32 %0, %20
%25 = tail call double @getLogFactorial(i32 %24)
%26 = fsub double %23, %25
%27 = icmp slt i32 %19, %16
br i1 %27, label %28, label %58
28: ; preds = %10, %28
%29 = phi i32 [ %49, %28 ], [ %20, %10 ]
%30 = phi double [ %55, %28 ], [ %26, %10 ]
%31 = phi double [ %47, %28 ], [ 0.000000e+00, %10 ]
%32 = sitofp i32 %29 to double
%33 = fdiv double %32, %3
%34 = fadd double %33, %1
%35 = add nsw i32 %29, -1
%36 = sitofp i32 %35 to double
%37 = tail call double @log(double %34)
%38 = tail call double @llvm.fmuladd.f64(double %36, double %37, double %30)
%39 = sub nsw i32 %0, %29
%40 = fneg double %34
%41 = tail call i32 @log1p(double %40)
%42 = mul nsw i32 %41, %39
%43 = sitofp i32 %42 to double
%44 = fadd double %38, %43
%45 = fptosi double %44 to i32
%46 = tail call double @exp(i32 %45)
%47 = fadd double %31, %46
%48 = sitofp i32 %39 to double
%49 = add nsw i32 %29, 1
%50 = sitofp i32 %49 to double
%51 = fdiv double %48, %50
%52 = tail call double @log(double %51)
%53 = fmul double %47, 0x3D719799812DEA11
%54 = fcmp ole double %46, %53
%55 = fadd double %30, %52
%56 = icmp sge i32 %29, %16
%57 = select i1 %54, i1 true, i1 %56
br i1 %57, label %58, label %28
58: ; preds = %28, %10
%59 = phi double [ 0.000000e+00, %10 ], [ %47, %28 ]
%60 = sitofp i32 %20 to double
%61 = sub nsw i32 %0, %19
%62 = sitofp i32 %61 to double
%63 = fdiv double %60, %62
%64 = tail call double @log(double %63)
%65 = icmp sgt i32 %19, 0
br i1 %65, label %66, label %97
66: ; preds = %58
%67 = fadd double %26, %64
br label %68
68: ; preds = %66, %68
%69 = phi i32 [ %75, %68 ], [ %19, %66 ]
%70 = phi double [ %94, %68 ], [ %67, %66 ]
%71 = phi double [ %87, %68 ], [ %59, %66 ]
%72 = sitofp i32 %69 to double
%73 = fdiv double %72, %3
%74 = fadd double %73, %1
%75 = add nsw i32 %69, -1
%76 = sitofp i32 %75 to double
%77 = tail call double @log(double %74)
%78 = tail call double @llvm.fmuladd.f64(double %76, double %77, double %70)
%79 = sub nsw i32 %0, %69
%80 = fneg double %74
%81 = tail call i32 @log1p(double %80)
%82 = mul nsw i32 %81, %79
%83 = sitofp i32 %82 to double
%84 = fadd double %78, %83
%85 = fptosi double %84 to i32
%86 = tail call double @exp(i32 %85)
%87 = fadd double %71, %86
%88 = add nsw i32 %79, 1
%89 = sitofp i32 %88 to double
%90 = fdiv double %72, %89
%91 = tail call double @log(double %90)
%92 = fmul double %87, 0x3D719799812DEA11
%93 = fcmp ugt double %86, %92
%94 = fadd double %70, %91
%95 = icmp ugt i32 %69, 1
%96 = select i1 %93, i1 %95, i1 false
br i1 %96, label %68, label %97
97: ; preds = %68, %58
%98 = phi double [ %59, %58 ], [ %87, %68 ]
%99 = fmul double %98, %1
%100 = fneg double %1
%101 = tail call i32 @log1p(double %100)
%102 = mul nsw i32 %101, %0
%103 = tail call double @exp(i32 %102)
%104 = fadd double %99, %103
br label %105
105: ; preds = %97, %8
%106 = phi double [ %9, %8 ], [ %104, %97 ]
ret double %106
}