#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 log(double);
double logFactorial(double);
double logPoisson3(double k, double lambda) {
  double offset = 0.0;
  if (lambda > 0) {
    offset = lambda * log(lambda) - lambda - logFactorial(lambda);
  }
  if (k == 0) {
    if (lambda == 0) {
      return 0.0;
    } else {
      return -lambda - offset;
    }
  } else {
    if (lambda == 0) {
      return -logFactorial(k) - offset;
    } else {
      return k * log(lambda) - lambda - logFactorial(k) - offset;
    }
  }
}


x86 assembly (clang, -O0):
<logPoisson3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ac <logPoisson3+0x8c>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <logFactorial@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1214 <logPoisson3+0xf4>
jp     1214 <logPoisson3+0xf4>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11e9 <logPoisson3+0xc9>
jp     11e9 <logPoisson3+0xc9>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <logPoisson3+0x1a1>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <logPoisson3+0x1a1>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    125c <logPoisson3+0x13c>
jp     125c <logPoisson3+0x13c>
movsd  -0x10(%rbp),%xmm0
call   1030 <logFactorial@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c1 <logPoisson3+0x1a1>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <logFactorial@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logPoisson3>:
sub    $0x28,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
xorpd  %xmm0,%xmm0
jbe    1186 <logPoisson3+0x66>
movapd %xmm1,%xmm0
movapd %xmm1,0x10(%rsp)
movsd  %xmm2,0x20(%rsp)
call   1040 <log@plt>
mulsd  0x10(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
call   1030 <logFactorial@plt>
xorpd  %xmm3,%xmm3
movsd  0x20(%rsp),%xmm2
movapd 0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm4
subsd  %xmm0,%xmm4
movapd %xmm4,%xmm0
ucomisd %xmm3,%xmm2
jne    11ac <logPoisson3+0x8c>
jp     11ac <logPoisson3+0x8c>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    119a <logPoisson3+0x7a>
jnp    1219 <logPoisson3+0xf9>
xorpd  0xe5e(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
jmp    1219 <logPoisson3+0xf9>
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    11d5 <logPoisson3+0xb5>
jp     11d5 <logPoisson3+0xb5>
movapd %xmm2,%xmm0
call   1030 <logFactorial@plt>
movapd %xmm0,%xmm2
xorpd  0xe2d(%rip),%xmm2
jmp    1213 <logPoisson3+0xf3>
movapd %xmm1,%xmm0
movapd %xmm1,0x10(%rsp)
movsd  %xmm2,0x20(%rsp)
call   1040 <log@plt>
movapd %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
mulsd  %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
movapd %xmm1,0x10(%rsp)
call   1030 <logFactorial@plt>
movapd 0x10(%rsp),%xmm2
subsd  %xmm0,%xmm2
subsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @logPoisson3(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
store double 0.000000e+00, double* %6
%7 = load double, double* %5
%8 = fcmp ogt double %7, 0.000000e+00
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load double, double* %5
%11 = load double, double* %5
%12 = call double @log(double %11)
%13 = load double, double* %5
%14 = fneg double %13
%15 = call double @llvm.fmuladd.f64(double %10, double %12, double %14)
%16 = load double, double* %5
%17 = call double @logFactorial(double %16)
%18 = fsub double %15, %17
store double %18, double* %6
br label %19
19: ; preds = %9, %2
%20 = load double, double* %4
%21 = fcmp oeq double %20, 0.000000e+00
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load double, double* %5
%24 = fcmp oeq double %23, 0.000000e+00
br i1 %24, label %25, label %26
25: ; preds = %22
store double 0.000000e+00, double* %3
br label %52
26: ; preds = %22
%27 = load double, double* %5
%28 = fneg double %27
%29 = load double, double* %6
%30 = fsub double %28, %29
store double %30, double* %3
br label %52
31: ; preds = %19
%32 = load double, double* %5
%33 = fcmp oeq double %32, 0.000000e+00
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load double, double* %4
%36 = call double @logFactorial(double %35)
%37 = fneg double %36
%38 = load double, double* %6
%39 = fsub double %37, %38
store double %39, double* %3
br label %52
40: ; preds = %31
%41 = load double, double* %4
%42 = load double, double* %5
%43 = call double @log(double %42)
%44 = load double, double* %5
%45 = fneg double %44
%46 = call double @llvm.fmuladd.f64(double %41, double %43, double %45)
%47 = load double, double* %4
%48 = call double @logFactorial(double %47)
%49 = fsub double %46, %48
%50 = load double, double* %6
%51 = fsub double %49, %50
store double %51, double* %3
br label %52
52: ; preds = %40, %34, %26, %25
%53 = load double, double* %3
ret double %53
}

LLVM IR (-O2):
define double @logPoisson3(double %0, double %1) {
%3 = fcmp ogt double %1, 0.000000e+00
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = tail call double @log(double %1)
%6 = fneg double %1
%7 = tail call double @llvm.fmuladd.f64(double %1, double %5, double %6)
%8 = tail call double @logFactorial(double %1)
%9 = fsub double %7, %8
br label %10
10: ; preds = %4, %2
%11 = phi double [ %9, %4 ], [ 0.000000e+00, %2 ]
%12 = fcmp oeq double %0, 0.000000e+00
%13 = fcmp oeq double %1, 0.000000e+00
br i1 %12, label %14, label %18
14: ; preds = %10
br i1 %13, label %30, label %15
15: ; preds = %14
%16 = fneg double %1
%17 = fsub double %16, %11
br label %30
18: ; preds = %10
br i1 %13, label %19, label %23
19: ; preds = %18
%20 = tail call double @logFactorial(double %0)
%21 = fneg double %20
%22 = fsub double %21, %11
br label %30
23: ; preds = %18
%24 = tail call double @log(double %1)
%25 = fneg double %1
%26 = tail call double @llvm.fmuladd.f64(double %0, double %24, double %25)
%27 = tail call double @logFactorial(double %0)
%28 = fsub double %26, %27
%29 = fsub double %28, %11
br label %30
30: ; preds = %14, %23, %19, %15
%31 = phi double [ %17, %15 ], [ %22, %19 ], [ %29, %23 ], [ 0.000000e+00, %14 ]
ret double %31
}