#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 exp(scalar_t__);
int /*<<< orphan*/ fatalx(char *);
scalar_t__ lgamma(double);
double log(double);
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)
    fatalx("Bad x in routine betai\n");
  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     118c <betai+0x3c>
movsd  -0x20(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1198 <betai+0x48>
lea    0xe7d(%rip),%rdi
call   1030 <fatalx@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11bd <betai+0x6d>
jp     11bd <betai+0x6d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1357 <betai+0x207>
movsd  -0x20(%rbp),%xmm0
movsd  0xe36(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11ec <betai+0x9c>
jp     11ec <betai+0x9c>
movsd  0xe1e(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1357 <betai+0x207>
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  0xd8b(%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  0xd50(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xd41(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1312 <betai+0x1c2>
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    1357 <betai+0x207>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xcd2(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
call   1070 <betacf@plt>
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm0,%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xcb2(%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     116f <betai+0x1f>
ucomisd 0xe93(%rip),%xmm2
jbe    119f <betai+0x4f>
lea    0xe9a(%rip),%rdi
movsd  %xmm1,0x8(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x20(%rsp)
call   1030 <fatalx@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    11af <betai+0x5f>
jnp    12f0 <betai+0x1a0>
movsd  0xe49(%rip),%xmm0
ucomisd %xmm0,%xmm2
jne    11c3 <betai+0x73>
jnp    12f0 <betai+0x1a0>
movapd %xmm3,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  %xmm1,0x8(%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  0x8(%rsp),%xmm0
call   1050 <lgamma@plt>
add    %r14,%rax
sub    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
call   1060 <log@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xdc3(%rip),%xmm0
subsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
call   1060 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <exp@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
movsd  0x30(%rsp),%xmm1
addsd  0xd80(%rip),%xmm1
addsd  0xd70(%rip),%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jbe    12bf <betai+0x16f>
movapd %xmm3,%xmm0
movsd  0x8(%rsp),%xmm1
call   1070 <betacf@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
divsd  0x18(%rsp),%xmm0
jmp    12f0 <betai+0x1a0>
movsd  0x8(%rsp),%xmm0
movapd %xmm3,%xmm1
movsd  0x28(%rsp),%xmm2
call   1070 <betacf@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
movsd  0xd14(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Bad x in routine 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 %16
14: ; preds = %11, %3
%15 = call i32 @fatalx(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load double, double* %7
%18 = fcmp oeq double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %16
store double 0.000000e+00, double* %4
br label %76
20: ; preds = %16
%21 = load double, double* %7
%22 = fcmp oeq double %21, 1.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %20
store double 1.000000e+00, double* %4
br label %76
24: ; preds = %20
%25 = load double, double* %5
%26 = load double, double* %6
%27 = fadd double %25, %26
%28 = call i64 @lgamma(double %27)
%29 = load double, double* %5
%30 = call i64 @lgamma(double %29)
%31 = sub nsw i64 %28, %30
%32 = load double, double* %6
%33 = call i64 @lgamma(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
%47 = load double, double* %7
%48 = load double, double* %5
%49 = fadd double %48, 1.000000e+00
%50 = load double, double* %5
%51 = load double, double* %6
%52 = fadd double %50, %51
%53 = fadd double %52, 2.000000e+00
%54 = fdiv double %49, %53
%55 = fcmp olt double %47, %54
br i1 %55, label %56, label %65
56: ; preds = %24
%57 = load double, double* %8
%58 = load double, double* %5
%59 = load double, double* %6
%60 = load double, double* %7
%61 = call double @betacf(double %58, double %59, double %60)
%62 = fmul double %57, %61
%63 = load double, double* %5
%64 = fdiv double %62, %63
store double %64, double* %4
br label %76
65: ; preds = %24
%66 = load double, double* %8
%67 = load double, double* %6
%68 = load double, double* %5
%69 = load double, double* %7
%70 = fsub double 1.000000e+00, %69
%71 = call double @betacf(double %67, double %68, double %70)
%72 = fmul double %66, %71
%73 = load double, double* %6
%74 = fdiv double %72, %73
%75 = fsub double 1.000000e+00, %74
store double %75, double* %4
br label %76
76: ; preds = %65, %56, %23, %19
%77 = load double, double* %4
ret double %77
}

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