#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 exp(double);
scalar_t__ log(double);
double Poisson(long k, double ny) {
  double value = 1.0;
  long i;
  double logsum = 0.0;
  for (i = 1; i <= k; i++) {
    logsum += log(ny / i);
  }
  value *= exp(-ny + logsum);
  return (value);
}


x86 assembly (clang, -O0):
<Poisson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  0xec7(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jg     1190 <Poisson+0x70>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <log@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114e <Poisson+0x2e>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
call   1030 <exp@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Poisson>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
jle    1199 <Poisson+0x79>
mov    %rdi,%r14
neg    %r14
mov    $0x1,%ebx
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1040 <log@plt>
movsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
jne    1150 <Poisson+0x30>
jmp    119d <Poisson+0x7d>
xorpd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1030 <exp@plt>

LLVM IR (-O0):
define double @Poisson(i64 %0, double %1) {
%3 = alloca i64
%4 = alloca double
%5 = alloca double
%6 = alloca i64
%7 = alloca double
store i64 %0, i64* %3
store double %1, double* %4
store double 1.000000e+00, double* %5
store double 0.000000e+00, double* %7
store i64 1, i64* %6
br label %8
8: ; preds = %21, %2
%9 = load i64, i64* %6
%10 = load i64, i64* %3
%11 = icmp sle i64 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load double, double* %4
%14 = load i64, i64* %6
%15 = sitofp i64 %14 to double
%16 = fdiv double %13, %15
%17 = call i64 @log(double %16)
%18 = sitofp i64 %17 to double
%19 = load double, double* %7
%20 = fadd double %19, %18
store double %20, double* %7
br label %21
21: ; preds = %12
%22 = load i64, i64* %6
%23 = add nsw i64 %22, 1
store i64 %23, i64* %6
br label %8
24: ; preds = %8
%25 = load double, double* %4
%26 = fneg double %25
%27 = load double, double* %7
%28 = fadd double %26, %27
%29 = call double @exp(double %28)
%30 = load double, double* %5
%31 = fmul double %30, %29
store double %31, double* %5
%32 = load double, double* %5
ret double %32
}

LLVM IR (-O2):
define double @Poisson(i64 %0, double %1) {
%3 = icmp slt i64 %0, 1
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = phi double [ %11, %4 ], [ 0.000000e+00, %2 ]
%6 = phi i64 [ %12, %4 ], [ 1, %2 ]
%7 = sitofp i64 %6 to double
%8 = fdiv double %1, %7
%9 = tail call i64 @log(double %8)
%10 = sitofp i64 %9 to double
%11 = fadd double %5, %10
%12 = add nuw i64 %6, 1
%13 = icmp eq i64 %6, %0
br i1 %13, label %14, label %4
14: ; preds = %4, %2
%15 = phi double [ 0.000000e+00, %2 ], [ %11, %4 ]
%16 = fsub double %15, %1
%17 = tail call double @exp(double %16)
ret double %17
}