#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 Binomial(double, int, double *);
int /*<<< orphan*/ error2(char *);
double exp(double);
double probBetaBinomial(int n, int k, double p, double q) {
  double a = p, b = q, C1, C2, C3, scale1, scale2, scale3;
  if (a <= 0 || b <= 0)
    return (0);
  C1 = Binomial(-a, k, &scale1);
  C2 = Binomial(-b, n - k, &scale2);
  C3 = Binomial(-a - b, n, &scale3);
  C1 *= C2 / C3;
  if (C1 < 0)
    error2("error in probBetaBinomial");
  return C1 * exp(scale1 + scale2 - scale3);
}


x86 assembly (clang, -O0):
<probBetaBinomial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jae    1178 <probBetaBinomial+0x48>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     1185 <probBetaBinomial+0x55>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1271 <probBetaBinomial+0x141>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <Binomial@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0xc(%rbp),%edi
sub    -0x10(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   1040 <Binomial@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1040 <Binomial@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1242 <probBetaBinomial+0x112>
lea    0xdc3(%rip),%rdi
call   1030 <error2@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<probBetaBinomial>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jae    1213 <probBetaBinomial+0xe3>
xorpd  %xmm3,%xmm3
ucomisd %xmm1,%xmm3
jae    1213 <probBetaBinomial+0xe3>
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
xorpd  0xe9e(%rip),%xmm2
movapd %xmm2,0x40(%rsp)
lea    0x28(%rsp),%rsi
movapd %xmm2,%xmm0
mov    %ebp,%edi
movapd %xmm1,0x30(%rsp)
call   1040 <Binomial@plt>
movsd  %xmm0,0x10(%rsp)
movaps 0xe75(%rip),%xmm0
xorps  0x30(%rsp),%xmm0
mov    %ebx,%edi
sub    %ebp,%edi
lea    0x20(%rsp),%rsi
call   1040 <Binomial@plt>
movsd  %xmm0,0x8(%rsp)
movapd 0x40(%rsp),%xmm0
subsd  0x30(%rsp),%xmm0
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
call   1040 <Binomial@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11e8 <probBetaBinomial+0xb8>
lea    0xe35(%rip),%rdi
call   1030 <error2@plt>
movsd  0x28(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
call   1050 <exp@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"error in probBetaBinomial\00"
define double @probBetaBinomial(i32 %0, i32 %1, double %2, double %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%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
%17 = alloca double
store i32 %0, i32* %6
store i32 %1, i32* %7
store double %2, double* %8
store double %3, double* %9
%18 = load double, double* %8
store double %18, double* %10
%19 = load double, double* %9
store double %19, double* %11
%20 = load double, double* %10
%21 = fcmp ole double %20, 0.000000e+00
br i1 %21, label %25, label %22
22: ; preds = %4
%23 = load double, double* %11
%24 = fcmp ole double %23, 0.000000e+00
br i1 %24, label %25, label %26
25: ; preds = %22, %4
store double 0.000000e+00, double* %5
br label %61
26: ; preds = %22
%27 = load double, double* %10
%28 = fneg double %27
%29 = load i32, i32* %7
%30 = call double @Binomial(double %28, i32 %29, double* %15)
store double %30, double* %12
%31 = load double, double* %11
%32 = fneg double %31
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = sub nsw i32 %33, %34
%36 = call double @Binomial(double %32, i32 %35, double* %16)
store double %36, double* %13
%37 = load double, double* %10
%38 = fneg double %37
%39 = load double, double* %11
%40 = fsub double %38, %39
%41 = load i32, i32* %6
%42 = call double @Binomial(double %40, i32 %41, double* %17)
store double %42, double* %14
%43 = load double, double* %13
%44 = load double, double* %14
%45 = fdiv double %43, %44
%46 = load double, double* %12
%47 = fmul double %46, %45
store double %47, double* %12
%48 = load double, double* %12
%49 = fcmp olt double %48, 0.000000e+00
br i1 %49, label %50, label %52
50: ; preds = %26
%51 = call i32 @error2(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %52
52: ; preds = %50, %26
%53 = load double, double* %12
%54 = load double, double* %15
%55 = load double, double* %16
%56 = fadd double %54, %55
%57 = load double, double* %17
%58 = fsub double %56, %57
%59 = call double @exp(double %58)
%60 = fmul double %53, %59
store double %60, double* %5
br label %61
61: ; preds = %52, %25
%62 = load double, double* %5
ret double %62
}

LLVM IR (-O2):
@.str = [26 x i8] c"error in probBetaBinomial\00"
define double @probBetaBinomial(i32 %0, i32 %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = bitcast double* %5 to i8*
%9 = bitcast double* %6 to i8*
%10 = bitcast double* %7 to i8*
%11 = fcmp ole double %2, 0.000000e+00
%12 = fcmp ole double %3, 0.000000e+00
%13 = or i1 %11, %12
br i1 %13, label %35, label %14
14: ; preds = %4
%15 = fneg double %2
%16 = call double @Binomial(double %15, i32 %1, double* %5)
%17 = fneg double %3
%18 = sub nsw i32 %0, %1
%19 = call double @Binomial(double %17, i32 %18, double* %6)
%20 = fsub double %15, %3
%21 = call double @Binomial(double %20, i32 %0, double* %7)
%22 = fdiv double %19, %21
%23 = fmul double %16, %22
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 @error2(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = load double, double* %5
%29 = load double, double* %6
%30 = fadd double %28, %29
%31 = load double, double* %7
%32 = fsub double %30, %31
%33 = call double @exp(double %32)
%34 = fmul double %23, %33
br label %35
35: ; preds = %4, %27
%36 = phi double [ %34, %27 ], [ 0.000000e+00, %4 ]
ret double %36
}