#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 exp(double);
double floor(double);
double log(double);
double rq_log_gamma(double);
double rq_random_normal();
double sqrt(double);
double tan(double);
double rq_random_poisson(double xm) {
  static double sq;
  static double alxm;
  static double g;
  static double oldm;
  double em;
  if (xm < 12.0) {
    double t = 1.0;
    if (xm != oldm) {
      oldm = xm;
      g = exp(-xm);
    }
    em = -1;
    do {
      ++em;
      t *= rq_random_normal();
    } while (t > g);
  } else {
    double t;
    if (xm != oldm) {
      oldm = xm;
      sq = sqrt(2.0 * xm);
      alxm = log(xm);
      g = xm * alxm - rq_log_gamma(xm + 1.0);
    }
    do {
      double y;
      do {
        y = tan(3.14159265358979323846264338328 * rq_random_normal());
        em = sq * y + xm;
      } while (em < 0.0);
      em = floor(em);
      t = 0.9 * (1.0 + y * y) * exp(em * alxm - rq_log_gamma(em + 1.0) - g);
    } while (rq_random_normal() > t);
  }
  return em;
}


x86 assembly (clang, -O0):
<rq_random_poisson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xe7b(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1239 <rq_random_poisson+0xc9>
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd 0x2ece(%rip),%xmm0
jne    11bb <rq_random_poisson+0x4b>
jp     11bb <rq_random_poisson+0x4b>
jmp    11f1 <rq_random_poisson+0x81>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2eb0(%rip)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x2e7f(%rip)
movsd  0xe2f(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe02(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rq_random_normal@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd 0x2e42(%rip),%xmm0
ja     11fe <rq_random_poisson+0x8e>
jmp    1408 <rq_random_poisson+0x298>
movsd  -0x8(%rbp),%xmm0
ucomisd 0x2e32(%rip),%xmm0
jne    1257 <rq_random_poisson+0xe7>
jp     1257 <rq_random_poisson+0xe7>
jmp    12ed <rq_random_poisson+0x17d>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2e14(%rip)
movsd  0xda4(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1080 <sqrt@plt>
movsd  %xmm0,0x2de2(%rip)
movsd  -0x8(%rbp),%xmm0
call   1070 <log@plt>
movsd  %xmm0,0x2dd8(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0x2dc6(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xd59(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1040 <rq_log_gamma@plt>
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2d83(%rip)
jmp    12f2 <rq_random_poisson+0x182>
jmp    12f7 <rq_random_poisson+0x187>
mov    $0x0,%al
call   1030 <rq_random_normal@plt>
movaps %xmm0,%xmm1
movsd  0xd0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <tan@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0x2d41(%rip),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     12f7 <rq_random_poisson+0x187>
movsd  -0x10(%rbp),%xmm0
call   1090 <floor@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xc9f(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xcab(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0x2cd8(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xc6b(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1040 <rq_log_gamma@plt>
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  0x2c95(%rip),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <rq_random_normal@plt>
ucomisd -0x20(%rbp),%xmm0
ja     12f2 <rq_random_poisson+0x182>
jmp    1408 <rq_random_poisson+0x298>
movsd  -0x10(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_random_poisson>:
sub    $0x28,%rsp
movapd %xmm0,%xmm2
movsd  0xe80(%rip),%xmm0
ucomisd %xmm2,%xmm0
movsd  0x2eec(%rip),%xmm0
jbe    1208 <rq_random_poisson+0x98>
ucomisd %xmm2,%xmm0
jne    1196 <rq_random_poisson+0x26>
jnp    11b7 <rq_random_poisson+0x47>
movsd  %xmm2,0x2eda(%rip)
xorpd  0xe8a(%rip),%xmm2
movapd %xmm2,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x2eb9(%rip)
movsd  0xe61(%rip),%xmm0
movsd  0xe41(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
addsd  0xe2b(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rq_random_normal@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
ucomisd 0x2e6f(%rip),%xmm1
ja     11d0 <rq_random_poisson+0x60>
add    $0x28,%rsp
ret
ucomisd %xmm2,%xmm0
movapd %xmm2,0x10(%rsp)
jne    1216 <rq_random_poisson+0xa6>
jnp    1290 <rq_random_poisson+0x120>
movsd  %xmm2,0x2e5a(%rip)
movapd %xmm2,%xmm0
addsd  %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1236 <rq_random_poisson+0xc6>
sqrtsd %xmm0,%xmm0
jmp    1241 <rq_random_poisson+0xd1>
call   1080 <sqrt@plt>
movapd 0x10(%rsp),%xmm2
movsd  %xmm0,0x2e17(%rip)
movapd %xmm2,%xmm0
call   1070 <log@plt>
movsd  %xmm0,(%rsp)
movsd  %xmm0,0x2e09(%rip)
movsd  0xda1(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
call   1040 <rq_log_gamma@plt>
movsd  (%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x2de7(%rip)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rq_random_normal@plt>
mulsd  0xd71(%rip),%xmm0
call   1060 <tan@plt>
movapd %xmm0,%xmm2
movsd  0x2db0(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1290 <rq_random_poisson+0x120>
movsd  %xmm2,(%rsp)
call   1090 <floor@plt>
movapd %xmm0,%xmm2
movsd  (%rsp),%xmm3
mulsd  %xmm3,%xmm3
movsd  0xd25(%rip),%xmm1
addsd  %xmm1,%xmm3
mulsd  0xd29(%rip),%xmm3
movsd  %xmm3,(%rsp)
addsd  %xmm1,%xmm0
movsd  0x2d68(%rip),%xmm1
movsd  %xmm2,0x8(%rsp)
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1040 <rq_log_gamma@plt>
movsd  0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
subsd  0x2d49(%rip),%xmm1
movapd %xmm1,%xmm0
call   1050 <exp@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <rq_random_normal@plt>
ucomisd (%rsp),%xmm0
ja     1290 <rq_random_poisson+0x120>
movsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@rq_random_poisson.sq = internal global double 0.000000e+00
@rq_random_poisson.alxm = internal global double 0.000000e+00
@rq_random_poisson.g = internal global double 0.000000e+00
@rq_random_poisson.oldm = internal global double 0.000000e+00
define double @rq_random_poisson(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %2
%7 = load double, double* %2
%8 = fcmp olt double %7, 1.200000e+01
br i1 %8, label %9, label %30
9: ; preds = %1
store double 1.000000e+00, double* %4
%10 = load double, double* %2
%11 = load double, double* @rq_random_poisson.oldm
%12 = fcmp une double %10, %11
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load double, double* %2
store double %14, double* @rq_random_poisson.oldm
%15 = load double, double* %2
%16 = fneg double %15
%17 = call double @exp(double %16)
store double %17, double* @rq_random_poisson.g
br label %18
18: ; preds = %13, %9
store double -1.000000e+00, double* %3
br label %19
19: ; preds = %25, %18
%20 = load double, double* %3
%21 = fadd double %20, 1.000000e+00
store double %21, double* %3
%22 = call double (...) @rq_random_normal()
%23 = load double, double* %4
%24 = fmul double %23, %22
store double %24, double* %4
br label %25
25: ; preds = %19
%26 = load double, double* %4
%27 = load double, double* @rq_random_poisson.g
%28 = fcmp ogt double %26, %27
br i1 %28, label %19, label %29
29: ; preds = %25
br label %84
30: ; preds = %1
%31 = load double, double* %2
%32 = load double, double* @rq_random_poisson.oldm
%33 = fcmp une double %31, %32
br i1 %33, label %34, label %48
34: ; preds = %30
%35 = load double, double* %2
store double %35, double* @rq_random_poisson.oldm
%36 = load double, double* %2
%37 = fmul double 2.000000e+00, %36
%38 = call double @sqrt(double %37)
store double %38, double* @rq_random_poisson.sq
%39 = load double, double* %2
%40 = call double @log(double %39)
store double %40, double* @rq_random_poisson.alxm
%41 = load double, double* %2
%42 = load double, double* @rq_random_poisson.alxm
%43 = load double, double* %2
%44 = fadd double %43, 1.000000e+00
%45 = call double @rq_log_gamma(double %44)
%46 = fneg double %45
%47 = call double @llvm.fmuladd.f64(double %41, double %42, double %46)
store double %47, double* @rq_random_poisson.g
br label %48
48: ; preds = %34, %30
br label %49
49: ; preds = %79, %48
br label %50
50: ; preds = %58, %49
%51 = call double (...) @rq_random_normal()
%52 = fmul double 0x400921FB54442D18, %51
%53 = call double @tan(double %52)
store double %53, double* %6
%54 = load double, double* @rq_random_poisson.sq
%55 = load double, double* %6
%56 = load double, double* %2
%57 = call double @llvm.fmuladd.f64(double %54, double %55, double %56)
store double %57, double* %3
br label %58
58: ; preds = %50
%59 = load double, double* %3
%60 = fcmp olt double %59, 0.000000e+00
br i1 %60, label %50, label %61
61: ; preds = %58
%62 = load double, double* %3
%63 = call double @llvm.floor.f64(double %62)
store double %63, double* %3
%64 = load double, double* %6
%65 = load double, double* %6
%66 = call double @llvm.fmuladd.f64(double %64, double %65, double 1.000000e+00)
%67 = fmul double 9.000000e-01, %66
%68 = load double, double* %3
%69 = load double, double* @rq_random_poisson.alxm
%70 = load double, double* %3
%71 = fadd double %70, 1.000000e+00
%72 = call double @rq_log_gamma(double %71)
%73 = fneg double %72
%74 = call double @llvm.fmuladd.f64(double %68, double %69, double %73)
%75 = load double, double* @rq_random_poisson.g
%76 = fsub double %74, %75
%77 = call double @exp(double %76)
%78 = fmul double %67, %77
store double %78, double* %5
br label %79
79: ; preds = %61
%80 = call double (...) @rq_random_normal()
%81 = load double, double* %5
%82 = fcmp ogt double %80, %81
br i1 %82, label %49, label %83
83: ; preds = %79
br label %84
84: ; preds = %83, %29
%85 = load double, double* %3
ret double %85
}

LLVM IR (-O2):
@rq_random_poisson.sq = internal unnamed_addr global double 0.000000e+00
@rq_random_poisson.alxm = internal unnamed_addr global double 0.000000e+00
@rq_random_poisson.g = internal unnamed_addr global double 0.000000e+00
@rq_random_poisson.oldm = internal unnamed_addr global double 0.000000e+00
define double @rq_random_poisson(double %0) {
%2 = fcmp olt double %0, 1.200000e+01
%3 = load double, double* @rq_random_poisson.oldm
%4 = fcmp une double %3, %0
br i1 %2, label %5, label %18
5: ; preds = %1
br i1 %4, label %6, label %9
6: ; preds = %5
store double %0, double* @rq_random_poisson.oldm
%7 = fneg double %0
%8 = tail call double @exp(double %7)
store double %8, double* @rq_random_poisson.g
br label %9
9: ; preds = %6, %5
br label %10
10: ; preds = %9, %10
%11 = phi double [ %15, %10 ], [ 1.000000e+00, %9 ]
%12 = phi double [ %13, %10 ], [ -1.000000e+00, %9 ]
%13 = fadd double %12, 1.000000e+00
%14 = tail call double (...) @rq_random_normal()
%15 = fmul double %11, %14
%16 = load double, double* @rq_random_poisson.g
%17 = fcmp ogt double %15, %16
br i1 %17, label %10, label %51
18: ; preds = %1
br i1 %4, label %19, label %27
19: ; preds = %18
store double %0, double* @rq_random_poisson.oldm
%20 = fmul double %0, 2.000000e+00
%21 = tail call double @sqrt(double %20)
store double %21, double* @rq_random_poisson.sq
%22 = tail call double @log(double %0)
store double %22, double* @rq_random_poisson.alxm
%23 = fadd double %0, 1.000000e+00
%24 = tail call double @rq_log_gamma(double %23)
%25 = fneg double %24
%26 = tail call double @llvm.fmuladd.f64(double %0, double %22, double %25)
store double %26, double* @rq_random_poisson.g
br label %27
27: ; preds = %18, %19
br label %28
28: ; preds = %35, %27
%29 = tail call double (...) @rq_random_normal()
%30 = fmul double %29, 0x400921FB54442D18
%31 = tail call double @tan(double %30)
%32 = load double, double* @rq_random_poisson.sq
%33 = tail call double @llvm.fmuladd.f64(double %32, double %31, double %0)
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %36
35: ; preds = %28, %36
br label %28
36: ; preds = %28
%37 = tail call double @llvm.floor.f64(double %33)
%38 = tail call double @llvm.fmuladd.f64(double %31, double %31, double 1.000000e+00)
%39 = fmul double %38, 9.000000e-01
%40 = load double, double* @rq_random_poisson.alxm
%41 = fadd double %37, 1.000000e+00
%42 = tail call double @rq_log_gamma(double %41)
%43 = fneg double %42
%44 = tail call double @llvm.fmuladd.f64(double %37, double %40, double %43)
%45 = load double, double* @rq_random_poisson.g
%46 = fsub double %44, %45
%47 = tail call double @exp(double %46)
%48 = fmul double %39, %47
%49 = tail call double (...) @rq_random_normal()
%50 = fcmp ogt double %49, %48
br i1 %50, label %35, label %51
51: ; preds = %36, %10
%52 = phi double [ %13, %10 ], [ %37, %36 ]
ret double %52
}