#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 */
int drnd();
double exp(double);
int floor(double);
double norm();
double sqrt(double);
int getpois(double la) {
  int i;
  double x, y;
  if (la > 500) {
    i = floor(norm() * sqrt(la) + la + .5);
    if (i < 0)
      i = 0;
    return i;
  }
  x = drnd() - 1e-10;
  y = exp(-la);
  i = 0;
  while (1) {
    x -= y;
    if (x < 0)
      return i;
    i++;
    y *= la / i;
  }
}


x86 assembly (clang, -O0):
<getpois>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe96(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cf <getpois+0x7f>
mov    $0x0,%al
call   1040 <norm@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe69(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1070 <floor@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c4 <getpois+0x74>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126a <getpois+0x11a>
mov    $0x0,%al
call   1030 <drnd@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe26(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1244 <getpois+0xf4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126a <getpois+0x11a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1218 <getpois+0xc8>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpois>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,0x10(%rsp)
xor    %ebx,%ebx
xor    %eax,%eax
ucomisd 0xe99(%rip),%xmm0
jbe    1192 <getpois+0x42>
call   1040 <norm@plt>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     1202 <getpois+0xb2>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    121d <getpois+0xcd>
call   1030 <drnd@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xe62(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0xe6c(%rip),%xmm0
xorpd  0x10(%rsp),%xmm0
call   1050 <exp@plt>
movsd  0x8(%rsp),%xmm5
subsd  %xmm0,%xmm5
xorpd  %xmm1,%xmm1
ucomisd %xmm5,%xmm1
movapd 0x10(%rsp),%xmm4
ja     123b <getpois+0xeb>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
xorps  %xmm2,%xmm2
cvtsi2sd %ebx,%xmm2
movapd %xmm4,%xmm3
divsd  %xmm2,%xmm3
mulsd  %xmm3,%xmm0
subsd  %xmm0,%xmm5
ucomisd %xmm5,%xmm1
jbe    11e0 <getpois+0x90>
jmp    123b <getpois+0xeb>
movapd %xmm1,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1060 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movapd 0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
addsd  0xde3(%rip),%xmm2
movapd %xmm2,%xmm0
call   1070 <floor@plt>
test   %eax,%eax
cmovns %eax,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @getpois(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store double %0, double* %3
%7 = load double, double* %3
%8 = fcmp ogt double %7, 5.000000e+02
br i1 %8, label %9, label %22
9: ; preds = %1
%10 = call double (...) @norm()
%11 = load double, double* %3
%12 = call double @sqrt(double %11)
%13 = load double, double* %3
%14 = call double @llvm.fmuladd.f64(double %10, double %12, double %13)
%15 = fadd double %14, 5.000000e-01
%16 = call i32 @floor(double %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %9
store i32 0, i32* %4
br label %20
20: ; preds = %19, %9
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %46
22: ; preds = %1
%23 = call i32 (...) @drnd()
%24 = sitofp i32 %23 to double
%25 = fsub double %24, 1.000000e-10
store double %25, double* %5
%26 = load double, double* %3
%27 = fneg double %26
%28 = call double @exp(double %27)
store double %28, double* %6
store i32 0, i32* %4
br label %29
29: ; preds = %22, %37
%30 = load double, double* %6
%31 = load double, double* %5
%32 = fsub double %31, %30
store double %32, double* %5
%33 = load double, double* %5
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = load i32, i32* %4
store i32 %36, i32* %2
br label %46
37: ; preds = %29
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
%40 = load double, double* %3
%41 = load i32, i32* %4
%42 = sitofp i32 %41 to double
%43 = fdiv double %40, %42
%44 = load double, double* %6
%45 = fmul double %44, %43
store double %45, double* %6
br label %29
46: ; preds = %35, %20
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
define i32 @getpois(double %0) {
%2 = fcmp ogt double %0, 5.000000e+02
br i1 %2, label %3, label %11
3: ; preds = %1
%4 = tail call double (...) @norm()
%5 = tail call double @sqrt(double %0)
%6 = tail call double @llvm.fmuladd.f64(double %4, double %5, double %0)
%7 = fadd double %6, 5.000000e-01
%8 = tail call i32 @floor(double %7)
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 0
br label %29
11: ; preds = %1
%12 = tail call i32 (...) @drnd()
%13 = sitofp i32 %12 to double
%14 = fadd double %13, -1.000000e-10
%15 = fneg double %0
%16 = tail call double @exp(double %15)
%17 = fsub double %14, %16
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %29, label %19
19: ; preds = %11, %19
%20 = phi double [ %27, %19 ], [ %17, %11 ]
%21 = phi double [ %26, %19 ], [ %16, %11 ]
%22 = phi i32 [ %23, %19 ], [ 0, %11 ]
%23 = add nuw nsw i32 %22, 1
%24 = sitofp i32 %23 to double
%25 = fdiv double %0, %24
%26 = fmul double %21, %25
%27 = fsub double %20, %26
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %19
29: ; preds = %19, %11, %3
%30 = phi i32 [ %10, %3 ], [ 0, %11 ], [ %23, %19 ]
ret i32 %30
}