#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_P_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;
  float sum_ln_m = 0;
  int i = 0;
  for (i = 1; i <= m; i++)
    sum_ln_m += log(i);
  logx = m * ln_lbd - sum_ln_m;
  residue = logx;
  for (; m > 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_P_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
mov    %eax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     11b7 <log10_poisson_cdf_P_large_lambda+0x77>
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    118b <log10_poisson_cdf_P_large_lambda+0x4b>
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)
cmpl   $0x1,-0x20(%rbp)
jle    12ca <log10_poisson_cdf_P_large_lambda+0x18a>
movss  -0x10(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <log@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1244 <log10_poisson_cdf_P_large_lambda+0x104>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
jmp    124e <log10_poisson_cdf_P_large_lambda+0x10e>
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  0xd5d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12b2 <log10_poisson_cdf_P_large_lambda+0x172>
jmp    12ca <log10_poisson_cdf_P_large_lambda+0x18a>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11ea <log10_poisson_cdf_P_large_lambda+0xaa>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
mov    0x2d05(%rip),%rax
divss  (%rax),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log10_poisson_cdf_P_large_lambda>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
movss  %xmm0,0x18(%rsp)
cvttss2si %xmm0,%edi
call   1050 <log@plt>
test   %r14d,%r14d
jle    126d <log10_poisson_cdf_P_large_lambda+0x12d>
movss  %xmm0,0x14(%rsp)
mov    %r14d,%r15d
neg    %r15d
xorps  %xmm1,%xmm1
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movss  %xmm1,0x10(%rsp)
mov    %ebx,%edi
call   1050 <log@plt>
movss  0x10(%rsp),%xmm1
addss  %xmm0,%xmm1
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1180 <log10_poisson_cdf_P_large_lambda+0x40>
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
movss  0x14(%rsp),%xmm2
mulss  %xmm2,%xmm0
subss  %xmm1,%xmm0
cmp    $0x2,%r14d
jl     127e <log10_poisson_cdf_P_large_lambda+0x13e>
movaps %xmm0,%xmm1
nopl   (%rax)
movss  %xmm0,0x10(%rsp)
subss  %xmm2,%xmm1
movss  %xmm1,0xc(%rsp)
mov    %r14d,%edi
call   1050 <log@plt>
movaps %xmm0,%xmm1
addss  0xc(%rsp),%xmm1
movss  0x10(%rsp),%xmm2
movaps %xmm2,%xmm0
maxss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
movaps %xmm2,%xmm0
movss  %xmm1,0x1c(%rsp)
subss  %xmm1,%xmm0
call   1030 <fabs@plt>
neg    %eax
mov    %eax,%edi
call   1040 <exp@plt>
mov    %eax,%edi
call   1060 <log1p@plt>
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm1
subss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    1278 <log10_poisson_cdf_P_large_lambda+0x138>
lea    -0x1(%r14),%eax
cmp    $0x2,%r14d
mov    %eax,%r14d
movss  0x14(%rsp),%xmm2
movss  0x1c(%rsp),%xmm1
movss  0xc(%rsp),%xmm0
jg     11d0 <log10_poisson_cdf_P_large_lambda+0x90>
jmp    127e <log10_poisson_cdf_P_large_lambda+0x13e>
cvtsi2ss %r14d,%xmm1
mulss  %xmm1,%xmm0
jmp    127e <log10_poisson_cdf_P_large_lambda+0x13e>
movss  0xc(%rsp),%xmm0
subss  0x18(%rsp),%xmm0
mov    0x2d55(%rip),%rax
divss  (%rax),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_LN10 = global float 0.000000e+00
define float @log10_poisson_cdf_P_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
store i32 %16, i32* %10
store float 0.000000e+00, float* %11
store i32 0, i32* %12
store i32 1, i32* %12
br label %17
17: ; preds = %26, %2
%18 = load i32, i32* %12
%19 = load i32, i32* %10
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* %12
%23 = call float @log(i32 %22)
%24 = load float, float* %11
%25 = fadd float %24, %23
store float %25, float* %11
br label %26
26: ; preds = %21
%27 = load i32, i32* %12
%28 = add nsw i32 %27, 1
store i32 %28, i32* %12
br label %17
29: ; preds = %17
%30 = load i32, i32* %10
%31 = sitofp i32 %30 to float
%32 = load float, float* %7
%33 = load float, float* %11
%34 = fneg float %33
%35 = call float @llvm.fmuladd.f32(float %31, float %32, float %34)
store float %35, float* %6
%36 = load float, float* %6
store float %36, float* %5
br label %37
37: ; preds = %74, %29
%38 = load i32, i32* %10
%39 = icmp sgt i32 %38, 1
br i1 %39, label %40, label %77
40: ; preds = %37
%41 = load float, float* %6
%42 = load float, float* %7
%43 = fsub float %41, %42
%44 = load i32, i32* %10
%45 = call float @log(i32 %44)
%46 = fadd 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 = %40
%52 = load float, float* %9
br label %55
53: ; preds = %40
%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 %77
72: ; preds = %55
%73 = load float, float* %8
store float %73, float* %6
br label %74
74: ; preds = %72
%75 = load i32, i32* %10
%76 = add nsw i32 %75, -1
store i32 %76, i32* %10
br label %37
77: ; preds = %71, %37
%78 = load float, float* %5
%79 = load float, float* %4
%80 = fsub float %78, %79
%81 = load float, float* @M_LN10
%82 = fdiv float %80, %81
ret float %82
}

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