#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);
double gammaln_mat(double);
double log(double);
double binopdf_mat(int n, int k, double p) {
  double res;
  double nk;
  double dn;
  double dk;
  double dnk;
  double lny;
  double cp;
  double nk1, nk2, nk3;
  if (k > n) {
    k = n;
  }
  if (p == 1.0) {
    res = 0.0;
  } else {
    if (p == 0.0) {
      res = 0.0;
    } else {
      dn = (double)n + 1.0;
      dk = (double)k + 1.0;
      dnk = dn - dk + 1.0;
      nk = gammaln_mat(dn) - gammaln_mat(dk) - gammaln_mat(dnk);
      lny = nk + (double)k * log(p) + ((double)n - (double)k) * log(1.0 - p);
      res = exp(lny);
    }
  }
  return res;
}


x86 assembly (clang, -O0):
<binopdf_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    1158 <binopdf_mat+0x28>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1182 <binopdf_mat+0x52>
jp     1182 <binopdf_mat+0x52>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12ca <binopdf_mat+0x19a>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a7 <binopdf_mat+0x77>
jp     11a7 <binopdf_mat+0x77>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12c5 <binopdf_mat+0x195>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe36(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <gammaln_mat@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1030 <gammaln_mat@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   1030 <gammaln_mat@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x80(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xd6e(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    12ca <binopdf_mat+0x19a>
movsd  -0x18(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binopdf_mat>:
sub    $0x38,%rsp
ucomisd 0xec4(%rip),%xmm0
jne    1144 <binopdf_mat+0x14>
jnp    1240 <binopdf_mat+0x110>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1158 <binopdf_mat+0x28>
jnp    1240 <binopdf_mat+0x110>
cmp    %edi,%esi
cmovg  %edi,%esi
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xe8e(%rip),%xmm2
cvtsi2sd %esi,%xmm3
movsd  %xmm3,0x30(%rsp)
addsd  %xmm2,%xmm0
movapd %xmm3,%xmm4
addsd  %xmm2,%xmm4
movsd  %xmm4,0x20(%rsp)
movapd %xmm0,%xmm3
subsd  %xmm4,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x28(%rsp)
movsd  %xmm1,0x18(%rsp)
call   1030 <gammaln_mat@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1030 <gammaln_mat@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x28(%rsp),%xmm0
call   1030 <gammaln_mat@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
movsd  0x30(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xde0(%rip),%xmm0
subsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
jmp    1040 <exp@plt>
xorpd  %xmm0,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @binopdf_mat(i32 %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
store double %2, double* %6
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = load i32, i32* %4
store i32 %21, i32* %5
br label %22
22: ; preds = %20, %3
%23 = load double, double* %6
%24 = fcmp oeq double %23, 1.000000e+00
br i1 %24, label %25, label %26
25: ; preds = %22
store double 0.000000e+00, double* %7
br label %67
26: ; preds = %22
%27 = load double, double* %6
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %26
store double 0.000000e+00, double* %7
br label %66
30: ; preds = %26
%31 = load i32, i32* %4
%32 = sitofp i32 %31 to double
%33 = fadd double %32, 1.000000e+00
store double %33, double* %9
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
%36 = fadd double %35, 1.000000e+00
store double %36, double* %10
%37 = load double, double* %9
%38 = load double, double* %10
%39 = fsub double %37, %38
%40 = fadd double %39, 1.000000e+00
store double %40, double* %11
%41 = load double, double* %9
%42 = call double @gammaln_mat(double %41)
%43 = load double, double* %10
%44 = call double @gammaln_mat(double %43)
%45 = fsub double %42, %44
%46 = load double, double* %11
%47 = call double @gammaln_mat(double %46)
%48 = fsub double %45, %47
store double %48, double* %8
%49 = load double, double* %8
%50 = load i32, i32* %5
%51 = sitofp i32 %50 to double
%52 = load double, double* %6
%53 = call double @log(double %52)
%54 = call double @llvm.fmuladd.f64(double %51, double %53, double %49)
%55 = load i32, i32* %4
%56 = sitofp i32 %55 to double
%57 = load i32, i32* %5
%58 = sitofp i32 %57 to double
%59 = fsub double %56, %58
%60 = load double, double* %6
%61 = fsub double 1.000000e+00, %60
%62 = call double @log(double %61)
%63 = call double @llvm.fmuladd.f64(double %59, double %62, double %54)
store double %63, double* %12
%64 = load double, double* %12
%65 = call double @exp(double %64)
store double %65, double* %7
br label %66
66: ; preds = %30, %29
br label %67
67: ; preds = %66, %25
%68 = load double, double* %7
ret double %68
}

LLVM IR (-O2):
define double @binopdf_mat(i32 %0, i32 %1, double %2) {
%4 = fcmp oeq double %2, 1.000000e+00
%5 = fcmp oeq double %2, 0.000000e+00
%6 = or i1 %4, %5
br i1 %6, label %28, label %7
7: ; preds = %3
%8 = icmp sgt i32 %1, %0
%9 = select i1 %8, i32 %0, i32 %1
%10 = sitofp i32 %0 to double
%11 = fadd double %10, 1.000000e+00
%12 = sitofp i32 %9 to double
%13 = fadd double %12, 1.000000e+00
%14 = fsub double %11, %13
%15 = fadd double %14, 1.000000e+00
%16 = tail call double @gammaln_mat(double %11)
%17 = tail call double @gammaln_mat(double %13)
%18 = fsub double %16, %17
%19 = tail call double @gammaln_mat(double %15)
%20 = fsub double %18, %19
%21 = tail call double @log(double %2)
%22 = tail call double @llvm.fmuladd.f64(double %12, double %21, double %20)
%23 = fsub double %10, %12
%24 = fsub double 1.000000e+00, %2
%25 = tail call double @log(double %24)
%26 = tail call double @llvm.fmuladd.f64(double %23, double %25, double %22)
%27 = tail call double @exp(double %26)
br label %28
28: ; preds = %3, %7
%29 = phi double [ %27, %7 ], [ 0.000000e+00, %3 ]
ret double %29
}