#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 */
float M_LN10;
int /*<<< orphan*/ exp(int);
int fabs(float);
float log(int);
float log1p(int /*<<< orphan*/);
float log10_poisson_cdf_Q_large_lambda(unsigned int k, float lbd) {
  float residue = 0;
  float logx = 0;
  float ln_lbd = log(lbd);
  float logy, pre_residue;
  int m = k + 1;
  float sum_ln_m = 0;
  int i;
  for (i = 2; i <= m; i++)
    sum_ln_m += log(i);
  logx = m * ln_lbd - sum_ln_m;
  residue = logx;
  while (1) {
    m++;
    logy = logx + ln_lbd - log(m);
    pre_residue = residue;
    residue = ((pre_residue) > (logy) ? (pre_residue) : (logy)) +
              log1p(exp(-fabs(pre_residue - logy)));
    if (fabs(pre_residue - residue) < 1e-5)
      break;
    logx = logy;
  }
  return (residue - lbd) / M_LN10;
}


x86 assembly (clang, -O0):
<log10_poisson_cdf_Q_large_lambda>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
cvttss2si -0x8(%rbp),%edi
call   1050 <log@plt>
movss  %xmm0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     11b3 <log10_poisson_cdf_Q_large_lambda+0x73>
mov    -0x28(%rbp),%edi
call   1050 <log@plt>
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1187 <log10_poisson_cdf_Q_large_lambda+0x47>
cvtsi2ssl -0x20(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <log@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    123f <log10_poisson_cdf_Q_large_lambda+0xff>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    1249 <log10_poisson_cdf_Q_large_lambda+0x109>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x1c(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
call   1030 <fabs@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1040 <exp@plt>
mov    %eax,%edi
call   1060 <log1p@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x1c(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd62(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12ad <log10_poisson_cdf_Q_large_lambda+0x16d>
jmp    12bc <log10_poisson_cdf_Q_large_lambda+0x17c>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    11e6 <log10_poisson_cdf_Q_large_lambda+0xa6>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
mov    0x2d13(%rip),%rax
divss  (%rax),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log10_poisson_cdf_Q_large_lambda>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
movss  %xmm0,0x14(%rsp)
cvttss2si %xmm0,%edi
call   1050 <log@plt>
movss  %xmm0,0xc(%rsp)
lea    0x1(%r14),%r15d
xorps  %xmm2,%xmm2
cmp    $0x2,%r15d
jl     11a9 <log10_poisson_cdf_Q_large_lambda+0x69>
mov    %r14d,%ebp
neg    %ebp
xorps  %xmm2,%xmm2
mov    $0x2,%ebx
nopl   0x0(%rax)
movss  %xmm2,0x4(%rsp)
mov    %ebx,%edi
call   1050 <log@plt>
movss  0x4(%rsp),%xmm2
addss  %xmm0,%xmm2
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x2,%eax
jne    1180 <log10_poisson_cdf_Q_large_lambda+0x40>
cvtsi2ss %r15d,%xmm1
movss  0xc(%rsp),%xmm0
mulss  %xmm0,%xmm1
subss  %xmm2,%xmm1
add    $0x2,%r14d
movss  %xmm1,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
movss  %xmm1,0x10(%rsp)
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
mov    %r14d,%edi
call   1050 <log@plt>
movss  0x4(%rsp),%xmm2
subss  %xmm0,%xmm2
movss  0x10(%rsp),%xmm1
movaps %xmm1,%xmm0
maxss  %xmm2,%xmm0
movss  %xmm0,0x8(%rsp)
movaps %xmm1,%xmm0
movss  %xmm2,0x4(%rsp)
subss  %xmm2,%xmm0
call   1030 <fabs@plt>
neg    %eax
mov    %eax,%edi
call   1040 <exp@plt>
mov    %eax,%edi
call   1060 <log1p@plt>
movaps %xmm0,%xmm1
addss  0x8(%rsp),%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x10(%rsp),%xmm0
subss  %xmm1,%xmm0
call   1030 <fabs@plt>
movss  0x8(%rsp),%xmm1
movss  0xc(%rsp),%xmm0
add    $0x1,%r14d
test   %eax,%eax
jg     11d0 <log10_poisson_cdf_Q_large_lambda+0x90>
subss  0x14(%rsp),%xmm1
mov    0x2d70(%rip),%rax
divss  (%rax),%xmm1
movaps %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_LN10 = global float 0.000000e+00
define float @log10_poisson_cdf_Q_large_lambda(i32 %0, float %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca float
%12 = alloca i32
store i32 %0, i32* %3
store float %1, float* %4
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
%13 = load float, float* %4
%14 = fptosi float %13 to i32
%15 = call float @log(i32 %14)
store float %15, float* %7
%16 = load i32, i32* %3
%17 = add i32 %16, 1
store i32 %17, i32* %10
store float 0.000000e+00, float* %11
store i32 2, i32* %12
br label %18
18: ; preds = %27, %2
%19 = load i32, i32* %12
%20 = load i32, i32* %10
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i32, i32* %12
%24 = call float @log(i32 %23)
%25 = load float, float* %11
%26 = fadd float %25, %24
store float %26, float* %11
br label %27
27: ; preds = %22
%28 = load i32, i32* %12
%29 = add nsw i32 %28, 1
store i32 %29, i32* %12
br label %18
30: ; preds = %18
%31 = load i32, i32* %10
%32 = sitofp i32 %31 to float
%33 = load float, float* %7
%34 = load float, float* %11
%35 = fneg float %34
%36 = call float @llvm.fmuladd.f32(float %32, float %33, float %35)
store float %36, float* %6
%37 = load float, float* %6
store float %37, float* %5
br label %38
38: ; preds = %30, %72
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
%41 = load float, float* %6
%42 = load float, float* %7
%43 = fadd float %41, %42
%44 = load i32, i32* %10
%45 = call float @log(i32 %44)
%46 = fsub float %43, %45
store float %46, float* %8
%47 = load float, float* %5
store float %47, float* %9
%48 = load float, float* %9
%49 = load float, float* %8
%50 = fcmp ogt float %48, %49
br i1 %50, label %51, label %53
51: ; preds = %38
%52 = load float, float* %9
br label %55
53: ; preds = %38
%54 = load float, float* %8
br label %55
55: ; preds = %53, %51
%56 = phi float [ %52, %51 ], [ %54, %53 ]
%57 = load float, float* %9
%58 = load float, float* %8
%59 = fsub float %57, %58
%60 = call i32 @fabs(float %59)
%61 = sub nsw i32 0, %60
%62 = call i32 @exp(i32 %61)
%63 = call float @log1p(i32 %62)
%64 = fadd float %56, %63
store float %64, float* %5
%65 = load float, float* %9
%66 = load float, float* %5
%67 = fsub float %65, %66
%68 = call i32 @fabs(float %67)
%69 = sitofp i32 %68 to double
%70 = fcmp olt double %69, 1.000000e-05
br i1 %70, label %71, label %72
71: ; preds = %55
br label %74
72: ; preds = %55
%73 = load float, float* %8
store float %73, float* %6
br label %38
74: ; preds = %71
%75 = load float, float* %5
%76 = load float, float* %4
%77 = fsub float %75, %76
%78 = load float, float* @M_LN10
%79 = fdiv float %77, %78
ret float %79
}

LLVM IR (-O2):
@M_LN10 = global float 0.000000e+00
define float @log10_poisson_cdf_Q_large_lambda(i32 %0, float %1) {
%3 = fptosi float %1 to i32
%4 = tail call float @log(i32 %3)
%5 = add i32 %0, 1
%6 = icmp slt i32 %5, 2
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = add i32 %0, 1
br label %9
9: ; preds = %7, %9
%10 = phi i32 [ %14, %9 ], [ 2, %7 ]
%11 = phi float [ %13, %9 ], [ 0.000000e+00, %7 ]
%12 = tail call float @log(i32 %10)
%13 = fadd float %11, %12
%14 = add nuw i32 %10, 1
%15 = icmp eq i32 %10, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %2
%17 = phi float [ 0.000000e+00, %2 ], [ %13, %9 ]
%18 = sitofp i32 %5 to float
%19 = fneg float %17
%20 = tail call float @llvm.fmuladd.f32(float %18, float %4, float %19)
br label %21
21: ; preds = %21, %16
%22 = phi float [ %20, %16 ], [ %28, %21 ]
%23 = phi float [ %20, %16 ], [ %36, %21 ]
%24 = phi i32 [ %5, %16 ], [ %25, %21 ]
%25 = add nsw i32 %24, 1
%26 = fadd float %4, %22
%27 = tail call float @log(i32 %25)
%28 = fsub float %26, %27
%29 = fcmp ogt float %23, %28
%30 = select i1 %29, float %23, float %28
%31 = fsub float %23, %28
%32 = tail call i32 @fabs(float %31)
%33 = sub nsw i32 0, %32
%34 = tail call i32 @exp(i32 %33)
%35 = tail call float @log1p(i32 %34)
%36 = fadd float %30, %35
%37 = fsub float %23, %36
%38 = tail call i32 @fabs(float %37)
%39 = icmp slt i32 %38, 1
br i1 %39, label %40, label %21
40: ; preds = %21
%41 = fsub float %36, %1
%42 = load float, float* @M_LN10
%43 = fdiv float %41, %42
ret float %43
}