#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, int);
double exp(scalar_t__);
scalar_t__ lgamma(double);
double log(int);
double betai(double a, double b, double x) {
  double bt, betai;
  if (x == 0 || x == 1)
    bt = 0;
  else
    bt = exp(lgamma(a + b) - lgamma(a) - lgamma(b) + a * log(x) +
             b * log(1 - x));
  if (x < (a + 1) / (a + b + 2))
    betai = bt * betacf(a, b, x) / a;
  else
    betai = 1 - bt * betacf(b, a, 1 - x) / b;
  return betai;
}


x86 assembly (clang, -O0):
<betai>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1174 <betai+0x34>
jp     1174 <betai+0x34>
jmp    1191 <betai+0x51>
movsd  -0x18(%rbp),%xmm0
movsd  0xe7f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    119e <betai+0x5e>
jp     119e <betai+0x5e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1259 <betai+0x119>
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1040 <lgamma@plt>
mov    %rax,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <lgamma@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <lgamma@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
sub    %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
cvttsd2si -0x18(%rbp),%edi
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  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdd9(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
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   1030 <exp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  0xd9a(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
addsd  -0x10(%rbp),%xmm2
movsd  0xd8b(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    12c8 <betai+0x188>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
cvttsd2si -0x18(%rbp),%edi
call   1060 <betacf@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1311 <betai+0x1d1>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xd1c(%rip),%xmm2
subsd  -0x18(%rbp),%xmm2
cvttsd2si %xmm2,%edi
call   1060 <betacf@plt>
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm0,%xmm1
divsd  -0x10(%rbp),%xmm1
movsd  0xcf8(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<betai>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm5,%xmm5
ucomisd %xmm5,%xmm2
movapd %xmm0,%xmm4
movsd  %xmm1,0x8(%rsp)
addsd  %xmm1,%xmm4
movsd  %xmm0,0x10(%rsp)
jne    116f <betai+0x2f>
jnp    1220 <betai+0xe0>
ucomisd 0xe89(%rip),%xmm2
jne    117f <betai+0x3f>
jnp    1220 <betai+0xe0>
movapd %xmm4,%xmm0
movsd  %xmm2,(%rsp)
movsd  %xmm4,0x20(%rsp)
call   1040 <lgamma@plt>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
call   1040 <lgamma@plt>
mov    %rax,%r14
movsd  0x8(%rsp),%xmm0
call   1040 <lgamma@plt>
add    %r14,%rax
sub    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x18(%rsp)
cvttsd2si (%rsp),%edi
call   1050 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xe19(%rip),%xmm0
subsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <exp@plt>
movsd  0x20(%rsp),%xmm4
movsd  (%rsp),%xmm2
movsd  0x10(%rsp),%xmm3
movapd %xmm0,%xmm5
movsd  0xdd8(%rip),%xmm0
addsd  0xdd8(%rip),%xmm4
addsd  %xmm3,%xmm0
divsd  %xmm4,%xmm0
ucomisd %xmm2,%xmm0
movsd  %xmm5,(%rsp)
jbe    1267 <betai+0x127>
cvttsd2si %xmm2,%edi
movapd %xmm3,%xmm0
movsd  0x8(%rsp),%xmm1
call   1060 <betacf@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x10(%rsp),%xmm1
jmp    12a5 <betai+0x165>
movsd  0xd91(%rip),%xmm0
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
movsd  0x8(%rsp),%xmm0
movapd %xmm3,%xmm1
call   1060 <betacf@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
movsd  0xd5f(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%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* %4
store double %1, double* %5
store double %2, double* %6
%9 = load double, double* %6
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load double, double* %6
%13 = fcmp oeq double %12, 1.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %11, %3
store double 0.000000e+00, double* %7
br label %40
15: ; preds = %11
%16 = load double, double* %4
%17 = load double, double* %5
%18 = fadd double %16, %17
%19 = call i64 @lgamma(double %18)
%20 = load double, double* %4
%21 = call i64 @lgamma(double %20)
%22 = sub nsw i64 %19, %21
%23 = load double, double* %5
%24 = call i64 @lgamma(double %23)
%25 = sub nsw i64 %22, %24
%26 = sitofp i64 %25 to double
%27 = load double, double* %4
%28 = load double, double* %6
%29 = fptosi double %28 to i32
%30 = call double @log(i32 %29)
%31 = call double @llvm.fmuladd.f64(double %27, double %30, double %26)
%32 = load double, double* %5
%33 = load double, double* %6
%34 = fsub double 1.000000e+00, %33
%35 = fptosi double %34 to i32
%36 = call double @log(i32 %35)
%37 = call double @llvm.fmuladd.f64(double %32, double %36, double %31)
%38 = fptosi double %37 to i64
%39 = call double @exp(i64 %38)
store double %39, double* %7
br label %40
40: ; preds = %15, %14
%41 = load double, double* %6
%42 = load double, double* %4
%43 = fadd double %42, 1.000000e+00
%44 = load double, double* %4
%45 = load double, double* %5
%46 = fadd double %44, %45
%47 = fadd double %46, 2.000000e+00
%48 = fdiv double %43, %47
%49 = fcmp olt double %41, %48
br i1 %49, label %50, label %60
50: ; preds = %40
%51 = load double, double* %7
%52 = load double, double* %4
%53 = load double, double* %5
%54 = load double, double* %6
%55 = fptosi double %54 to i32
%56 = call double @betacf(double %52, double %53, i32 %55)
%57 = fmul double %51, %56
%58 = load double, double* %4
%59 = fdiv double %57, %58
store double %59, double* %8
br label %72
60: ; preds = %40
%61 = load double, double* %7
%62 = load double, double* %5
%63 = load double, double* %4
%64 = load double, double* %6
%65 = fsub double 1.000000e+00, %64
%66 = fptosi double %65 to i32
%67 = call double @betacf(double %62, double %63, i32 %66)
%68 = fmul double %61, %67
%69 = load double, double* %5
%70 = fdiv double %68, %69
%71 = fsub double 1.000000e+00, %70
store double %71, double* %8
br label %72
72: ; preds = %60, %50
%73 = load double, double* %8
ret double %73
}

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