double 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 = -expm1(dn * log1p(-p));
    else
      dk = 1.0 - pow(1.0 - p, dn);
  } else {
    dk = k + 1;
    dk = incbet(dk, dn, p);
  }
  return (dk);
}


x86 assembly (clang, -O0):
<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 <bdtrc+0x38>
movsd  -0x18(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118d <bdtrc+0x3d>
jmp    11ba <bdtrc+0x6a>
cmpl   $0x0,-0xc(%rbp)
jge    11a9 <bdtrc+0x59>
movsd  0xe61(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e4 <bdtrc+0x194>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11da <bdtrc+0x8a>
jmp    11ba <bdtrc+0x6a>
lea    0xe4f(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1060 <mtherr@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e4 <bdtrc+0x194>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11f3 <bdtrc+0xa3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e4 <bdtrc+0x194>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12ac <bdtrc+0x15c>
movsd  0xdf4(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    127c <bdtrc+0x12c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1070 <log1p@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <expm1@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12a7 <bdtrc+0x157>
movsd  0xd7c(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xd62(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12da <bdtrc+0x18a>
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   1030 <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):
<bdtrc>:
push   %rax
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
ja     1171 <bdtrc+0x21>
ucomisd 0xe99(%rip),%xmm2
ja     1171 <bdtrc+0x21>
test   %edi,%edi
js     118a <bdtrc+0x3a>
sub    %edi,%esi
jge    1194 <bdtrc+0x44>
lea    0xea8(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <mtherr@plt>
xorpd  %xmm0,%xmm0
pop    %rax
ret
movsd  0xe6e(%rip),%xmm0
pop    %rax
ret
xorpd  %xmm0,%xmm0
je     11ba <bdtrc+0x6a>
cvtsi2sd %esi,%xmm1
test   %edi,%edi
je     11bc <bdtrc+0x6c>
add    $0x1,%edi
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
mov    $0x3,%al
call   1030 <incbet@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
pop    %rax
ret
movsd  0xe44(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    11f4 <bdtrc+0xa4>
xorpd  0xe3e(%rip),%xmm2
movapd %xmm2,%xmm0
movsd  %xmm1,(%rsp)
call   1070 <log1p@plt>
mulsd  (%rsp),%xmm0
call   1050 <expm1@plt>
xorpd  0xe1e(%rip),%xmm0
pop    %rax
ret
movsd  0xe04(%rip),%xmm0
subsd  %xmm2,%xmm0
call   1040 <pow@plt>
movsd  0xdf3(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [6 x i8] c"bdtrc\00"
define double @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 %68
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 %68
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 %68
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 %57
39: ; preds = %32
%40 = load double, double* %7
%41 = fcmp olt double %40, 1.000000e-02
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = load double, double* %9
%44 = load double, double* %7
%45 = fneg double %44
%46 = call double @log1p(double %45)
%47 = fmul double %43, %46
%48 = call double @expm1(double %47)
%49 = fneg double %48
store double %49, double* %8
br label %56
50: ; preds = %39
%51 = load double, double* %7
%52 = fsub double 1.000000e+00, %51
%53 = load double, double* %9
%54 = call double @pow(double %52, double %53)
%55 = fsub double 1.000000e+00, %54
store double %55, double* %8
br label %56
56: ; preds = %50, %42
br label %66
57: ; preds = %32
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
%60 = sitofp i32 %59 to double
store double %60, double* %8
%61 = load double, double* %8
%62 = load double, double* %9
%63 = load double, double* %7
%64 = call i32 (double, double, double, ...) bitcast (i32 (...)* @incbet to i32 (double, double, double, ...)*)(double %61, double %62, double %63)
%65 = sitofp i32 %64 to double
store double %65, double* %8
br label %66
66: ; preds = %57, %56
%67 = load double, double* %8
store double %67, double* %4
br label %68
68: ; preds = %66, %31, %25, %19
%69 = load double, double* %4
ret double %69
}

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