long double bdtril(k, n, y)
int k, n;
long double y;
{
  long double dk, dn, p;
  if ((y < 0.0L) || (y > 1.0L))
    goto domerr;
  if ((k < 0) || (n <= k)) {
  domerr:
    mtherr("bdtril", 1);
    return (0.0L);
  }
  dn = n - k;
  if (k == 0) {
    if (y > 0.8L)
      p = -expm1l(log1pl(y - 1.0L) / dn);
    else
      p = 1.0L - powl(y, 1.0L / dn);
  } else {
    dk = k + 1;
    p = incbetl(dn, dk, y);
    if (p > 0.5)
      p = incbil(dk, dn, 1.0L - y);
    else
      p = 1.0 - incbil(dn, dk, y);
  }
  return (p);
}


x86 assembly (clang, -O0):
<bdtril>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
fldt   0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
ja     11a1 <bdtril+0x41>
jmp    118b <bdtril+0x2b>
fldt   -0x30(%rbp)
fld1
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    11a6 <bdtril+0x46>
jmp    11a1 <bdtril+0x41>
jmp    11c1 <bdtril+0x61>
cmpl   $0x0,-0x14(%rbp)
jl     11bc <bdtril+0x5c>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11de <bdtril+0x7e>
jmp    11c1 <bdtril+0x61>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
mov    $0x1,%esi
call   1080 <mtherr@plt>
fldz
fstpt  -0x10(%rbp)
jmp    1329 <bdtril+0x1c9>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x64(%rbp)
fildl  -0x64(%rbp)
fstpt  -0x50(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    126e <bdtril+0x10e>
fldt   -0x30(%rbp)
fldt   0xe0e(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    123f <bdtril+0xdf>
jmp    1213 <bdtril+0xb3>
fldt   -0x30(%rbp)
fld1
fchs
faddp  %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <log1pl@plt>
fldt   -0x50(%rbp)
fdivrp %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
call   1060 <expm1l@plt>
fchs
fstpt  -0x60(%rbp)
jmp    1269 <bdtril+0x109>
fldt   -0x30(%rbp)
fldt   -0x50(%rbp)
fld1
fld    %st(0)
fstpt  -0x88(%rbp)
fdivp  %st,%st(1)
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
call   1030 <powl@plt>
fldt   -0x88(%rbp)
fsubp  %st,%st(1)
fstpt  -0x60(%rbp)
jmp    1323 <bdtril+0x1c3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
fildl  -0x6c(%rbp)
fstpt  -0x40(%rbp)
fldt   -0x50(%rbp)
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  0x20(%rax)
fstpt  0x10(%rax)
fstpt  (%rax)
xor    %eax,%eax
call   1050 <incbetl@plt>
mov    %eax,-0x68(%rbp)
fildl  -0x68(%rbp)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
flds   0xd56(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    12e8 <bdtril+0x188>
jmp    12bb <bdtril+0x15b>
fldt   -0x40(%rbp)
fldt   -0x50(%rbp)
fldt   -0x30(%rbp)
fld1
fsubp  %st,%st(1)
mov    %rsp,%rax
fstpt  0x20(%rax)
fstpt  0x10(%rax)
fstpt  (%rax)
xor    %eax,%eax
call   1070 <incbil@plt>
mov    %eax,-0x7c(%rbp)
fildl  -0x7c(%rbp)
fstpt  -0x60(%rbp)
jmp    131e <bdtril+0x1be>
fldt   -0x50(%rbp)
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
mov    %rsp,%rax
fstpt  0x20(%rax)
fstpt  0x10(%rax)
fstpt  (%rax)
xor    %eax,%eax
call   1070 <incbil@plt>
cvtsi2sd %eax,%xmm1
movsd  0xcf9(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
fldl   -0x78(%rbp)
fstpt  -0x60(%rbp)
jmp    1323 <bdtril+0x1c3>
fldt   -0x60(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bdtril>:
sub    $0x78,%rsp
fldt   0x80(%rsp)
sub    %edi,%esi
fldz
jle    121f <bdtril+0xbf>
fstp   %st(0)
test   %edi,%edi
fldz
js     121f <bdtril+0xbf>
fstp   %st(0)
fldz
fucomip %st(1),%st
fldz
ja     121f <bdtril+0xbf>
fstp   %st(0)
fld1
fxch   %st(1)
fucomi %st(1),%st
fxch   %st(1)
ja     121f <bdtril+0xbf>
mov    %esi,0x48(%rsp)
fildl  0x48(%rsp)
test   %edi,%edi
je     123d <bdtril+0xdd>
fxch   %st(1)
fstpt  0x4c(%rsp)
add    $0x1,%edi
mov    %edi,0x44(%rsp)
fildl  0x44(%rsp)
fld    %st(2)
fstpt  0x20(%rsp)
fld    %st(1)
fstpt  (%rsp)
fld    %st(0)
fstpt  0x64(%rsp)
fstpt  0x10(%rsp)
xor    %eax,%eax
fxch   %st(1)
fstpt  0x58(%rsp)
fstpt  0x34(%rsp)
call   1050 <incbetl@plt>
test   %eax,%eax
jle    1274 <bdtril+0x114>
fldt   0x4c(%rsp)
fldt   0x58(%rsp)
fsubrp %st,%st(1)
fstpt  0x20(%rsp)
fldt   0x34(%rsp)
fstpt  0x10(%rsp)
fldt   0x64(%rsp)
fstpt  (%rsp)
xor    %eax,%eax
call   1070 <incbil@plt>
mov    %eax,0x40(%rsp)
fildl  0x40(%rsp)
add    $0x78,%rsp
ret
fstp   %st(1)
fstp   %st(0)
lea    0xdf6(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1080 <mtherr@plt>
fldz
add    $0x78,%rsp
ret
fldt   0xdcd(%rip)
fxch   %st(3)
fucomi %st(3),%st
fstp   %st(3)
jbe    12b1 <bdtril+0x151>
fxch   %st(1)
fchs
faddp  %st,%st(2)
fxch   %st(1)
fstpt  (%rsp)
fstpt  0x34(%rsp)
call   1040 <log1pl@plt>
fldt   0x34(%rsp)
fdivrp %st,%st(1)
fstpt  (%rsp)
call   1060 <expm1l@plt>
fchs
add    $0x78,%rsp
ret
fldt   0x58(%rsp)
fstpt  0x20(%rsp)
fldt   0x64(%rsp)
fstpt  0x10(%rsp)
fldt   0x34(%rsp)
fstpt  (%rsp)
xor    %eax,%eax
call   1070 <incbil@plt>
cvtsi2sd %eax,%xmm0
movsd  0xd62(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x70(%rsp)
fldl   0x70(%rsp)
add    $0x78,%rsp
ret
fdivr  %st(1),%st
fstpt  0x10(%rsp)
fxch   %st(1)
fstpt  (%rsp)
fstpt  0x4c(%rsp)
call   1030 <powl@plt>
fldt   0x4c(%rsp)
fsubp  %st,%st(1)
add    $0x78,%rsp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"bdtril\00"
define x86_fp80 @bdtril(i32 %0, i32 %1, x86_fp80 %2) {
%4 = alloca x86_fp80
%5 = alloca i32
%6 = alloca i32
%7 = alloca x86_fp80
%8 = alloca x86_fp80
%9 = alloca x86_fp80
%10 = alloca x86_fp80
store i32 %0, i32* %5
store i32 %1, i32* %6
store x86_fp80 %2, x86_fp80* %7
%11 = load x86_fp80, x86_fp80* %7
%12 = fcmp olt x86_fp80 %11, 0xK00000000000000000000
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load x86_fp80, x86_fp80* %7
%15 = fcmp ogt x86_fp80 %14, 0xK3FFF8000000000000000
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 ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1)
store x86_fp80 0xK00000000000000000000, x86_fp80* %4
br label %81
27: ; preds = %20
%28 = load i32, i32* %6
%29 = load i32, i32* %5
%30 = sub nsw i32 %28, %29
%31 = sitofp i32 %30 to x86_fp80
store x86_fp80 %31, x86_fp80* %9
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %52
34: ; preds = %27
%35 = load x86_fp80, x86_fp80* %7
%36 = fcmp ogt x86_fp80 %35, 0xK3FFECCCCCCCCCCCCCCCD
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load x86_fp80, x86_fp80* %7
%39 = fsub x86_fp80 %38, 0xK3FFF8000000000000000
%40 = call x86_fp80 @log1pl(x86_fp80 %39)
%41 = load x86_fp80, x86_fp80* %9
%42 = fdiv x86_fp80 %40, %41
%43 = call x86_fp80 @expm1l(x86_fp80 %42)
%44 = fneg x86_fp80 %43
store x86_fp80 %44, x86_fp80* %10
br label %51
45: ; preds = %34
%46 = load x86_fp80, x86_fp80* %7
%47 = load x86_fp80, x86_fp80* %9
%48 = fdiv x86_fp80 0xK3FFF8000000000000000, %47
%49 = call x86_fp80 @powl(x86_fp80 %46, x86_fp80 %48)
%50 = fsub x86_fp80 0xK3FFF8000000000000000, %49
store x86_fp80 %50, x86_fp80* %10
br label %51
51: ; preds = %45, %37
br label %79
52: ; preds = %27
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
%55 = sitofp i32 %54 to x86_fp80
store x86_fp80 %55, x86_fp80* %8
%56 = load x86_fp80, x86_fp80* %9
%57 = load x86_fp80, x86_fp80* %8
%58 = load x86_fp80, x86_fp80* %7
%59 = call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbetl to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %56, x86_fp80 %57, x86_fp80 %58)
%60 = sitofp i32 %59 to x86_fp80
store x86_fp80 %60, x86_fp80* %10
%61 = load x86_fp80, x86_fp80* %10
%62 = fcmp ogt x86_fp80 %61, 0xK3FFE8000000000000000
br i1 %62, label %63, label %70
63: ; preds = %52
%64 = load x86_fp80, x86_fp80* %8
%65 = load x86_fp80, x86_fp80* %9
%66 = load x86_fp80, x86_fp80* %7
%67 = fsub x86_fp80 0xK3FFF8000000000000000, %66
%68 = call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbil to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %64, x86_fp80 %65, x86_fp80 %67)
%69 = sitofp i32 %68 to x86_fp80
store x86_fp80 %69, x86_fp80* %10
br label %78
70: ; preds = %52
%71 = load x86_fp80, x86_fp80* %9
%72 = load x86_fp80, x86_fp80* %8
%73 = load x86_fp80, x86_fp80* %7
%74 = call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbil to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %71, x86_fp80 %72, x86_fp80 %73)
%75 = sitofp i32 %74 to double
%76 = fsub double 1.000000e+00, %75
%77 = fpext double %76 to x86_fp80
store x86_fp80 %77, x86_fp80* %10
br label %78
78: ; preds = %70, %63
br label %79
79: ; preds = %78, %51
%80 = load x86_fp80, x86_fp80* %10
store x86_fp80 %80, x86_fp80* %4
br label %81
81: ; preds = %79, %25
%82 = load x86_fp80, x86_fp80* %4
ret x86_fp80 %82
}

LLVM IR (-O2):
@.str = [7 x i8] c"bdtril\00"
define x86_fp80 @bdtril(i32 %0, i32 %1, x86_fp80 %2) {
%4 = fcmp olt x86_fp80 %2, 0xK00000000000000000000
%5 = fcmp ogt x86_fp80 %2, 0xK3FFF8000000000000000
%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 ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1)
br label %43
13: ; preds = %3
%14 = sub nsw i32 %1, %0
%15 = sitofp i32 %14 to x86_fp80
%16 = icmp eq i32 %0, 0
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = fcmp ogt x86_fp80 %2, 0xK3FFECCCCCCCCCCCCCCCD
br i1 %18, label %19, label %25
19: ; preds = %17
%20 = fadd x86_fp80 %2, 0xKBFFF8000000000000000
%21 = tail call x86_fp80 @log1pl(x86_fp80 %20)
%22 = fdiv x86_fp80 %21, %15
%23 = tail call x86_fp80 @expm1l(x86_fp80 %22)
%24 = fneg x86_fp80 %23
br label %43
25: ; preds = %17
%26 = fdiv x86_fp80 0xK3FFF8000000000000000, %15
%27 = tail call x86_fp80 @powl(x86_fp80 %2, x86_fp80 %26)
%28 = fsub x86_fp80 0xK3FFF8000000000000000, %27
br label %43
29: ; preds = %13
%30 = add nuw nsw i32 %0, 1
%31 = sitofp i32 %30 to x86_fp80
%32 = tail call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbetl to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %15, x86_fp80 %31, x86_fp80 %2)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = fsub x86_fp80 0xK3FFF8000000000000000, %2
%36 = tail call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbil to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %31, x86_fp80 %15, x86_fp80 %35)
%37 = sitofp i32 %36 to x86_fp80
br label %43
38: ; preds = %29
%39 = tail call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbil to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %15, x86_fp80 %31, x86_fp80 %2)
%40 = sitofp i32 %39 to double
%41 = fsub double 1.000000e+00, %40
%42 = fpext double %41 to x86_fp80
br label %43
43: ; preds = %25, %19, %38, %34, %11
%44 = phi x86_fp80 [ 0xK00000000000000000000, %11 ], [ %24, %19 ], [ %28, %25 ], [ %37, %34 ], [ %42, %38 ]
ret x86_fp80 %44
}