double cephes_bdtrc(k, n, p)
int k, n;
double p;
{
  double dk, dn;
  if ((p < 0.0) || (p > 1.0))
    goto domerr;
  if (k < 0)
    return (1.0);
  if (n < k) {
  domerr:
    mtherr("bdtrc", 1);
    return (0.0);
  }
  if (k == n)
    return (0.0);
  dn = n - k;
  if (k == 0) {
    if (p < .01)
      dk = -cephes_expm1(dn * cephes_log1p(-p));
    else
      dk = 1.0 - cephes_pow(1.0 - p, dn);
  } else {
    dk = k + 1;
    dk = cephes_incbet(dk, dn, p);
  }
  return (dk);
}


x86 assembly (clang, -O0):
<cephes_bdtrc>:
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     1188 <cephes_bdtrc+0x38>
movsd  -0x18(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118d <cephes_bdtrc+0x3d>
jmp    11ba <cephes_bdtrc+0x6a>
cmpl   $0x0,-0xc(%rbp)
jge    11a9 <cephes_bdtrc+0x59>
movsd  0xe61(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12df <cephes_bdtrc+0x18f>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11da <cephes_bdtrc+0x8a>
jmp    11ba <cephes_bdtrc+0x6a>
lea    0xe4f(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1050 <mtherr@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12df <cephes_bdtrc+0x18f>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11f3 <cephes_bdtrc+0xa3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12df <cephes_bdtrc+0x18f>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12a7 <cephes_bdtrc+0x157>
movsd  0xdf4(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1274 <cephes_bdtrc+0x124>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    $0x1,%al
call   1060 <cephes_log1p@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
mov    $0x1,%al
call   1040 <cephes_expm1@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12a2 <cephes_bdtrc+0x152>
movsd  0xd84(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    $0x2,%al
call   1030 <cephes_pow@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd67(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12d5 <cephes_bdtrc+0x185>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mov    $0x3,%al
call   1070 <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_bdtrc>:
push   %rax
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
ja     1171 <cephes_bdtrc+0x21>
ucomisd 0xe99(%rip),%xmm2
ja     1171 <cephes_bdtrc+0x21>
test   %edi,%edi
js     118a <cephes_bdtrc+0x3a>
sub    %edi,%esi
jge    1194 <cephes_bdtrc+0x44>
lea    0xea8(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <mtherr@plt>
xorpd  %xmm0,%xmm0
pop    %rax
ret
movsd  0xe6e(%rip),%xmm0
pop    %rax
ret
xorpd  %xmm0,%xmm0
je     11fb <cephes_bdtrc+0xab>
cvtsi2sd %esi,%xmm1
test   %edi,%edi
je     11b5 <cephes_bdtrc+0x65>
add    $0x1,%edi
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
mov    $0x3,%al
call   1070 <cephes_incbet@plt>
jmp    11f4 <cephes_bdtrc+0xa4>
movsd  0xe4b(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    11fd <cephes_bdtrc+0xad>
xorpd  0xe45(%rip),%xmm2
movapd %xmm2,%xmm0
mov    $0x1,%al
movsd  %xmm1,(%rsp)
call   1060 <cephes_log1p@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
mov    $0x1,%al
call   1040 <cephes_expm1@plt>
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
pop    %rax
ret
movsd  0xdfb(%rip),%xmm0
subsd  %xmm2,%xmm0
mov    $0x2,%al
call   1030 <cephes_pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xde1(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [6 x i8] c"bdtrc\00"
define double @cephes_bdtrc(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 %25
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store double 1.000000e+00, double* %4
br label %71
20: ; preds = %16
%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
br label %25
25: ; preds = %24, %15
%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 %71
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 double 0.000000e+00, double* %4
br label %71
32: ; preds = %27
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = sub nsw i32 %33, %34
%36 = sitofp i32 %35 to double
store double %36, double* %9
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %60
39: ; preds = %32
%40 = load double, double* %7
%41 = fcmp olt double %40, 1.000000e-02
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load double, double* %9
%44 = load double, double* %7
%45 = fneg double %44
%46 = call i32 (double, ...) bitcast (i32 (...)* @cephes_log1p to i32 (double, ...)*)(double %45)
%47 = sitofp i32 %46 to double
%48 = fmul double %43, %47
%49 = call i32 (double, ...) bitcast (i32 (...)* @cephes_expm1 to i32 (double, ...)*)(double %48)
%50 = sub nsw i32 0, %49
%51 = sitofp i32 %50 to double
store double %51, double* %8
br label %59
52: ; preds = %39
%53 = load double, double* %7
%54 = fsub double 1.000000e+00, %53
%55 = load double, double* %9
%56 = call i32 (double, double, ...) bitcast (i32 (...)* @cephes_pow to i32 (double, double, ...)*)(double %54, double %55)
%57 = sitofp i32 %56 to double
%58 = fsub double 1.000000e+00, %57
store double %58, double* %8
br label %59
59: ; preds = %52, %42
br label %69
60: ; preds = %32
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
%63 = sitofp i32 %62 to double
store double %63, double* %8
%64 = load double, double* %8
%65 = load double, double* %9
%66 = load double, double* %7
%67 = call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbet to i32 (double, double, double, ...)*)(double %64, double %65, double %66)
%68 = sitofp i32 %67 to double
store double %68, double* %8
br label %69
69: ; preds = %60, %59
%70 = load double, double* %8
store double %70, double* %4
br label %71
71: ; preds = %69, %31, %25, %19
%72 = load double, double* %4
ret double %72
}

LLVM IR (-O2):
@.str = [6 x i8] c"bdtrc\00"
define double @cephes_bdtrc(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
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = icmp slt i32 %0, 0
br i1 %8, label %39, label %9
9: ; preds = %7
%10 = icmp slt i32 %1, %0
br i1 %10, label %11, label %13
11: ; preds = %9, %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 %39
13: ; preds = %9
%14 = icmp eq i32 %1, %0
br i1 %14, label %39, 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 %34
19: ; preds = %15
%20 = fcmp olt double %2, 1.000000e-02
br i1 %20, label %21, label %29
21: ; preds = %19
%22 = fneg double %2
%23 = tail call i32 (double, ...) bitcast (i32 (...)* @cephes_log1p to i32 (double, ...)*)(double %22)
%24 = sitofp i32 %23 to double
%25 = fmul double %17, %24
%26 = tail call i32 (double, ...) bitcast (i32 (...)* @cephes_expm1 to i32 (double, ...)*)(double %25)
%27 = sub nsw i32 0, %26
%28 = sitofp i32 %27 to double
br label %39
29: ; preds = %19
%30 = fsub double 1.000000e+00, %2
%31 = tail call i32 (double, double, ...) bitcast (i32 (...)* @cephes_pow to i32 (double, double, ...)*)(double %30, double %17)
%32 = sitofp i32 %31 to double
%33 = fsub double 1.000000e+00, %32
br label %39
34: ; preds = %15
%35 = add nuw nsw i32 %0, 1
%36 = sitofp i32 %35 to double
%37 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @cephes_incbet to i32 (double, double, double, ...)*)(double %36, double %17, double %2)
%38 = sitofp i32 %37 to double
br label %39
39: ; preds = %34, %29, %21, %13, %7, %11
%40 = phi double [ 0.000000e+00, %11 ], [ 1.000000e+00, %7 ], [ 0.000000e+00, %13 ], [ %28, %21 ], [ %33, %29 ], [ %38, %34 ]
ret double %40
}