double cephes_bdtr(k, n, p)
int k, n;
double p;
{
  double dk, dn;
  if ((p < 0.0) || (p > 1.0))
    goto domerr;
  if ((k < 0) || (n < k)) {
  domerr:
    mtherr("bdtr", 1);
    return (0.0);
  }
  if (k == n)
    return (1.0);
  dn = n - k;
  if (k == 0) {
    dk = cephes_pow(1.0 - p, dn);
  } else {
    dk = k + 1;
    dk = cephes_incbet(dn, dk, 1.0 - p);
  }
  return (dk);
}


x86 assembly (clang, -O0):
<cephes_bdtr>:
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     1168 <cephes_bdtr+0x38>
movsd  -0x18(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    116d <cephes_bdtr+0x3d>
jmp    1188 <cephes_bdtr+0x58>
cmpl   $0x0,-0xc(%rbp)
jl     1183 <cephes_bdtr+0x53>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a8 <cephes_bdtr+0x78>
jmp    1188 <cephes_bdtr+0x58>
lea    0xe79(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <mtherr@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <cephes_bdtr+0x116>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11c6 <cephes_bdtr+0x96>
movsd  0xe44(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <cephes_bdtr+0x116>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1206 <cephes_bdtr+0xd6>
movsd  0xe19(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    $0x2,%al
call   1030 <cephes_pow@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    123c <cephes_bdtr+0x10c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xdd9(%rip),%xmm2
subsd  -0x18(%rbp),%xmm2
mov    $0x3,%al
call   1050 <cephes_incbet@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cephes_bdtr>:
push   %rax
cmp    %edi,%esi
jl     115b <cephes_bdtr+0x2b>
test   %edi,%edi
js     115b <cephes_bdtr+0x2b>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     115b <cephes_bdtr+0x2b>
ucomisd 0xeb5(%rip),%xmm0
ja     115b <cephes_bdtr+0x2b>
sub    %edi,%esi
jne    1174 <cephes_bdtr+0x44>
movsd  0xea7(%rip),%xmm0
pop    %rax
ret
lea    0xea6(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <mtherr@plt>
xorpd  %xmm0,%xmm0
pop    %rax
ret
cvtsi2sd %esi,%xmm3
test   %edi,%edi
je     119f <cephes_bdtr+0x6f>
add    $0x1,%edi
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
movsd  0xe72(%rip),%xmm2
subsd  %xmm0,%xmm2
movapd %xmm3,%xmm0
mov    $0x3,%al
call   1050 <cephes_incbet@plt>
jmp    11ba <cephes_bdtr+0x8a>
movsd  0xe59(%rip),%xmm2
subsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
movapd %xmm3,%xmm1
mov    $0x2,%al
call   1030 <cephes_pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"bdtr\00"
define double @cephes_bdtr(i32 %0, i32 %1, double %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
%10 = load double, double* %7
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load double, double* %7
%14 = fcmp ogt double %13, 1.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %12, %3
br label %24
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19, %16
br label %24
24: ; preds = %23, %15
%25 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @mtherr to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
store double 0.000000e+00, double* %4
br label %56
26: ; preds = %19
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store double 1.000000e+00, double* %4
br label %56
31: ; preds = %26
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = sub nsw i32 %32, %33
%35 = sitofp i32 %34 to double
store double %35, double* %9
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load double, double* %7
%40 = fsub double 1.000000e+00, %39
%41 = load double, double* %9
%42 = call i32 (double, double, ...) bitcast (i32 (...)* @cephes_pow to i32 (double, double, ...)*)(double %40, double %41)
%43 = sitofp i32 %42 to double
store double %43, double* %8
br label %54
44: ; preds = %31
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
%47 = sitofp i32 %46 to double
store double %47, double* %8
%48 = load double, double* %9
%49 = load double, double* %8
%50 = load double, double* %7
%51 = fsub double 1.000000e+00, %50
%52 = call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbet to i32 (double, double, double, ...)*)(double %48, double %49, double %51)
%53 = sitofp i32 %52 to double
store double %53, double* %8
br label %54
54: ; preds = %44, %38
%55 = load double, double* %8
store double %55, double* %4
br label %56
56: ; preds = %54, %30, %24
%57 = load double, double* %4
ret double %57
}

LLVM IR (-O2):
@.str = [5 x i8] c"bdtr\00"
define double @cephes_bdtr(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 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 ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
br label %30
13: ; preds = %3
%14 = icmp eq i32 %1, %0
br i1 %14, label %30, label %15
15: ; preds = %13
%16 = sub nsw i32 %1, %0
%17 = sitofp i32 %16 to double
%18 = icmp eq i32 %0, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = fsub double 1.000000e+00, %2
%21 = tail call i32 (double, double, ...) bitcast (i32 (...)* @cephes_pow to i32 (double, double, ...)*)(double %20, double %17)
br label %27
22: ; preds = %15
%23 = add nuw nsw i32 %0, 1
%24 = sitofp i32 %23 to double
%25 = fsub double 1.000000e+00, %2
%26 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbet to i32 (double, double, double, ...)*)(double %17, double %24, double %25)
br label %27
27: ; preds = %22, %19
%28 = phi i32 [ %21, %19 ], [ %26, %22 ]
%29 = sitofp i32 %28 to double
br label %30
30: ; preds = %13, %27, %11
%31 = phi double [ 0.000000e+00, %11 ], [ %29, %27 ], [ 1.000000e+00, %13 ]
ret double %31
}