#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 */
int /*<<< orphan*/ exit(int);
double exp(scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ lgamma(double);
double log(double);
int /*<<< orphan*/ stderr;
double betai(double a, double b, double x) {
  double betacf(double a, double b, double x);
  double bt;
  if (x < 0.0 || x > 1.0) {
    fprintf(stderr, "betai argument out of range\n");
    exit(-1);
  }
  if (x == 0.0)
    return 0.0;
  if (x == 1.0)
    return 1.0;
  bt = exp(lgamma(a + b) - lgamma(a) - lgamma(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     119c <betai+0x3c>
movsd  -0x20(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11bb <betai+0x5b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11e0 <betai+0x80>
jp     11e0 <betai+0x80>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    137a <betai+0x21a>
movsd  -0x20(%rbp),%xmm0
movsd  0xe13(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    120f <betai+0xaf>
jp     120f <betai+0xaf>
movsd  0xdfb(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    137a <betai+0x21a>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1050 <lgamma@plt>
mov    %rax,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <lgamma@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <lgamma@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   1060 <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  0xd68(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1060 <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  0xd2d(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xd1e(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1335 <betai+0x1d5>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1080 <betacf@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    137a <betai+0x21a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xcaf(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
call   1080 <betacf@plt>
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xc8f(%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    $0x38,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
ja     12e0 <betai+0x180>
ucomisd 0xe7f(%rip),%xmm2
ja     12e0 <betai+0x180>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1197 <betai+0x37>
jnp    12d8 <betai+0x178>
movsd  0xe61(%rip),%xmm0
ucomisd %xmm0,%xmm2
jne    11ab <betai+0x4b>
jnp    12d8 <betai+0x178>
movapd %xmm3,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x20(%rsp)
call   1050 <lgamma@plt>
mov    %rax,%rbx
movsd  0x18(%rsp),%xmm0
call   1050 <lgamma@plt>
mov    %rax,%r14
movsd  0x10(%rsp),%xmm0
call   1050 <lgamma@plt>
add    %r14,%rax
sub    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1060 <log@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xddb(%rip),%xmm0
subsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
call   1060 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <exp@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  %xmm0,0x8(%rsp)
movapd %xmm3,%xmm0
movsd  0x30(%rsp),%xmm1
addsd  0xd98(%rip),%xmm1
addsd  0xd88(%rip),%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jbe    12a7 <betai+0x147>
movapd %xmm3,%xmm0
movsd  0x10(%rsp),%xmm1
call   1080 <betacf@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
divsd  0x18(%rsp),%xmm0
jmp    12d8 <betai+0x178>
movsd  0x10(%rsp),%xmm0
movapd %xmm3,%xmm1
movsd  0x28(%rsp),%xmm2
call   1080 <betacf@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x10(%rsp),%xmm1
movsd  0xd2c(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"betai argument out of range\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 %11
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %3
%12 = fcmp oeq double %2, 0.000000e+00
br i1 %12, label %43, label %13
13: ; preds = %11
%14 = fcmp oeq double %2, 1.000000e+00
br i1 %14, label %43, label %15
15: ; preds = %13
%16 = fadd double %0, %1
%17 = tail call i64 @lgamma(double %16)
%18 = tail call i64 @lgamma(double %0)
%19 = tail call i64 @lgamma(double %1)
%20 = add i64 %18, %19
%21 = sub i64 %17, %20
%22 = sitofp i64 %21 to double
%23 = tail call double @log(double %2)
%24 = tail call double @llvm.fmuladd.f64(double %0, double %23, double %22)
%25 = fsub double 1.000000e+00, %2
%26 = tail call double @log(double %25)
%27 = tail call double @llvm.fmuladd.f64(double %1, double %26, double %24)
%28 = fptosi double %27 to i64
%29 = tail call double @exp(i64 %28)
%30 = fadd double %0, 1.000000e+00
%31 = fadd double %16, 2.000000e+00
%32 = fdiv double %30, %31
%33 = fcmp ogt double %32, %2
br i1 %33, label %34, label %38
34: ; preds = %15
%35 = tail call double @betacf(double %0, double %1, double %2)
%36 = fmul double %29, %35
%37 = fdiv double %36, %0
br label %43
38: ; preds = %15
%39 = tail call double @betacf(double %1, double %0, double %25)
%40 = fmul double %29, %39
%41 = fdiv double %40, %1
%42 = fsub double 1.000000e+00, %41
br label %43
43: ; preds = %13, %11, %38, %34
%44 = phi double [ %37, %34 ], [ %42, %38 ], [ 0.000000e+00, %11 ], [ 1.000000e+00, %13 ]
ret double %44
}