#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 M_PI;
double exp(double);
double floor(double);
double gammln(double);
double log(double);
double ran_get();
double sqrt(double);
double tan(double);
int ran_binomial(double pp, int n) {
  int j;
  static int nold = (-1);
  double am, em, g, angle, p, bnl, sq, t, y;
  static double pold = (-1.0), pc, plog, pclog, en, oldg;
  p = (pp <= 0.5 ? pp : 1.0 - pp);
  am = n * p;
  if (n < 25) {
    bnl = 0.0;
    for (j = 1; j <= n; j++)
      if (ran_get() < p)
        ++bnl;
  } else if (am < 1.0) {
    g = exp(-am);
    t = 1.0;
    for (j = 0; j <= n; j++) {
      t *= ran_get();
      if (t < g)
        break;
    }
    bnl = (j <= n ? j : n);
  } else {
    if (n != nold) {
      en = n;
      oldg = gammln(en + 1.0);
      nold = n;
    }
    if (p != pold) {
      pc = 1.0 - p;
      plog = log(p);
      pclog = log(pc);
      pold = p;
    }
    sq = sqrt(2.0 * am * pc);
    do {
      do {
        angle = M_PI * ran_get();
        y = tan(angle);
        em = sq * y + am;
      } while (em < 0.0 || em >= (en + 1.0));
      em = floor(em);
      t = 1.2 * sq * (1.0 + y * y) *
          exp(oldg - gammln(em + 1.0) - gammln(en - em + 1.0) + em * plog +
              (en - em) * pclog);
    } while (ran_get() > t);
    bnl = em;
  }
  if (p != pp)
    bnl = n - bnl;
  return (int)bnl;
}


