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


x86 assembly (clang, -O0):
<p_kescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116e <p_kescape+0x3e>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1208 <p_kescape+0xd8>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <lchoose@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xe4e(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1050 <log@plt>
mov    -0x20(%rbp),%ecx
mov    %eax,%edx
mov    -0x1c(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_kescape>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
test   %edi,%edi
je     1199 <p_kescape+0x69>
mov    %edi,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
movaps %xmm0,(%rsp)
call   1030 <lchoose@plt>
mov    %eax,%r14d
movapd 0xea8(%rip),%xmm0
xorpd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <exp@plt>
movsd  0xea2(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1050 <log@plt>
imul   %ebp,%eax
add    %r14d,%eax
cvtsi2sd %eax,%xmm2
sub    %ebp,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  (%rsp),%xmm1
subsd  %xmm1,%xmm2
jmp    11a3 <p_kescape+0x73>
neg    %ebx
cvtsi2sd %ebx,%xmm2
mulsd  %xmm0,%xmm2
cvttsd2si %xmm2,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <exp@plt>

LLVM IR (-O0):
define double @p_kescape(i32 %0, i32 %1, double %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = load i32, i32* %6
%12 = sub nsw i32 0, %11
%13 = sitofp i32 %12 to double
%14 = load double, double* %7
%15 = fmul double %13, %14
%16 = fptosi double %15 to i32
%17 = call double @exp(i32 %16)
store double %17, double* %4
br label %41
18: ; preds = %3
%19 = load i32, i32* %6
%20 = load i32, i32* %5
%21 = call i32 @lchoose(i32 %19, i32 %20)
%22 = load i32, i32* %5
%23 = load double, double* %7
%24 = fneg double %23
%25 = fptosi double %24 to i32
%26 = call double @exp(i32 %25)
%27 = fsub double 1.000000e+00, %26
%28 = call i32 @log(double %27)
%29 = mul nsw i32 %22, %28
%30 = add nsw i32 %21, %29
%31 = sitofp i32 %30 to double
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = sub nsw i32 %32, %33
%35 = sitofp i32 %34 to double
%36 = load double, double* %7
%37 = fneg double %35
%38 = call double @llvm.fmuladd.f64(double %37, double %36, double %31)
%39 = fptosi double %38 to i32
%40 = call double @exp(i32 %39)
store double %40, double* %4
br label %41
41: ; preds = %18, %10
%42 = load double, double* %4
ret double %42
}

LLVM IR (-O2):
define double @p_kescape(i32 %0, i32 %1, double %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = sub nsw i32 0, %1
%7 = sitofp i32 %6 to double
%8 = fmul double %7, %2
br label %23
9: ; preds = %3
%10 = tail call i32 @lchoose(i32 %1, i32 %0)
%11 = fneg double %2
%12 = fptosi double %11 to i32
%13 = tail call double @exp(i32 %12)
%14 = fsub double 1.000000e+00, %13
%15 = tail call i32 @log(double %14)
%16 = mul nsw i32 %15, %0
%17 = add nsw i32 %16, %10
%18 = sitofp i32 %17 to double
%19 = sub nsw i32 %1, %0
%20 = sitofp i32 %19 to double
%21 = fneg double %20
%22 = tail call double @llvm.fmuladd.f64(double %21, double %2, double %18)
br label %23
23: ; preds = %9, %5
%24 = phi double [ %22, %9 ], [ %8, %5 ]
%25 = fptosi double %24 to i32
%26 = tail call double @exp(i32 %25)
ret double %26
}