long double bdtrl(k, n, p)
int k, n;
long double p;
{
  long double dk, dn, q;
  if ((p < 0.0L) || (p > 1.0L))
    goto domerr;
  if ((k < 0) || (n < k)) {
  domerr:
    mtherr("bdtrl", 1);
    return (0.0L);
  }
  if (k == n)
    return (1.0L);
  q = 1.0L - p;
  dn = n - k;
  if (k == 0) {
    dk = powl(q, dn);
  } else {
    dk = k + 1;
    dk = incbetl(dn, dk, q);
  }
  return (dk);
}


x86 assembly (clang, -O0):
<bdtrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%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     1171 <bdtrl+0x41>
jmp    115b <bdtrl+0x2b>
fldt   -0x30(%rbp)
fld1
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1176 <bdtrl+0x46>
jmp    1171 <bdtrl+0x41>
jmp    1191 <bdtrl+0x61>
cmpl   $0x0,-0x14(%rbp)
jl     118c <bdtrl+0x5c>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ae <bdtrl+0x7e>
jmp    1191 <bdtrl+0x61>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
mov    $0x1,%esi
call   1050 <mtherr@plt>
fldz
fstpt  -0x10(%rbp)
jmp    123d <bdtrl+0x10d>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11c4 <bdtrl+0x94>
fld1
fstpt  -0x10(%rbp)
jmp    123d <bdtrl+0x10d>
fldt   -0x30(%rbp)
fld1
fsubp  %st,%st(1)
fstpt  -0x60(%rbp)
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    1204 <bdtrl+0xd4>
fldt   -0x60(%rbp)
fldt   -0x50(%rbp)
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
call   1030 <powl@plt>
fstpt  -0x40(%rbp)
jmp    1237 <bdtrl+0x107>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
fildl  -0x6c(%rbp)
fstpt  -0x40(%rbp)
fldt   -0x50(%rbp)
fldt   -0x40(%rbp)
fldt   -0x60(%rbp)
mov    %rsp,%rax
fstpt  0x20(%rax)
fstpt  0x10(%rax)
fstpt  (%rax)
xor    %eax,%eax
call   1040 <incbetl@plt>
mov    %eax,-0x68(%rbp)
fildl  -0x68(%rbp)
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bdtrl>:
sub    $0x48,%rsp
fldt   0x50(%rsp)
cmp    %edi,%esi
fldz
jl     119d <bdtrl+0x6d>
fstp   %st(0)
test   %edi,%edi
fldz
js     119d <bdtrl+0x6d>
fstp   %st(0)
fldz
fucomip %st(1),%st
fldz
ja     119d <bdtrl+0x6d>
fstp   %st(0)
fld1
fxch   %st(1)
fucomi %st(1),%st
fxch   %st(1)
ja     119d <bdtrl+0x6d>
sub    %edi,%esi
fxch   %st(1)
je     11b8 <bdtrl+0x88>
fstp   %st(1)
fld1
fsubp  %st,%st(1)
mov    %esi,0x44(%rsp)
fildl  0x44(%rsp)
test   %edi,%edi
je     11bf <bdtrl+0x8f>
add    $0x1,%edi
mov    %edi,0x3c(%rsp)
fildl  0x3c(%rsp)
fxch   %st(2)
fstpt  0x20(%rsp)
fstpt  (%rsp)
fstpt  0x10(%rsp)
xor    %eax,%eax
call   1040 <incbetl@plt>
mov    %eax,0x40(%rsp)
fildl  0x40(%rsp)
jmp    11b6 <bdtrl+0x86>
fstp   %st(1)
fstp   %st(0)
lea    0xe58(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <mtherr@plt>
fldz
fldz
fstp   %st(0)
add    $0x48,%rsp
ret
fstpt  0x10(%rsp)
fstpt  (%rsp)
call   1030 <powl@plt>
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"bdtrl\00"
define x86_fp80 @bdtrl(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 slt 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 x86_fp80 0xK00000000000000000000, x86_fp80* %4
br label %56
27: ; preds = %20
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store x86_fp80 0xK3FFF8000000000000000, x86_fp80* %4
br label %56
32: ; preds = %27
%33 = load x86_fp80, x86_fp80* %7
%34 = fsub x86_fp80 0xK3FFF8000000000000000, %33
store x86_fp80 %34, x86_fp80* %10
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = sub nsw i32 %35, %36
%38 = sitofp i32 %37 to x86_fp80
store x86_fp80 %38, x86_fp80* %9
%39 = load i32, i32* %5
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %32
%42 = load x86_fp80, x86_fp80* %10
%43 = load x86_fp80, x86_fp80* %9
%44 = call x86_fp80 @powl(x86_fp80 %42, x86_fp80 %43)
store x86_fp80 %44, x86_fp80* %8
br label %54
45: ; preds = %32
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
%48 = sitofp i32 %47 to x86_fp80
store x86_fp80 %48, x86_fp80* %8
%49 = load x86_fp80, x86_fp80* %9
%50 = load x86_fp80, x86_fp80* %8
%51 = load x86_fp80, x86_fp80* %10
%52 = call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbetl to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %49, x86_fp80 %50, x86_fp80 %51)
%53 = sitofp i32 %52 to x86_fp80
store x86_fp80 %53, x86_fp80* %8
br label %54
54: ; preds = %45, %41
%55 = load x86_fp80, x86_fp80* %8
store x86_fp80 %55, x86_fp80* %4
br label %56
56: ; preds = %54, %31, %25
%57 = load x86_fp80, x86_fp80* %4
ret x86_fp80 %57
}

LLVM IR (-O2):
@.str = [6 x i8] c"bdtrl\00"
define x86_fp80 @bdtrl(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 slt 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 %27
13: ; preds = %3
%14 = icmp eq i32 %1, %0
br i1 %14, label %27, label %15
15: ; preds = %13
%16 = fsub x86_fp80 0xK3FFF8000000000000000, %2
%17 = sub nsw i32 %1, %0
%18 = sitofp i32 %17 to x86_fp80
%19 = icmp eq i32 %0, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call x86_fp80 @powl(x86_fp80 %16, x86_fp80 %18)
br label %27
22: ; preds = %15
%23 = add nuw nsw i32 %0, 1
%24 = sitofp i32 %23 to x86_fp80
%25 = tail call i32 (x86_fp80, x86_fp80, x86_fp80, ...) bitcast (i32 (...)* @incbetl to i32 (x86_fp80, x86_fp80, x86_fp80, ...)*)(x86_fp80 %18, x86_fp80 %24, x86_fp80 %16)
%26 = sitofp i32 %25 to x86_fp80
br label %27
27: ; preds = %20, %22, %13, %11
%28 = phi x86_fp80 [ 0xK00000000000000000000, %11 ], [ 0xK3FFF8000000000000000, %13 ], [ %21, %20 ], [ %26, %22 ]
ret x86_fp80 %28
}