#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(int);
int gammln(int);
int log(double);
double binomial_distribution(double p, int n, int k) {
  double fac = gammln((double)n + 1.0);
  if (k < 0) {
  }
  if (k > n) {
    return 0;
  }
  return exp(k * log(p) + (n - k) * log(1.0 - p) + fac - gammln(k + 1.0) -
             gammln(n - k + 1.0));
}


x86 assembly (clang, -O0):
<binomial_distribution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xeb0(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <gammln@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1175 <binomial_distribution+0x45>
jmp    1175 <binomial_distribution+0x45>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    118e <binomial_distribution+0x5e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1245 <binomial_distribution+0x115>
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
movsd  0xe46(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
mov    -0x38(%rbp),%ecx
mov    %eax,%edx
mov    -0x34(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xe14(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <gammln@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xde3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <gammln@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binomial_distribution>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebx
movsd  %xmm0,(%rsp)
lea    0x1(%rbx),%edi
call   1050 <gammln@plt>
sub    %r15d,%ebx
jge    115c <binomial_distribution+0x2c>
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r14d
movsd  (%rsp),%xmm0
call   1040 <log@plt>
mov    %eax,%ebp
imul   %r15d,%ebp
movsd  0xe89(%rip),%xmm0
subsd  (%rsp),%xmm0
call   1040 <log@plt>
imul   %ebx,%eax
add    %eax,%ebp
add    %ebp,%r14d
add    $0x1,%r15d
mov    %r15d,%edi
call   1050 <gammln@plt>
mov    %eax,%ebp
add    $0x1,%ebx
mov    %ebx,%edi
call   1050 <gammln@plt>
add    %ebp,%eax
sub    %eax,%r14d
mov    %r14d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <exp@plt>

LLVM IR (-O0):
define double @binomial_distribution(double %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store double %0, double* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = sitofp i32 %9 to double
%11 = fadd double %10, 1.000000e+00
%12 = fptosi double %11 to i32
%13 = call i32 @gammln(i32 %12)
%14 = sitofp i32 %13 to double
store double %14, double* %8
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %3
br label %18
18: ; preds = %17, %3
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp sgt i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
store double 0.000000e+00, double* %4
br label %57
23: ; preds = %18
%24 = load i32, i32* %7
%25 = load double, double* %5
%26 = call i32 @log(double %25)
%27 = mul nsw i32 %24, %26
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = sub nsw i32 %28, %29
%31 = load double, double* %5
%32 = fsub double 1.000000e+00, %31
%33 = call i32 @log(double %32)
%34 = mul nsw i32 %30, %33
%35 = add nsw i32 %27, %34
%36 = sitofp i32 %35 to double
%37 = load double, double* %8
%38 = fadd double %36, %37
%39 = load i32, i32* %7
%40 = sitofp i32 %39 to double
%41 = fadd double %40, 1.000000e+00
%42 = fptosi double %41 to i32
%43 = call i32 @gammln(i32 %42)
%44 = sitofp i32 %43 to double
%45 = fsub double %38, %44
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = sub nsw i32 %46, %47
%49 = sitofp i32 %48 to double
%50 = fadd double %49, 1.000000e+00
%51 = fptosi double %50 to i32
%52 = call i32 @gammln(i32 %51)
%53 = sitofp i32 %52 to double
%54 = fsub double %45, %53
%55 = fptosi double %54 to i32
%56 = call double @exp(i32 %55)
store double %56, double* %4
br label %57
57: ; preds = %23, %22
%58 = load double, double* %4
ret double %58
}

LLVM IR (-O2):
define double @binomial_distribution(double %0, i32 %1, i32 %2) {
%4 = add i32 %1, 1
%5 = tail call i32 @gammln(i32 %4)
%6 = icmp slt i32 %1, %2
br i1 %6, label %23, label %7
7: ; preds = %3
%8 = tail call i32 @log(double %0)
%9 = mul nsw i32 %8, %2
%10 = sub nsw i32 %1, %2
%11 = fsub double 1.000000e+00, %0
%12 = tail call i32 @log(double %11)
%13 = mul nsw i32 %12, %10
%14 = add nsw i32 %13, %9
%15 = add i32 %5, %14
%16 = add i32 %2, 1
%17 = tail call i32 @gammln(i32 %16)
%18 = add i32 %10, 1
%19 = tail call i32 @gammln(i32 %18)
%20 = add i32 %17, %19
%21 = sub i32 %15, %20
%22 = tail call double @exp(i32 %21)
br label %23
23: ; preds = %3, %7
%24 = phi double [ %22, %7 ], [ 0.000000e+00, %3 ]
ret double %24
}