#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 _log_factorial(long);
double _sqr(scalar_t__);
scalar_t__ exp(double);
scalar_t__ floor(double);
double log(double);
double mc_randf();
double sqrt(double);
long mc_poisson_large(double lambda) {
  double loglam, c, beta, alpha, k, u, v, x, y, lhs = 0, rhs = 0;
  long n = 0;
  loglam = log(lambda);
  c = 0.767 - 3.36 / lambda;
  beta = 3.14159265358979323846 / sqrt(3.0 * lambda);
  alpha = beta * lambda;
  k = log(c) - lambda - log(beta);
  do {
    u = mc_randf();
    x = (alpha - log((1.0 - u) / u)) / beta;
    n = (long)floor(x + 0.5);
    if (n < 0) {
      continue;
    }
    v = mc_randf();
    y = alpha - beta * x;
    lhs = y + log(v / _sqr(1.0 + exp(y)));
    rhs = k + n * loglam - _log_factorial(n);
  } while (lhs > rhs);
  return n;
}


x86 assembly (clang, -O0):
<mc_poisson_large>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xe69(%rip),%xmm1
divsd  -0x8(%rbp),%xmm1
movsd  0xe54(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe3b(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe1e(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <mc_randf@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xde1(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
subsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdac(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
call   1090 <floor@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jge    1292 <mc_poisson_large+0x122>
jmp    136f <mc_poisson_large+0x1ff>
mov    $0x0,%al
call   1040 <mc_randf@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
call   1050 <exp@plt>
cvtsi2sd %rax,%xmm1
movsd  0xd26(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1080 <_sqr@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm1
cvtsi2sdq -0x68(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x68(%rbp),%rdi
call   1030 <_log_factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
ja     1229 <mc_poisson_large+0xb9>
mov    -0x68(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mc_poisson_large>:
push   %rbx
sub    $0x70,%rsp
movsd  %xmm0,(%rsp)
call   1060 <log@plt>
movsd  %xmm0,0x48(%rsp)
movsd  0xe73(%rip),%xmm3
movsd  (%rsp),%xmm1
divsd  %xmm1,%xmm3
addsd  0xe6a(%rip),%xmm3
movsd  0xe6a(%rip),%xmm0
mulsd  %xmm1,%xmm0
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x28(%rsp)
ucomisd %xmm2,%xmm0
jb     11c4 <mc_poisson_large+0x54>
sqrtsd %xmm0,%xmm0
jmp    11d5 <mc_poisson_large+0x65>
movsd  %xmm3,0x10(%rsp)
call   1070 <sqrt@plt>
movsd  0x10(%rsp),%xmm3
movsd  0xe3b(%rip),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,0x30(%rsp)
movapd %xmm1,%xmm0
mulsd  (%rsp),%xmm0
movapd %xmm0,0x50(%rsp)
movapd %xmm3,%xmm0
call   1060 <log@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x30(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd 0xe03(%rip),%xmm0
xorpd  0x30(%rsp),%xmm0
movapd %xmm0,0x60(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
jmp    1261 <mc_poisson_large+0xf1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x28(%rsp),%xmm0
ucomisd (%rsp),%xmm0
jbe    1345 <mc_poisson_large+0x1d5>
xor    %eax,%eax
call   1040 <mc_randf@plt>
movsd  0xdb0(%rip),%xmm1
subsd  %xmm0,%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1060 <log@plt>
movapd 0x50(%rsp),%xmm1
subsd  %xmm0,%xmm1
divsd  0x30(%rsp),%xmm1
movapd %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
addsd  0xd85(%rip),%xmm0
call   1090 <floor@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1250 <mc_poisson_large+0xe0>
xor    %eax,%eax
call   1040 <mc_randf@plt>
movsd  %xmm0,(%rsp)
movapd 0x10(%rsp),%xmm0
mulsd  0x60(%rsp),%xmm0
addsd  0x50(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
call   1050 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0xd37(%rip),%xmm0
cvttsd2si %xmm0,%rdi
call   1080 <_sqr@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1060 <log@plt>
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mulsd  0x48(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <_log_factorial@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
jmp    1250 <mc_poisson_large+0xe0>
mov    %rbx,%rax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @mc_poisson_large(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%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 i64
store double %0, double* %2
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store i64 0, i64* %14
%15 = load double, double* %2
%16 = call double @log(double %15)
store double %16, double* %3
%17 = load double, double* %2
%18 = fdiv double 3.360000e+00, %17
%19 = fsub double 7.670000e-01, %18
store double %19, double* %4
%20 = load double, double* %2
%21 = fmul double 3.000000e+00, %20
%22 = call double @sqrt(double %21)
%23 = fdiv double 0x400921FB54442D18, %22
store double %23, double* %5
%24 = load double, double* %5
%25 = load double, double* %2
%26 = fmul double %24, %25
store double %26, double* %6
%27 = load double, double* %4
%28 = call double @log(double %27)
%29 = load double, double* %2
%30 = fsub double %28, %29
%31 = load double, double* %5
%32 = call double @log(double %31)
%33 = fsub double %30, %32
store double %33, double* %7
br label %34
34: ; preds = %77, %1
%35 = call double (...) @mc_randf()
store double %35, double* %8
%36 = load double, double* %6
%37 = load double, double* %8
%38 = fsub double 1.000000e+00, %37
%39 = load double, double* %8
%40 = fdiv double %38, %39
%41 = call double @log(double %40)
%42 = fsub double %36, %41
%43 = load double, double* %5
%44 = fdiv double %42, %43
store double %44, double* %10
%45 = load double, double* %10
%46 = fadd double %45, 5.000000e-01
%47 = call i64 @floor(double %46)
store i64 %47, i64* %14
%48 = load i64, i64* %14
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %34
br label %77
51: ; preds = %34
%52 = call double (...) @mc_randf()
store double %52, double* %9
%53 = load double, double* %6
%54 = load double, double* %5
%55 = load double, double* %10
%56 = fneg double %54
%57 = call double @llvm.fmuladd.f64(double %56, double %55, double %53)
store double %57, double* %11
%58 = load double, double* %11
%59 = load double, double* %9
%60 = load double, double* %11
%61 = call i64 @exp(double %60)
%62 = sitofp i64 %61 to double
%63 = fadd double 1.000000e+00, %62
%64 = fptosi double %63 to i64
%65 = call double @_sqr(i64 %64)
%66 = fdiv double %59, %65
%67 = call double @log(double %66)
%68 = fadd double %58, %67
store double %68, double* %12
%69 = load double, double* %7
%70 = load i64, i64* %14
%71 = sitofp i64 %70 to double
%72 = load double, double* %3
%73 = call double @llvm.fmuladd.f64(double %71, double %72, double %69)
%74 = load i64, i64* %14
%75 = call double @_log_factorial(i64 %74)
%76 = fsub double %73, %75
store double %76, double* %13
br label %77
77: ; preds = %51, %50
%78 = load double, double* %12
%79 = load double, double* %13
%80 = fcmp ogt double %78, %79
br i1 %80, label %34, label %81
81: ; preds = %77
%82 = load i64, i64* %14
ret i64 %82
}

LLVM IR (-O2):
define i64 @mc_poisson_large(double %0) {
%2 = tail call double @log(double %0)
%3 = fdiv double 3.360000e+00, %0
%4 = fsub double 7.670000e-01, %3
%5 = fmul double %0, 3.000000e+00
%6 = tail call double @sqrt(double %5)
%7 = fdiv double 0x400921FB54442D18, %6
%8 = fmul double %7, %0
%9 = tail call double @log(double %4)
%10 = fsub double %9, %0
%11 = tail call double @log(double %7)
%12 = fsub double %10, %11
%13 = fneg double %7
br label %14
14: ; preds = %41, %1
%15 = phi double [ 0.000000e+00, %1 ], [ %42, %41 ]
%16 = phi double [ 0.000000e+00, %1 ], [ %43, %41 ]
%17 = tail call double (...) @mc_randf()
%18 = fsub double 1.000000e+00, %17
%19 = fdiv double %18, %17
%20 = tail call double @log(double %19)
%21 = fsub double %8, %20
%22 = fdiv double %21, %7
%23 = fadd double %22, 5.000000e-01
%24 = tail call i64 @floor(double %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %41, label %26
26: ; preds = %14
%27 = tail call double (...) @mc_randf()
%28 = tail call double @llvm.fmuladd.f64(double %13, double %22, double %8)
%29 = tail call i64 @exp(double %28)
%30 = sitofp i64 %29 to double
%31 = fadd double %30, 1.000000e+00
%32 = fptosi double %31 to i64
%33 = tail call double @_sqr(i64 %32)
%34 = fdiv double %27, %33
%35 = tail call double @log(double %34)
%36 = fadd double %28, %35
%37 = sitofp i64 %24 to double
%38 = tail call double @llvm.fmuladd.f64(double %37, double %2, double %12)
%39 = tail call double @_log_factorial(i64 %24)
%40 = fsub double %38, %39
br label %41
41: ; preds = %14, %26
%42 = phi double [ %15, %14 ], [ %36, %26 ]
%43 = phi double [ %16, %14 ], [ %40, %26 ]
%44 = fcmp ogt double %42, %43
br i1 %44, label %14, label %45
45: ; preds = %41
ret i64 %24
}