double cephes_bdtri(k, n, y)
int k, n;
double y;
{
  double dk, dn, p;
  if ((y < 0.0) || (y > 1.0))
    goto domerr;
  if ((k < 0) || (n <= k)) {
  domerr:
    mtherr("bdtri", 1);
    return (0.0);
  }
  dn = n - k;
  if (k == 0) {
    if (y > 0.8)
      p = -cephes_expm1(cephes_log1p(y - 1.0) / dn);
    else
      p = 1.0 - cephes_pow(y, 1.0 / dn);
  } else {
    dk = k + 1;
    p = cephes_incbet(dn, dk, 0.5);
    if (p > 0.5)
      p = cephes_incbi(dk, dn, 1.0 - y);
    else
      p = 1.0 - cephes_incbi(dn, dk, y);
  }
  return (p);
}


x86 assembly (clang, -O0):
<cephes_bdtri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     1198 <cephes_bdtri+0x38>
movsd  -0x18(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119d <cephes_bdtri+0x3d>
jmp    11b8 <cephes_bdtri+0x58>
cmpl   $0x0,-0xc(%rbp)
jl     11b3 <cephes_bdtri+0x53>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11d8 <cephes_bdtri+0x78>
jmp    11b8 <cephes_bdtri+0x58>
lea    0xe59(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1060 <mtherr@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1325 <cephes_bdtri+0x1c5>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1277 <cephes_bdtri+0x117>
movsd  -0x18(%rbp),%xmm0
movsd  0xe12(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1244 <cephes_bdtri+0xe4>
movsd  -0x18(%rbp),%xmm0
movsd  0xdeb(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    $0x1,%al
call   1070 <cephes_log1p@plt>
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
call   1050 <cephes_expm1@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1272 <cephes_bdtri+0x112>
movsd  -0x18(%rbp),%xmm0
movsd  0xdaf(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
mov    $0x2,%al
call   1040 <cephes_pow@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd97(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    131b <cephes_bdtri+0x1bb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd70(%rip),%xmm2
mov    $0x3,%al
call   1080 <cephes_incbet@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xd53(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12eb <cephes_bdtri+0x18b>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xd2f(%rip),%xmm2
subsd  -0x18(%rbp),%xmm2
mov    $0x3,%al
call   1030 <cephes_incbi@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1316 <cephes_bdtri+0x1b6>
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mov    $0x3,%al
call   1030 <cephes_incbi@plt>
cvtsi2sd %eax,%xmm1
movsd  0xcf3(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    131b <cephes_bdtri+0x1bb>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cephes_bdtri>:
sub    $0x18,%rsp
sub    %edi,%esi
jle    11dc <cephes_bdtri+0x7c>
test   %edi,%edi
js     11dc <cephes_bdtri+0x7c>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     11dc <cephes_bdtri+0x7c>
ucomisd 0xe82(%rip),%xmm0
ja     11dc <cephes_bdtri+0x7c>
cvtsi2sd %esi,%xmm3
test   %edi,%edi
je     11f8 <cephes_bdtri+0x98>
movsd  %xmm0,0x10(%rsp)
add    $0x1,%edi
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
movsd  0xe68(%rip),%xmm2
movapd %xmm3,%xmm0
movsd  %xmm1,0x8(%rsp)
mov    $0x3,%al
movsd  %xmm3,(%rsp)
call   1080 <cephes_incbet@plt>
test   %eax,%eax
jle    1237 <cephes_bdtri+0xd7>
movsd  0xe3e(%rip),%xmm2
subsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
mov    $0x3,%al
call   1030 <cephes_incbi@plt>
jmp    122b <cephes_bdtri+0xcb>
lea    0xe3d(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <mtherr@plt>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
ret
ucomisd 0xe10(%rip),%xmm0
jbe    1260 <cephes_bdtri+0x100>
addsd  0xe0e(%rip),%xmm0
mov    $0x1,%al
movsd  %xmm3,(%rsp)
call   1070 <cephes_log1p@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <cephes_expm1@plt>
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x18,%rsp
ret
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mov    $0x3,%al
call   1030 <cephes_incbi@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0xda2(%rip),%xmm0
jmp    1282 <cephes_bdtri+0x122>
movsd  0xd98(%rip),%xmm1
divsd  %xmm3,%xmm1
mov    $0x2,%al
call   1040 <cephes_pow@plt>
movsd  0xd85(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"bdtri\00"
define double @cephes_bdtri(i32 %0, i32 %1, double %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
%11 = load double, double* %7
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load double, double* %7
%15 = fcmp ogt double %14, 1.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %13, %3
br label %25
17: ; preds = %13
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = load i32, i32* %6
%22 = load i32, i32* %5
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20, %17
br label %25
25: ; preds = %24, %16
%26 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @mtherr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1)
store double 0.000000e+00, double* %4
br label %82
27: ; preds = %20
%28 = load i32, i32* %6
%29 = load i32, i32* %5
%30 = sub nsw i32 %28, %29
%31 = sitofp i32 %30 to double
store double %31, double* %9
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %55
34: ; preds = %27
%35 = load double, double* %7
%36 = fcmp ogt double %35, 8.000000e-01
br i1 %36, label %37, label %47
37: ; preds = %34
%38 = load double, double* %7
%39 = fsub double %38, 1.000000e+00
%40 = call i32 (double, ...) bitcast (i32 (...)* @cephes_log1p to i32 (double, ...)*)(double %39)
%41 = sitofp i32 %40 to double
%42 = load double, double* %9
%43 = fdiv double %41, %42
%44 = call i32 (double, ...) bitcast (i32 (...)* @cephes_expm1 to i32 (double, ...)*)(double %43)
%45 = sub nsw i32 0, %44
%46 = sitofp i32 %45 to double
store double %46, double* %10
br label %54
47: ; preds = %34
%48 = load double, double* %7
%49 = load double, double* %9
%50 = fdiv double 1.000000e+00, %49
%51 = call i32 (double, double, ...) bitcast (i32 (...)* @cephes_pow to i32 (double, double, ...)*)(double %48, double %50)
%52 = sitofp i32 %51 to double
%53 = fsub double 1.000000e+00, %52
store double %53, double* %10
br label %54
54: ; preds = %47, %37
br label %80
55: ; preds = %27
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
%58 = sitofp i32 %57 to double
store double %58, double* %8
%59 = load double, double* %9
%60 = load double, double* %8
%61 = call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbet to i32 (double, double, double, ...)*)(double %59, double %60, double 5.000000e-01)
%62 = sitofp i32 %61 to double
store double %62, double* %10
%63 = load double, double* %10
%64 = fcmp ogt double %63, 5.000000e-01
br i1 %64, label %65, label %72
65: ; preds = %55
%66 = load double, double* %8
%67 = load double, double* %9
%68 = load double, double* %7
%69 = fsub double 1.000000e+00, %68
%70 = call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbi to i32 (double, double, double, ...)*)(double %66, double %67, double %69)
%71 = sitofp i32 %70 to double
store double %71, double* %10
br label %79
72: ; preds = %55
%73 = load double, double* %9
%74 = load double, double* %8
%75 = load double, double* %7
%76 = call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbi to i32 (double, double, double, ...)*)(double %73, double %74, double %75)
%77 = sitofp i32 %76 to double
%78 = fsub double 1.000000e+00, %77
store double %78, double* %10
br label %79
79: ; preds = %72, %65
br label %80
80: ; preds = %79, %54
%81 = load double, double* %10
store double %81, double* %4
br label %82
82: ; preds = %80, %25
%83 = load double, double* %4
ret double %83
}

LLVM IR (-O2):
@.str = [6 x i8] c"bdtri\00"
define double @cephes_bdtri(i32 %0, i32 %1, double %2) {
%4 = fcmp olt double %2, 0.000000e+00
%5 = fcmp ogt double %2, 1.000000e+00
%6 = or i1 %4, %5
%7 = icmp slt i32 %0, 0
%8 = or i1 %7, %6
%9 = icmp sle i32 %1, %0
%10 = or i1 %9, %8
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @mtherr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1)
br label %45
13: ; preds = %3
%14 = sub nsw i32 %1, %0
%15 = sitofp i32 %14 to double
%16 = icmp eq i32 %0, 0
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = fcmp ogt double %2, 8.000000e-01
br i1 %18, label %19, label %27
19: ; preds = %17
%20 = fadd double %2, -1.000000e+00
%21 = tail call i32 (double, ...) bitcast (i32 (...)* @cephes_log1p to i32 (double, ...)*)(double %20)
%22 = sitofp i32 %21 to double
%23 = fdiv double %22, %15
%24 = tail call i32 (double, ...) bitcast (i32 (...)* @cephes_expm1 to i32 (double, ...)*)(double %23)
%25 = sub nsw i32 0, %24
%26 = sitofp i32 %25 to double
br label %45
27: ; preds = %17
%28 = fdiv double 1.000000e+00, %15
%29 = tail call i32 (double, double, ...) bitcast (i32 (...)* @cephes_pow to i32 (double, double, ...)*)(double %2, double %28)
%30 = sitofp i32 %29 to double
%31 = fsub double 1.000000e+00, %30
br label %45
32: ; preds = %13
%33 = add nuw nsw i32 %0, 1
%34 = sitofp i32 %33 to double
%35 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbet to i32 (double, double, double, ...)*)(double %15, double %34, double 5.000000e-01)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = fsub double 1.000000e+00, %2
%39 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbi to i32 (double, double, double, ...)*)(double %34, double %15, double %38)
%40 = sitofp i32 %39 to double
br label %45
41: ; preds = %32
%42 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbi to i32 (double, double, double, ...)*)(double %15, double %34, double %2)
%43 = sitofp i32 %42 to double
%44 = fsub double 1.000000e+00, %43
br label %45
45: ; preds = %27, %19, %41, %37, %11
%46 = phi double [ 0.000000e+00, %11 ], [ %26, %19 ], [ %31, %27 ], [ %40, %37 ], [ %44, %41 ]
ret double %46
}