#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 combinations_d(unsigned int, unsigned int);
double pow(int, unsigned int);
double dbinom(unsigned int x, unsigned int n, double p) {
  if ((x == 0) && (p == 0))
    return 1;
  if ((x == n) && (p == 1))
    return 1;
  double c = combinations_d(n, x);
  double p0 = pow(p, x);
  double p1 = pow(1 - p, n - x);
  return c * p0 * p1;
}


x86 assembly (clang, -O0):
<dbinom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1167 <dbinom+0x47>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1167 <dbinom+0x47>
jp     1167 <dbinom+0x47>
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f9 <dbinom+0xd9>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11a2 <dbinom+0x82>
movsd  -0x18(%rbp),%xmm0
movsd  0xe80(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11a2 <dbinom+0x82>
jp     11a2 <dbinom+0x82>
movsd  0xe68(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f9 <dbinom+0xd9>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <combinations_d@plt>
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xe34(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
call   1040 <pow@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbinom>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movsd  0xed0(%rip),%xmm1
test   %edi,%edi
jne    1140 <dbinom+0x20>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    1140 <dbinom+0x20>
jnp    11a0 <dbinom+0x80>
mov    %esi,%ebp
sub    %ebx,%ebp
jne    1152 <dbinom+0x32>
ucomisd 0xeb2(%rip),%xmm0
jne    1152 <dbinom+0x32>
jnp    11a0 <dbinom+0x80>
mov    %esi,%edi
mov    %ebx,%esi
movsd  %xmm0,(%rsp)
call   1030 <combinations_d@plt>
movsd  %xmm0,0x10(%rsp)
cvttsd2si (%rsp),%edi
mov    %ebx,%esi
call   1040 <pow@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe80(%rip),%xmm0
subsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @dbinom(i32 %0, i32 %1, double %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load double, double* %7
%15 = fcmp oeq double %14, 0.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %13
store double 1.000000e+00, double* %4
br label %45
17: ; preds = %13, %3
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load double, double* %7
%23 = fcmp oeq double %22, 1.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %21
store double 1.000000e+00, double* %4
br label %45
25: ; preds = %21, %17
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = call double @combinations_d(i32 %26, i32 %27)
store double %28, double* %8
%29 = load double, double* %7
%30 = fptosi double %29 to i32
%31 = load i32, i32* %5
%32 = call double @pow(i32 %30, i32 %31)
store double %32, double* %9
%33 = load double, double* %7
%34 = fsub double 1.000000e+00, %33
%35 = fptosi double %34 to i32
%36 = load i32, i32* %6
%37 = load i32, i32* %5
%38 = sub i32 %36, %37
%39 = call double @pow(i32 %35, i32 %38)
store double %39, double* %10
%40 = load double, double* %8
%41 = load double, double* %9
%42 = fmul double %40, %41
%43 = load double, double* %10
%44 = fmul double %42, %43
store double %44, double* %4
br label %45
45: ; preds = %25, %24, %16
%46 = load double, double* %4
ret double %46
}

LLVM IR (-O2):
define double @dbinom(i32 %0, i32 %1, double %2) {
%4 = icmp eq i32 %0, 0
%5 = fcmp oeq double %2, 0.000000e+00
%6 = and i1 %4, %5
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = icmp eq i32 %1, %0
%9 = fcmp oeq double %2, 1.000000e+00
%10 = and i1 %8, %9
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = tail call double @combinations_d(i32 %1, i32 %0)
%13 = fptosi double %2 to i32
%14 = tail call double @pow(i32 %13, i32 %0)
%15 = fsub double 1.000000e+00, %2
%16 = fptosi double %15 to i32
%17 = sub i32 %1, %0
%18 = tail call double @pow(i32 %16, i32 %17)
%19 = fmul double %12, %14
%20 = fmul double %19, %18
br label %21
21: ; preds = %7, %3, %11
%22 = phi double [ %20, %11 ], [ 1.000000e+00, %3 ], [ 1.000000e+00, %7 ]
ret double %22
}