#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 */
float exp(float);
float log(double);
float betai(float a, float b, float x) {
  float betacf(float a, float b, float x);
  float gammln(float xx);
  void nrerror(char error_text[]);
  float bt;
  if (x < 0.0 || x > 1.0)
    nrerror("Bad x in routine betai");
  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    $0x40,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
ja     1198 <betai+0x48>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a4 <betai+0x54>
lea    0xe71(%rip),%rdi
call   1030 <nrerror@plt>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c5 <betai+0x75>
jp     11c5 <betai+0x75>
jmp    11e6 <betai+0x96>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11f3 <betai+0xa3>
jp     11f3 <betai+0xa3>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    12b2 <betai+0x162>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
call   1060 <gammln@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x8(%rbp),%xmm0
call   1060 <gammln@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0xc(%rbp),%xmm0
call   1060 <gammln@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1050 <log@plt>
movss  -0x24(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x20(%rbp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd76(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1050 <log@plt>
movss  -0x1c(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x18(%rbp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <exp@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd34(%rip),%xmm2
addsd  %xmm2,%xmm0
movss  -0x8(%rbp),%xmm2
addss  -0xc(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0xd22(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1331 <betai+0x1e1>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
call   1070 <betacf@plt>
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
mulss  %xmm1,%xmm0
divss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    138d <betai+0x23d>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
cvtss2sd %xmm2,%xmm3
movsd  0xcaa(%rip),%xmm2
subsd  %xmm3,%xmm2
cvtsd2ss %xmm2,%xmm2
call   1070 <betacf@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
mulss  %xmm1,%xmm0
divss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xc80(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<betai>:
sub    $0x48,%rsp
movss  %xmm1,0x10(%rsp)
movaps %xmm0,%xmm3
xorps  %xmm0,%xmm0
ucomiss %xmm2,%xmm0
movaps %xmm3,0x20(%rsp)
movss  %xmm2,0x14(%rsp)
ja     117c <betai+0x2c>
movaps %xmm2,%xmm4
ucomiss 0xe86(%rip),%xmm2
jbe    1193 <betai+0x43>
lea    0xe9d(%rip),%rdi
call   1030 <nrerror@plt>
movss  0x14(%rsp),%xmm4
movaps 0x20(%rsp),%xmm3
xorps  %xmm2,%xmm2
cvtss2sd %xmm4,%xmm2
xorps  %xmm5,%xmm5
ucomiss %xmm5,%xmm4
movaps %xmm3,%xmm1
addss  0x10(%rsp),%xmm1
jne    11b1 <betai+0x61>
jnp    1268 <betai+0x118>
ucomiss 0xe48(%rip),%xmm4
jne    11c0 <betai+0x70>
jnp    1268 <betai+0x118>
movaps %xmm1,%xmm0
movsd  %xmm2,0x18(%rsp)
movaps %xmm1,0x30(%rsp)
call   1060 <gammln@plt>
movss  %xmm0,0xc(%rsp)
movaps 0x20(%rsp),%xmm0
call   1060 <gammln@plt>
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
movss  0x10(%rsp),%xmm0
call   1060 <gammln@plt>
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
mulss  0x20(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movsd  0xdd5(%rip),%xmm0
subsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
mulss  0x10(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
call   1040 <exp@plt>
movaps 0x30(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
movss  0x14(%rsp),%xmm4
movaps 0x20(%rsp),%xmm3
movaps %xmm0,%xmm5
movaps %xmm3,%xmm0
unpcklps %xmm1,%xmm0
cvtps2pd %xmm0,%xmm0
addpd  0xd97(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
divsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
movss  %xmm5,0xc(%rsp)
jbe    12b4 <betai+0x164>
movaps %xmm3,%xmm0
movss  0x10(%rsp),%xmm1
movaps %xmm4,%xmm2
call   1070 <betacf@plt>
movss  0xc(%rsp),%xmm1
mulss  %xmm0,%xmm1
divss  0x20(%rsp),%xmm1
jmp    12ed <betai+0x19d>
movss  0xd44(%rip),%xmm2
subss  %xmm4,%xmm2
movss  0x10(%rsp),%xmm0
movaps %xmm3,%xmm1
call   1070 <betacf@plt>
movss  0xc(%rsp),%xmm1
mulss  %xmm0,%xmm1
divss  0x10(%rsp),%xmm1
movaps %xmm1,%xmm0
movss  0xd17(%rip),%xmm1
subss  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Bad x in routine betai\00"
define float @betai(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
%9 = load float, float* %7
%10 = fpext float %9 to double
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load float, float* %7
%14 = fpext float %13 to double
%15 = fcmp ogt double %14, 1.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %12, %3
br label %17
17: ; preds = %16, %12
%18 = load float, float* %7
%19 = fpext float %18 to double
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load float, float* %7
%23 = fpext float %22 to double
%24 = fcmp oeq double %23, 1.000000e+00
br i1 %24, label %25, label %26
25: ; preds = %21, %17
store float 0.000000e+00, float* %8
br label %49
26: ; preds = %21
%27 = load float, float* %5
%28 = load float, float* %6
%29 = fadd float %27, %28
%30 = call float @gammln(float %29)
%31 = load float, float* %5
%32 = call float @gammln(float %31)
%33 = fsub float %30, %32
%34 = load float, float* %6
%35 = call float @gammln(float %34)
%36 = fsub float %33, %35
%37 = load float, float* %5
%38 = load float, float* %7
%39 = fpext float %38 to double
%40 = call float @log(double %39)
%41 = call float @llvm.fmuladd.f32(float %37, float %40, float %36)
%42 = load float, float* %6
%43 = load float, float* %7
%44 = fpext float %43 to double
%45 = fsub double 1.000000e+00, %44
%46 = call float @log(double %45)
%47 = call float @llvm.fmuladd.f32(float %42, float %46, float %41)
%48 = call float @exp(float %47)
store float %48, float* %8
br label %49
49: ; preds = %26, %25
%50 = load float, float* %7
%51 = fpext float %50 to double
%52 = load float, float* %5
%53 = fpext float %52 to double
%54 = fadd double %53, 1.000000e+00
%55 = load float, float* %5
%56 = load float, float* %6
%57 = fadd float %55, %56
%58 = fpext float %57 to double
%59 = fadd double %58, 2.000000e+00
%60 = fdiv double %54, %59
%61 = fcmp olt double %51, %60
br i1 %61, label %62, label %71
62: ; preds = %49
%63 = load float, float* %8
%64 = load float, float* %5
%65 = load float, float* %6
%66 = load float, float* %7
%67 = call float @betacf(float %64, float %65, float %66)
%68 = fmul float %63, %67
%69 = load float, float* %5
%70 = fdiv float %68, %69
store float %70, float* %4
br label %86
71: ; preds = %49
%72 = load float, float* %8
%73 = load float, float* %6
%74 = load float, float* %5
%75 = load float, float* %7
%76 = fpext float %75 to double
%77 = fsub double 1.000000e+00, %76
%78 = fptrunc double %77 to float
%79 = call float @betacf(float %73, float %74, float %78)
%80 = fmul float %72, %79
%81 = load float, float* %6
%82 = fdiv float %80, %81
%83 = fpext float %82 to double
%84 = fsub double 1.000000e+00, %83
%85 = fptrunc double %84 to float
store float %85, float* %4
br label %86
86: ; preds = %71, %62
%87 = load float, float* %4
ret float %87
}

LLVM IR (-O2):
@.str = [23 x i8] c"Bad x in routine betai\00"
define float @betai(float %0, float %1, float %2) {
%4 = fpext float %2 to double
%5 = fcmp olt float %2, 0.000000e+00
%6 = fcmp ogt float %2, 1.000000e+00
%7 = or i1 %5, %6
br i1 %7, label %8, label %9
8: ; preds = %3
tail call void @nrerror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %3, %8
%10 = fcmp oeq float %2, 0.000000e+00
%11 = fcmp oeq float %2, 1.000000e+00
%12 = or i1 %10, %11
%13 = fadd float %0, %1
br i1 %12, label %26, label %14
14: ; preds = %9
%15 = tail call float @gammln(float %13)
%16 = tail call float @gammln(float %0)
%17 = fsub float %15, %16
%18 = tail call float @gammln(float %1)
%19 = fsub float %17, %18
%20 = tail call float @log(double %4)
%21 = tail call float @llvm.fmuladd.f32(float %0, float %20, float %19)
%22 = fsub double 1.000000e+00, %4
%23 = tail call float @log(double %22)
%24 = tail call float @llvm.fmuladd.f32(float %1, float %23, float %21)
%25 = tail call float @exp(float %24)
br label %26
26: ; preds = %9, %14
%27 = phi float [ %25, %14 ], [ 0.000000e+00, %9 ]
%28 = insertelement <2 x float> poison, float %0, i64 0
%29 = insertelement <2 x float> %28, float %13, i64 1
%30 = fpext <2 x float> %29 to <2 x double>
%31 = fadd <2 x double> %30, <double 1.000000e+00, double 2.000000e+00>
%32 = extractelement <2 x double> %31, i64 0
%33 = extractelement <2 x double> %31, i64 1
%34 = fdiv double %32, %33
%35 = fcmp ogt double %34, %4
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = tail call float @betacf(float %0, float %1, float %2)
%38 = fmul float %27, %37
%39 = fdiv float %38, %0
br label %46
40: ; preds = %26
%41 = fsub float 1.000000e+00, %2
%42 = tail call float @betacf(float %1, float %0, float %41)
%43 = fmul float %27, %42
%44 = fdiv float %43, %1
%45 = fsub float 1.000000e+00, %44
br label %46
46: ; preds = %40, %36
%47 = phi float [ %39, %36 ], [ %45, %40 ]
ret float %47
}