#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 cdfPoisson(double, long);
long idfPoisson(double m, double u) {
  long x = (long)m;
  if (cdfPoisson(m, x) <= u)
    while (cdfPoisson(m, x) <= u)
      x++;
  else if (cdfPoisson(m, 0) <= u)
    while (cdfPoisson(m, x - 1) > u)
      x--;
  else
    x = 0;
  return (x);
}


x86 assembly (clang, -O0):
<idfPoisson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
cvttsd2si -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1030 <cdfPoisson@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1187 <idfPoisson+0x77>
jmp    1151 <idfPoisson+0x41>
movsd  -0x8(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1030 <cdfPoisson@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1182 <idfPoisson+0x72>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <idfPoisson+0x41>
jmp    11ec <idfPoisson+0xdc>
movsd  -0x8(%rbp),%xmm0
xor    %eax,%eax
mov    %eax,%edi
call   1030 <cdfPoisson@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11df <idfPoisson+0xcf>
jmp    11ac <idfPoisson+0x9c>
movsd  -0x8(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
sub    $0x1,%rdi
call   1030 <cdfPoisson@plt>
ucomisd -0x10(%rbp),%xmm0
jbe    11da <idfPoisson+0xca>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11ac <idfPoisson+0x9c>
jmp    11e7 <idfPoisson+0xd7>
movq   $0x0,-0x18(%rbp)
jmp    11ec <idfPoisson+0xdc>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idfPoisson>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x8(%rsp)
cvttsd2si %xmm0,%rbx
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <cdfPoisson@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    1180 <idfPoisson+0x70>
xor    %r14d,%r14d
movsd  0x10(%rsp),%xmm0
xor    %edi,%edi
call   1030 <cdfPoisson@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     11a5 <idfPoisson+0x95>
add    $0x1,%rbx
mov    %rbx,%r14
nop
lea    -0x2(%r14),%rdi
movsd  0x10(%rsp),%xmm0
call   1030 <cdfPoisson@plt>
add    $0xffffffffffffffff,%r14
ucomisd 0x8(%rsp),%xmm0
ja     1160 <idfPoisson+0x50>
jmp    11a5 <idfPoisson+0x95>
nopl   (%rax)
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
call   1030 <cdfPoisson@plt>
add    $0x1,%rbx
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    1180 <idfPoisson+0x70>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%r14
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @idfPoisson(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i64
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %3
%7 = fptosi double %6 to i64
store i64 %7, i64* %5
%8 = load double, double* %3
%9 = load i64, i64* %5
%10 = call double @cdfPoisson(double %8, i64 %9)
%11 = load double, double* %4
%12 = fcmp ole double %10, %11
br i1 %12, label %13, label %24
13: ; preds = %2
br label %14
14: ; preds = %20, %13
%15 = load double, double* %3
%16 = load i64, i64* %5
%17 = call double @cdfPoisson(double %15, i64 %16)
%18 = load double, double* %4
%19 = fcmp ole double %17, %18
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i64, i64* %5
%22 = add nsw i64 %21, 1
store i64 %22, i64* %5
br label %14
23: ; preds = %14
br label %43
24: ; preds = %2
%25 = load double, double* %3
%26 = call double @cdfPoisson(double %25, i64 0)
%27 = load double, double* %4
%28 = fcmp ole double %26, %27
br i1 %28, label %29, label %41
29: ; preds = %24
br label %30
30: ; preds = %37, %29
%31 = load double, double* %3
%32 = load i64, i64* %5
%33 = sub nsw i64 %32, 1
%34 = call double @cdfPoisson(double %31, i64 %33)
%35 = load double, double* %4
%36 = fcmp ogt double %34, %35
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i64, i64* %5
%39 = add nsw i64 %38, -1
store i64 %39, i64* %5
br label %30
40: ; preds = %30
br label %42
41: ; preds = %24
store i64 0, i64* %5
br label %42
42: ; preds = %41, %40
br label %43
43: ; preds = %42, %23
%44 = load i64, i64* %5
ret i64 %44
}

LLVM IR (-O2):
define i64 @idfPoisson(double %0, double %1) {
%3 = fptosi double %0 to i64
%4 = tail call double @cdfPoisson(double %0, i64 %3)
%5 = fcmp ugt double %4, %1
br i1 %5, label %11, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %10, %6 ], [ %3, %2 ]
%8 = tail call double @cdfPoisson(double %0, i64 %7)
%9 = fcmp ugt double %8, %1
%10 = add nsw i64 %7, 1
br i1 %9, label %19, label %6
11: ; preds = %2
%12 = tail call double @cdfPoisson(double %0, i64 0)
%13 = fcmp ugt double %12, %1
br i1 %13, label %19, label %14
14: ; preds = %11, %14
%15 = phi i64 [ %16, %14 ], [ %3, %11 ]
%16 = add nsw i64 %15, -1
%17 = tail call double @cdfPoisson(double %0, i64 %16)
%18 = fcmp ogt double %17, %1
br i1 %18, label %14, label %19
19: ; preds = %6, %14, %11
%20 = phi i64 [ 0, %11 ], [ %15, %14 ], [ %7, %6 ]
ret i64 %20
}