#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);
int /*<<< orphan*/ exit(int);
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, "Bad x in routine betai");
    exit(1);
  }
  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     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    $0x1,%edi
call   1070 <exit@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d8 <betai+0x78>
jp     11d8 <betai+0x78>
jmp    11f5 <betai+0x95>
movsd  -0x20(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1202 <betai+0xa2>
jp     1202 <betai+0xa2>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12b9 <betai+0x159>
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  0xd75(%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  0xd3a(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xd2b(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1328 <betai+0x1c8>
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    136d <betai+0x20d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xcbc(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
call   1080 <betacf@plt>
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xc9c(%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 %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
ja     12e1 <betai+0x181>
movapd %xmm2,%xmm4
ucomisd 0xe7b(%rip),%xmm2
ja     12e1 <betai+0x181>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm4
movapd %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm1,0x8(%rsp)
movsd  %xmm3,0x10(%rsp)
jne    11af <betai+0x4f>
jnp    1258 <betai+0xf8>
ucomisd 0xe49(%rip),%xmm4
jne    11bf <betai+0x5f>
jnp    1258 <betai+0xf8>
movapd %xmm2,%xmm0
movsd  %xmm4,(%rsp)
movsd  %xmm2,0x20(%rsp)
call   1060 <gammln@plt>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
call   1060 <gammln@plt>
mov    %rax,%r14
movsd  0x8(%rsp),%xmm0
call   1060 <gammln@plt>
add    %r14,%rax
sub    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
call   1050 <log@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xdd9(%rip),%xmm0
subsd  (%rsp),%xmm0
call   1050 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <exp@plt>
movsd  0x20(%rsp),%xmm2
movsd  (%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movsd  %xmm0,(%rsp)
movsd  0xd9b(%rip),%xmm0
addsd  0xd9b(%rip),%xmm2
addsd  %xmm3,%xmm0
divsd  %xmm2,%xmm0
ucomisd %xmm4,%xmm0
jbe    12a3 <betai+0x143>
movapd %xmm3,%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm4,%xmm2
call   1080 <betacf@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
divsd  0x10(%rsp),%xmm0
jmp    12d9 <betai+0x179>
movsd  0xd55(%rip),%xmm2
subsd  %xmm4,%xmm2
movsd  0x8(%rsp),%xmm0
movapd %xmm3,%xmm1
call   1080 <betacf@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
movsd  0xd2b(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd1f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Bad x in routine betai\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 ([23 x i8], [23 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 %24, label %21
21: ; preds = %18
%22 = load double, double* %7
%23 = fcmp oeq double %22, 1.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %21, %18
store double 0.000000e+00, double* %8
br label %48
25: ; preds = %21
%26 = load double, double* %5
%27 = load double, double* %6
%28 = fadd double %26, %27
%29 = call i64 @gammln(double %28)
%30 = load double, double* %5
%31 = call i64 @gammln(double %30)
%32 = sub nsw i64 %29, %31
%33 = load double, double* %6
%34 = call i64 @gammln(double %33)
%35 = sub nsw i64 %32, %34
%36 = sitofp i64 %35 to double
%37 = load double, double* %5
%38 = load double, double* %7
%39 = call double @log(double %38)
%40 = call double @llvm.fmuladd.f64(double %37, double %39, double %36)
%41 = load double, double* %6
%42 = load double, double* %7
%43 = fsub double 1.000000e+00, %42
%44 = call double @log(double %43)
%45 = call double @llvm.fmuladd.f64(double %41, double %44, double %40)
%46 = fptosi double %45 to i64
%47 = call double @exp(i64 %46)
store double %47, double* %8
br label %48
48: ; preds = %25, %24
%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 = %48
%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 = %48
%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
%79 = load double, double* %4
ret double %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Bad x in routine betai\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 ([23 x i8], [23 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
%13 = fcmp oeq double %2, 1.000000e+00
%14 = or i1 %12, %13
%15 = fadd double %0, %1
br i1 %14, label %30, label %16
16: ; preds = %11
%17 = tail call i64 @gammln(double %15)
%18 = tail call i64 @gammln(double %0)
%19 = tail call i64 @gammln(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)
br label %30
30: ; preds = %11, %16
%31 = phi double [ %29, %16 ], [ 0.000000e+00, %11 ]
%32 = fadd double %0, 1.000000e+00
%33 = fadd double %15, 2.000000e+00
%34 = fdiv double %32, %33
%35 = fcmp ogt double %34, %2
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = tail call double @betacf(double %0, double %1, double %2)
%38 = fmul double %31, %37
%39 = fdiv double %38, %0
br label %46
40: ; preds = %30
%41 = fsub double 1.000000e+00, %2
%42 = tail call double @betacf(double %1, double %0, double %41)
%43 = fmul double %31, %42
%44 = fdiv double %43, %1
%45 = fsub double 1.000000e+00, %44
br label %46
46: ; preds = %40, %36
%47 = phi double [ %39, %36 ], [ %45, %40 ]
ret double %47
}