double bdtri(k, n, y)
int k, n;
double y;
{
  double dk, dn, p;
  if ((y < 0.0) || (y > 1.0))
    goto domerr;
  if ((k < 0) || (n <= k)) {
  domerr:
    mtherr("bdtri", 1);
    return (0.0);
  }
  dn = n - k;
  if (k == 0) {
    if (y > 0.8)
      p = -expm1(log1p(y - 1.0) / dn);
    else
      p = 1.0 - pow(y, 1.0 / dn);
  } else {
    dk = k + 1;
    p = incbet(dn, dk, 0.5);
    if (p > 0.5)
      p = incbi(dk, dn, 1.0 - y);
    else
      p = 1.0 - incbi(dn, dk, y);
  }
  return (p);
}


x86 assembly (clang, -O0):
<bdtri>:
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     1198 <bdtri+0x38>
movsd  -0x18(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119d <bdtri+0x3d>
jmp    11b8 <bdtri+0x58>
cmpl   $0x0,-0xc(%rbp)
jl     11b3 <bdtri+0x53>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11d8 <bdtri+0x78>
jmp    11b8 <bdtri+0x58>
lea    0xe59(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1070 <mtherr@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1327 <bdtri+0x1c7>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1279 <bdtri+0x119>
movsd  -0x18(%rbp),%xmm0
movsd  0xe12(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1249 <bdtri+0xe9>
movsd  -0x18(%rbp),%xmm0
movsd  0xdeb(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1080 <log1p@plt>
divsd  -0x28(%rbp),%xmm0
call   1060 <expm1@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1274 <bdtri+0x114>
movsd  -0x18(%rbp),%xmm0
movsd  0xdaa(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xd95(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    131d <bdtri+0x1bd>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd6e(%rip),%xmm2
mov    $0x3,%al
call   1040 <incbet@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xd51(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ed <bdtri+0x18d>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xd2d(%rip),%xmm2
subsd  -0x18(%rbp),%xmm2
mov    $0x3,%al
call   1030 <incbi@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1318 <bdtri+0x1b8>
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mov    $0x3,%al
call   1030 <incbi@plt>
cvtsi2sd %eax,%xmm1
movsd  0xcf1(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    131d <bdtri+0x1bd>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bdtri>:
sub    $0x18,%rsp
sub    %edi,%esi
jle    11e6 <bdtri+0x86>
test   %edi,%edi
js     11e6 <bdtri+0x86>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     11e6 <bdtri+0x86>
ucomisd 0xe82(%rip),%xmm0
ja     11e6 <bdtri+0x86>
cvtsi2sd %esi,%xmm3
test   %edi,%edi
je     11ff <bdtri+0x9f>
movsd  %xmm0,0x10(%rsp)
add    $0x1,%edi
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
movsd  0xe68(%rip),%xmm2
movapd %xmm3,%xmm0
movsd  %xmm1,0x8(%rsp)
mov    $0x3,%al
movsd  %xmm3,(%rsp)
call   1040 <incbet@plt>
test   %eax,%eax
jle    1233 <bdtri+0xd3>
movsd  0xe3e(%rip),%xmm2
subsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
mov    $0x3,%al
call   1030 <incbi@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
jmp    1271 <bdtri+0x111>
lea    0xe43(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1070 <mtherr@plt>
xorpd  %xmm1,%xmm1
jmp    1271 <bdtri+0x111>
ucomisd 0xe09(%rip),%xmm0
jbe    1254 <bdtri+0xf4>
addsd  0xe07(%rip),%xmm0
movsd  %xmm3,(%rsp)
call   1080 <log1p@plt>
divsd  (%rsp),%xmm0
call   1060 <expm1@plt>
movapd %xmm0,%xmm1
xorpd  0xdef(%rip),%xmm1
jmp    1271 <bdtri+0x111>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mov    $0x3,%al
call   1030 <incbi@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
jmp    1265 <bdtri+0x105>
movsd  0xda4(%rip),%xmm1
divsd  %xmm3,%xmm1
call   1050 <pow@plt>
movsd  0xd93(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"bdtri\00"
define double @bdtri(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 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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1)
br label %42
13: ; preds = %3
%14 = sub nsw i32 %1, %0
%15 = sitofp i32 %14 to double
%16 = icmp eq i32 %0, 0
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = fcmp ogt double %2, 8.000000e-01
br i1 %18, label %19, label %25
19: ; preds = %17
%20 = fadd double %2, -1.000000e+00
%21 = tail call double @log1p(double %20)
%22 = fdiv double %21, %15
%23 = tail call double @expm1(double %22)
%24 = fneg double %23
br label %42
25: ; preds = %17
%26 = fdiv double 1.000000e+00, %15
%27 = tail call double @pow(double %2, double %26)
%28 = fsub double 1.000000e+00, %27
br label %42
29: ; preds = %13
%30 = add nuw nsw i32 %0, 1
%31 = sitofp i32 %30 to double
%32 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @incbet to i32 (double, double, double, ...)*)(double %15, double %31, double 5.000000e-01)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = fsub double 1.000000e+00, %2
%36 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @incbi to i32 (double, double, double, ...)*)(double %31, double %15, double %35)
%37 = sitofp i32 %36 to double
br label %42
38: ; preds = %29
%39 = tail call i32 (double, double, double, ...) bitcast (i32 (...)* @incbi to i32 (double, double, double, ...)*)(double %15, double %31, double %2)
%40 = sitofp i32 %39 to double
%41 = fsub double 1.000000e+00, %40
br label %42
42: ; preds = %25, %19, %38, %34, %11
%43 = phi double [ 0.000000e+00, %11 ], [ %24, %19 ], [ %28, %25 ], [ %37, %34 ], [ %41, %38 ]
ret double %43
}