#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__);
scalar_t__ gammln(double);
double log(double);
double betai(double a, double b, double x) {
  double bt;
  if (x < 0.0 || x > 1.0)
    return 0.;
  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     117c <betai+0x3c>
movsd  -0x20(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1189 <betai+0x49>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133b <betai+0x1fb>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a6 <betai+0x66>
jp     11a6 <betai+0x66>
jmp    11c3 <betai+0x83>
movsd  -0x20(%rbp),%xmm0
movsd  0xe4d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11d0 <betai+0x90>
jp     11d0 <betai+0x90>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1287 <betai+0x147>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1050 <gammln@plt>
mov    %rax,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <gammln@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <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   1040 <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  0xda7(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <exp@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  0xd6c(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xd5d(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    12f6 <betai+0x1b6>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1060 <betacf@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133b <betai+0x1fb>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xcee(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
call   1060 <betacf@plt>
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xcce(%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
movapd %xmm2,%xmm4
xorpd  %xmm2,%xmm2
ucomisd %xmm4,%xmm2
ja     12b9 <betai+0x179>
ucomisd 0xe9f(%rip),%xmm4
ja     12b9 <betai+0x179>
movapd %xmm0,%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm4
movapd %xmm0,%xmm5
addsd  %xmm1,%xmm5
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
jne    118f <betai+0x4f>
jnp    123c <betai+0xfc>
ucomisd 0xe69(%rip),%xmm4
jne    119f <betai+0x5f>
jnp    123c <betai+0xfc>
movapd %xmm5,%xmm0
movsd  %xmm4,(%rsp)
movsd  %xmm5,0x20(%rsp)
call   1050 <gammln@plt>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
call   1050 <gammln@plt>
mov    %rax,%r14
movsd  0x8(%rsp),%xmm0
call   1050 <gammln@plt>
add    %r14,%rax
sub    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
call   1040 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xdf9(%rip),%xmm0
subsd  (%rsp),%xmm0
call   1040 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <exp@plt>
movsd  0x20(%rsp),%xmm5
movsd  (%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movapd %xmm0,%xmm2
movsd  0xdbc(%rip),%xmm0
addsd  0xdbc(%rip),%xmm5
addsd  %xmm3,%xmm0
divsd  %xmm5,%xmm0
ucomisd %xmm4,%xmm0
movsd  %xmm2,(%rsp)
jbe    1283 <betai+0x143>
movapd %xmm3,%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm4,%xmm2
call   1060 <betacf@plt>
movsd  (%rsp),%xmm2
mulsd  %xmm0,%xmm2
divsd  0x10(%rsp),%xmm2
jmp    12b9 <betai+0x179>
movsd  0xd75(%rip),%xmm2
subsd  %xmm4,%xmm2
movsd  0x8(%rsp),%xmm0
movapd %xmm3,%xmm1
call   1060 <betacf@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
movsd  0xd4b(%rip),%xmm2
subsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
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 %42, label %7
7: ; preds = %3
%8 = fcmp oeq double %2, 0.000000e+00
%9 = fcmp oeq double %2, 1.000000e+00
%10 = or i1 %8, %9
%11 = fadd double %0, %1
br i1 %10, label %26, label %12
12: ; preds = %7
%13 = tail call i64 @gammln(double %11)
%14 = tail call i64 @gammln(double %0)
%15 = tail call i64 @gammln(double %1)
%16 = add i64 %14, %15
%17 = sub i64 %13, %16
%18 = sitofp i64 %17 to double
%19 = tail call double @log(double %2)
%20 = tail call double @llvm.fmuladd.f64(double %0, double %19, double %18)
%21 = fsub double 1.000000e+00, %2
%22 = tail call double @log(double %21)
%23 = tail call double @llvm.fmuladd.f64(double %1, double %22, double %20)
%24 = fptosi double %23 to i64
%25 = tail call double @exp(i64 %24)
br label %26
26: ; preds = %7, %12
%27 = phi double [ %25, %12 ], [ 0.000000e+00, %7 ]
%28 = fadd double %0, 1.000000e+00
%29 = fadd double %11, 2.000000e+00
%30 = fdiv double %28, %29
%31 = fcmp ogt double %30, %2
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = tail call double @betacf(double %0, double %1, double %2)
%34 = fmul double %27, %33
%35 = fdiv double %34, %0
br label %42
36: ; preds = %26
%37 = fsub double 1.000000e+00, %2
%38 = tail call double @betacf(double %1, double %0, double %37)
%39 = fmul double %27, %38
%40 = fdiv double %39, %1
%41 = fsub double 1.000000e+00, %40
br label %42
42: ; preds = %3, %36, %32
%43 = phi double [ %35, %32 ], [ %41, %36 ], [ 0.000000e+00, %3 ]
ret double %43
}