#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 betacf(double, double, double);
double exp(scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ gammln(double);
double log(double);
int /*<<< orphan*/ stderr;
double betai(double a, double b, double x) {
  double bt;
  if (x < 0.0 || x > 1.0) {
    fprintf(stderr, "WARNING: bad x in BETAI\n");
  }
  if (x == 0.0 || x == 1.0) {
    bt = 0.0;
  } else {
    bt = exp(gammln(a + b) - gammln(a) - gammln(b) + a * log(x) +
             b * log(1.0 - x));
  }
  if (x < (a + 1.0) / (a + b + 2.0)) {
    return bt * betacf(a, b, x) / a;
  } else {
    return 1.0 - bt * betacf(b, a, 1.0 - x) / b;
  }
}


x86 assembly (clang, -O0):
<betai>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     118c <betai+0x3c>
movsd  -0x20(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a1 <betai+0x51>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11be <betai+0x6e>
jp     11be <betai+0x6e>
jmp    11db <betai+0x8b>
movsd  -0x20(%rbp),%xmm0
movsd  0xe35(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11e8 <betai+0x98>
jp     11e8 <betai+0x98>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    129f <betai+0x14f>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1060 <gammln@plt>
mov    %rax,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <gammln@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <gammln@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
sub    %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd8f(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <exp@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  0xd54(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xd45(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    130e <betai+0x1be>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1070 <betacf@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1353 <betai+0x203>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xcd6(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
call   1070 <betacf@plt>
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xcb6(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<betai>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,(%rsp)
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x18(%rsp)
ja     1184 <betai+0x34>
movapd %xmm2,%xmm3
ucomisd 0xe7e(%rip),%xmm2
jbe    11a5 <betai+0x55>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1030 <fprintf@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm3
movapd %xmm1,%xmm2
addsd  (%rsp),%xmm2
jne    11be <betai+0x6e>
jnp    1267 <betai+0x117>
ucomisd 0xe3a(%rip),%xmm3
jne    11ce <betai+0x7e>
jnp    1267 <betai+0x117>
movapd %xmm2,%xmm0
movsd  %xmm2,0x10(%rsp)
call   1060 <gammln@plt>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
call   1060 <gammln@plt>
mov    %rax,%r14
movsd  (%rsp),%xmm0
call   1060 <gammln@plt>
add    %r14,%rax
sub    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0xdcf(%rip),%xmm0
subsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
mulsd  (%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <exp@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm4
movsd  0xd91(%rip),%xmm0
addsd  0xd91(%rip),%xmm2
addsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
ucomisd %xmm3,%xmm0
movsd  %xmm4,0x10(%rsp)
jbe    12af <betai+0x15f>
movapd %xmm1,%xmm0
movsd  (%rsp),%xmm1
movapd %xmm3,%xmm2
call   1070 <betacf@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
jmp    12e4 <betai+0x194>
movsd  0xd49(%rip),%xmm2
subsd  %xmm3,%xmm2
movsd  (%rsp),%xmm0
call   1070 <betacf@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
movsd  0xd20(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"WARNING: bad x in BETAI\0A\00"
define double @betai(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%9 = load double, double* %7
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load double, double* %7
%13 = fcmp ogt double %12, 1.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %11, %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %11
%18 = load double, double* %7
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load double, double* %7
%22 = fcmp oeq double %21, 1.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %20, %17
store double 0.000000e+00, double* %8
br label %47
24: ; preds = %20
%25 = load double, double* %5
%26 = load double, double* %6
%27 = fadd double %25, %26
%28 = call i64 @gammln(double %27)
%29 = load double, double* %5
%30 = call i64 @gammln(double %29)
%31 = sub nsw i64 %28, %30
%32 = load double, double* %6
%33 = call i64 @gammln(double %32)
%34 = sub nsw i64 %31, %33
%35 = sitofp i64 %34 to double
%36 = load double, double* %5
%37 = load double, double* %7
%38 = call double @log(double %37)
%39 = call double @llvm.fmuladd.f64(double %36, double %38, double %35)
%40 = load double, double* %6
%41 = load double, double* %7
%42 = fsub double 1.000000e+00, %41
%43 = call double @log(double %42)
%44 = call double @llvm.fmuladd.f64(double %40, double %43, double %39)
%45 = fptosi double %44 to i64
%46 = call double @exp(i64 %45)
store double %46, double* %8
br label %47
47: ; preds = %24, %23
%48 = load double, double* %7
%49 = load double, double* %5
%50 = fadd double %49, 1.000000e+00
%51 = load double, double* %5
%52 = load double, double* %6
%53 = fadd double %51, %52
%54 = fadd double %53, 2.000000e+00
%55 = fdiv double %50, %54
%56 = fcmp olt double %48, %55
br i1 %56, label %57, label %66
57: ; preds = %47
%58 = load double, double* %8
%59 = load double, double* %5
%60 = load double, double* %6
%61 = load double, double* %7
%62 = call double @betacf(double %59, double %60, double %61)
%63 = fmul double %58, %62
%64 = load double, double* %5
%65 = fdiv double %63, %64
store double %65, double* %4
br label %77
66: ; preds = %47
%67 = load double, double* %8
%68 = load double, double* %6
%69 = load double, double* %5
%70 = load double, double* %7
%71 = fsub double 1.000000e+00, %70
%72 = call double @betacf(double %68, double %69, double %71)
%73 = fmul double %67, %72
%74 = load double, double* %6
%75 = fdiv double %73, %74
%76 = fsub double 1.000000e+00, %75
store double %76, double* %4
br label %77
77: ; preds = %66, %57
%78 = load double, double* %4
ret double %78
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"WARNING: bad x in BETAI\0A\00"
define double @betai(double %0, double %1, double %2) {
%4 = fcmp olt double %2, 0.000000e+00
%5 = fcmp ogt double %2, 1.000000e+00
%6 = or i1 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %3, %7
%11 = fcmp oeq double %2, 0.000000e+00
%12 = fcmp oeq double %2, 1.000000e+00
%13 = or i1 %11, %12
%14 = fadd double %0, %1
br i1 %13, label %29, label %15
15: ; preds = %10
%16 = tail call i64 @gammln(double %14)
%17 = tail call i64 @gammln(double %0)
%18 = tail call i64 @gammln(double %1)
%19 = add i64 %17, %18
%20 = sub i64 %16, %19
%21 = sitofp i64 %20 to double
%22 = tail call double @log(double %2)
%23 = tail call double @llvm.fmuladd.f64(double %0, double %22, double %21)
%24 = fsub double 1.000000e+00, %2
%25 = tail call double @log(double %24)
%26 = tail call double @llvm.fmuladd.f64(double %1, double %25, double %23)
%27 = fptosi double %26 to i64
%28 = tail call double @exp(i64 %27)
br label %29
29: ; preds = %10, %15
%30 = phi double [ %28, %15 ], [ 0.000000e+00, %10 ]
%31 = fadd double %0, 1.000000e+00
%32 = fadd double %14, 2.000000e+00
%33 = fdiv double %31, %32
%34 = fcmp ogt double %33, %2
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = tail call double @betacf(double %0, double %1, double %2)
%37 = fmul double %30, %36
%38 = fdiv double %37, %0
br label %45
39: ; preds = %29
%40 = fsub double 1.000000e+00, %2
%41 = tail call double @betacf(double %1, double %0, double %40)
%42 = fmul double %30, %41
%43 = fdiv double %42, %1
%44 = fsub double 1.000000e+00, %43
br label %45
45: ; preds = %39, %35
%46 = phi double [ %38, %35 ], [ %44, %39 ]
ret double %46
}