x86 assembly (clang, -O0):
<ran_binomial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  0xe75(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     11a5 <ran_binomial+0x35>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    11b7 <ran_binomial+0x47>
movsd  0xe5b(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x19,-0xc(%rbp)
jge    1238 <ran_binomial+0xc8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1233 <ran_binomial+0xc3>
mov    $0x0,%al
call   1050 <ran_get@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1220 <ran_binomial+0xb0>
movsd  0xdf2(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1225 <ran_binomial+0xb5>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e9 <ran_binomial+0x79>
jmp    1567 <ran_binomial+0x3f7>
movsd  0xdc8(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    12fc <ran_binomial+0x18c>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xd8f(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12ce <ran_binomial+0x15e>
mov    $0x0,%al
call   1050 <ran_get@plt>
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12bb <ran_binomial+0x14b>
jmp    12ce <ran_binomial+0x15e>
jmp    12c0 <ran_binomial+0x150>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1285 <ran_binomial+0x115>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12e5 <ran_binomial+0x175>
mov    -0x10(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    12eb <ran_binomial+0x17b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1562 <ran_binomial+0x3f2>
mov    -0xc(%rbp),%eax
cmp    0x2d53(%rip),%eax
je     133e <ran_binomial+0x1ce>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  %xmm0,0x2d70(%rip)
movsd  0xce8(%rip),%xmm0
addsd  0x2d60(%rip),%xmm0
call   1080 <gammln@plt>
movsd  %xmm0,0x2d5b(%rip)
mov    -0xc(%rbp),%eax
mov    %eax,0x2d1a(%rip)
movsd  -0x38(%rbp),%xmm0
ucomisd 0x2d15(%rip),%xmm0
jne    135c <ran_binomial+0x1ec>
jp     135c <ran_binomial+0x1ec>
jmp    13a5 <ran_binomial+0x235>
movsd  0xca4(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,0x2cff(%rip)
movsd  -0x38(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x2cf5(%rip)
movsd  0x2ce5(%rip),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x2ce8(%rip)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,0x2cbb(%rip)
movsd  0xc63(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  0x2cb6(%rip),%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
jmp    13c9 <ran_binomial+0x259>
mov    0x2c18(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    $0x0,%al
call   1050 <ran_get@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <tan@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x1,%al
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
mov    %al,-0x71(%rbp)
ja     144e <ran_binomial+0x2de>
movsd  -0x20(%rbp),%xmm0
movsd  0xbcc(%rip),%xmm1
addsd  0x2c44(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    13c9 <ran_binomial+0x259>
movsd  -0x20(%rbp),%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xba8(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xb7d(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  0x2bf0(%rip),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xb58(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
call   1080 <gammln@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  0x2baf(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xb22(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <gammln@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0x2b6d(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0x2b6d(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0x2b58(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1050 <ran_get@plt>
ucomisd -0x50(%rbp),%xmm0
ja     13c4 <ran_binomial+0x254>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1567 <ran_binomial+0x3f7>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x8(%rbp),%xmm0
jne    1582 <ran_binomial+0x412>
jp     1582 <ran_binomial+0x412>
jmp    1591 <ran_binomial+0x421>
cvtsi2sdl -0xc(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
cvttsd2si -0x40(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ran_binomial>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
mov    %edi,%ebx
movsd  0xe7d(%rip),%xmm3
movapd %xmm3,%xmm2
subsd  %xmm0,%xmm2
movapd %xmm0,%xmm4
cmplesd 0xe70(%rip),%xmm4
movapd %xmm4,%xmm1
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm4
orpd   %xmm1,%xmm4
movapd %xmm4,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
cmp    $0x18,%edi
movapd %xmm0,0x70(%rsp)
movapd %xmm1,0x30(%rsp)
jg     1224 <ran_binomial+0xb4>
test   %ebx,%ebx
jle    1363 <ran_binomial+0x1f3>
xorpd  %xmm1,%xmm1
movsd  %xmm2,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
movapd %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1050 <ran_get@plt>
movsd  0x8(%rsp),%xmm2
movapd 0x10(%rsp),%xmm3
movapd %xmm3,%xmm1
addsd  0xdfb(%rip),%xmm1
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm3,%xmm0
orpd   %xmm1,%xmm0
movapd %xmm0,%xmm1
add    $0xffffffff,%ebx
jne    11e0 <ran_binomial+0x70>
jmp    14e5 <ran_binomial+0x375>
mulsd  %xmm1,%xmm4
ucomisd %xmm4,%xmm3
movsd  %xmm2,0x8(%rsp)
jbe    129f <ran_binomial+0x12f>
xorpd  0xde4(%rip),%xmm4
movapd %xmm4,%xmm0
call   1030 <exp@plt>
movsd  0xdb3(%rip),%xmm1
movsd  %xmm0,0x28(%rsp)
add    $0x1,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1050 <ran_get@plt>
movapd %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  0x28(%rsp),%xmm0
ucomisd %xmm1,%xmm0
ja     136c <ran_binomial+0x1fc>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1260 <ran_binomial+0xf0>
movapd 0x30(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
jmp    14e5 <ran_binomial+0x375>
cmp    %ebx,0x2db3(%rip)
movapd %xmm4,0x40(%rsp)
je     12ee <ran_binomial+0x17e>
movapd 0x30(%rsp),%xmm1
movsd  %xmm1,0x2dcd(%rip)
movsd  0xd3d(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1080 <gammln@plt>
movapd 0x40(%rsp),%xmm4
movsd  0xd26(%rip),%xmm3
movsd  0x8(%rsp),%xmm2
movsd  %xmm0,0x2da8(%rip)
mov    %ebx,0x2d6a(%rip)
ucomisd 0x2d6a(%rip),%xmm2
jne    12fa <ran_binomial+0x18a>
jnp    1344 <ran_binomial+0x1d4>
movapd %xmm3,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,0x2d66(%rip)
movapd %xmm2,%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x2d5d(%rip)
movsd  0x2d4d(%rip),%xmm0
call   1060 <log@plt>
movapd 0x40(%rsp),%xmm4
movsd  0x8(%rsp),%xmm2
movsd  %xmm0,0x2d44(%rip)
movsd  %xmm2,0x2d1c(%rip)
addsd  %xmm4,%xmm4
mulsd  0x2d20(%rip),%xmm4
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm4
jb     137e <ran_binomial+0x20e>
xorps  %xmm0,%xmm0
sqrtsd %xmm4,%xmm0
jmp    1387 <ran_binomial+0x217>
xorpd  %xmm0,%xmm0
jmp    14e5 <ran_binomial+0x375>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0x8(%rsp),%xmm2
jmp    14e5 <ran_binomial+0x375>
movapd %xmm4,%xmm0
call   1070 <sqrt@plt>
movsd  0xc81(%rip),%xmm1
movsd  %xmm0,0x68(%rsp)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x60(%rsp)
mov    0x2c42(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
movsd  (%rbx),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1050 <ran_get@plt>
mulsd  0x10(%rsp),%xmm0
call   1040 <tan@plt>
movapd %xmm0,%xmm2
movsd  0x68(%rsp),%xmm0
mulsd  %xmm2,%xmm0
addsd  0x40(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movsd  0x2c98(%rip),%xmm1
addsd  0xc08(%rip),%xmm1
ja     13b0 <ran_binomial+0x240>
ucomisd %xmm1,%xmm0
jae    13b0 <ran_binomial+0x240>
movsd  %xmm2,0x10(%rsp)
call   1090 <floor@plt>
movapd %xmm0,%xmm2
movapd %xmm0,0x50(%rsp)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
movsd  0xbd9(%rip),%xmm3
addsd  %xmm3,%xmm1
mulsd  0x60(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x2c51(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
addsd  %xmm3,%xmm2
movapd %xmm2,%xmm0
call   1080 <gammln@plt>
movsd  0x28(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
movsd  0x2c1e(%rip),%xmm0
subsd  0x50(%rsp),%xmm0
addsd  0xb88(%rip),%xmm0
call   1080 <gammln@plt>
movsd  0x28(%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  0x2be9(%rip),%xmm1
movapd 0x50(%rsp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm3,%xmm1
movsd  0x2be3(%rip),%xmm0
subsd  %xmm2,%xmm0
mulsd  0x2bcf(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1030 <exp@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1050 <ran_get@plt>
ucomisd 0x10(%rsp),%xmm0
ja     13b0 <ran_binomial+0x240>
movsd  0x8(%rsp),%xmm2
movapd 0x50(%rsp),%xmm0
movapd 0x30(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd 0x70(%rsp),%xmm3
cmpneqsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
cvttsd2si %xmm3,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@ran_binomial.nold = internal unnamed_addr global i32 -1
@ran_binomial.pold = internal unnamed_addr global double -1.000000e+00
@ran_binomial.pc = internal unnamed_addr global double 0.000000e+00
@ran_binomial.plog = internal unnamed_addr global double 0.000000e+00
@ran_binomial.pclog = internal unnamed_addr global double 0.000000e+00
@ran_binomial.en = internal unnamed_addr global double 0.000000e+00
@ran_binomial.oldg = internal unnamed_addr global double 0.000000e+00
@M_PI = global double 0.000000e+00
define i32 @ran_binomial(double %0, i32 %1) {
%3 = fcmp ole double %0, 5.000000e-01
%4 = fsub double 1.000000e+00, %0
%5 = select i1 %3, double %0, double %4
%6 = sitofp i32 %1 to double
%7 = fmul double %5, %6
%8 = icmp slt i32 %1, 25
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = icmp slt i32 %1, 1
br i1 %10, label %91, label %11
11: ; preds = %9, %11
%12 = phi i32 [ %18, %11 ], [ 1, %9 ]
%13 = phi double [ %17, %11 ], [ 0.000000e+00, %9 ]
%14 = tail call double (...) @ran_get()
%15 = fcmp olt double %14, %5
%16 = fadd double %13, 1.000000e+00
%17 = select i1 %15, double %16, double %13
%18 = add nuw i32 %12, 1
%19 = icmp eq i32 %12, %1
br i1 %19, label %91, label %11
20: ; preds = %2
%21 = fcmp olt double %7, 1.000000e+00
br i1 %21, label %22, label %36
22: ; preds = %20
%23 = fneg double %7
%24 = tail call double @exp(double %23)
br label %25
25: ; preds = %22, %33
%26 = phi i32 [ %34, %33 ], [ 0, %22 ]
%27 = phi double [ %29, %33 ], [ 1.000000e+00, %22 ]
%28 = tail call double (...) @ran_get()
%29 = fmul double %27, %28
%30 = fcmp olt double %29, %24
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = sitofp i32 %26 to double
br label %91
33: ; preds = %25
%34 = add nuw i32 %26, 1
%35 = icmp eq i32 %26, %1
br i1 %35, label %91, label %25
36: ; preds = %20
%37 = load i32, i32* @ran_binomial.nold
%38 = icmp eq i32 %37, %1
br i1 %38, label %42, label %39
39: ; preds = %36
store double %6, double* @ran_binomial.en
%40 = fadd double %6, 1.000000e+00
%41 = tail call double @gammln(double %40)
store double %41, double* @ran_binomial.oldg
store i32 %1, i32* @ran_binomial.nold
br label %42
42: ; preds = %39, %36
%43 = load double, double* @ran_binomial.pold
%44 = fcmp une double %5, %43
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = fsub double 1.000000e+00, %5
store double %46, double* @ran_binomial.pc
%47 = tail call double @log(double %5)
store double %47, double* @ran_binomial.plog
%48 = load double, double* @ran_binomial.pc
%49 = tail call double @log(double %48)
store double %49, double* @ran_binomial.pclog
store double %5, double* @ran_binomial.pold
br label %50
50: ; preds = %45, %42
%51 = fmul double %7, 2.000000e+00
%52 = load double, double* @ran_binomial.pc
%53 = fmul double %51, %52
%54 = tail call double @sqrt(double %53)
%55 = fmul double %54, 1.200000e+00
br label %56
56: ; preds = %67, %50
%57 = load double, double* @M_PI
%58 = tail call double (...) @ran_get()
%59 = fmul double %57, %58
%60 = tail call double @tan(double %59)
%61 = tail call double @llvm.fmuladd.f64(double %54, double %60, double %7)
%62 = fcmp olt double %61, 0.000000e+00
%63 = load double, double* @ran_binomial.en
%64 = fadd double %63, 1.000000e+00
%65 = fcmp oge double %61, %64
%66 = select i1 %62, i1 true, i1 %65
br i1 %66, label %67, label %68
67: ; preds = %56, %68
br label %56
68: ; preds = %56
%69 = tail call double @llvm.floor.f64(double %61)
%70 = tail call double @llvm.fmuladd.f64(double %60, double %60, double 1.000000e+00)
%71 = fmul double %55, %70
%72 = load double, double* @ran_binomial.oldg
%73 = fadd double %69, 1.000000e+00
%74 = tail call double @gammln(double %73)
%75 = fsub double %72, %74
%76 = load double, double* @ran_binomial.en
%77 = fsub double %76, %69
%78 = fadd double %77, 1.000000e+00
%79 = tail call double @gammln(double %78)
%80 = fsub double %75, %79
%81 = load double, double* @ran_binomial.plog
%82 = tail call double @llvm.fmuladd.f64(double %69, double %81, double %80)
%83 = load double, double* @ran_binomial.en
%84 = fsub double %83, %69
%85 = load double, double* @ran_binomial.pclog
%86 = tail call double @llvm.fmuladd.f64(double %84, double %85, double %82)
%87 = tail call double @exp(double %86)
%88 = fmul double %71, %87
%89 = tail call double (...) @ran_get()
%90 = fcmp ogt double %89, %88
br i1 %90, label %67, label %91
91: ; preds = %68, %33, %11, %31, %9
%92 = phi double [ 0.000000e+00, %9 ], [ %32, %31 ], [ %17, %11 ], [ %6, %33 ], [ %69, %68 ]
%93 = fcmp une double %5, %0
%94 = fsub double %6, %92
%95 = select i1 %93, double %94, double %92
%96 = fptosi double %95 to i32
ret i32 %96
}