#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double betai(double, double, double);
double expm1(double);
double log(double);
double log1p(double);
double pow(double, double);
double bdtrc(int k, int 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:
    return (-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 = betai(dk, dn, p);
  }
  return (log(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    12d0 <bdtrc+0x180>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c7 <bdtrc+0x77>
jmp    11ba <bdtrc+0x6a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d0 <bdtrc+0x180>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11e0 <bdtrc+0x90>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d0 <bdtrc+0x180>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1299 <bdtrc+0x149>
movsd  0xe07(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1269 <bdtrc+0x119>
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   1060 <expm1@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1294 <bdtrc+0x144>
movsd  0xd8f(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xd75(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12c1 <bdtrc+0x171>
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
call   1030 <betai@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
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     1196 <bdtrc+0x46>
ucomisd 0xe99(%rip),%xmm2
ja     1196 <bdtrc+0x46>
test   %edi,%edi
js     118e <bdtrc+0x3e>
sub    %edi,%esi
jle    1196 <bdtrc+0x46>
cvtsi2sd %esi,%xmm1
test   %edi,%edi
je     1198 <bdtrc+0x48>
add    $0x1,%edi
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
call   1030 <betai@plt>
pop    %rax
jmp    1040 <log@plt>
movsd  0xe6a(%rip),%xmm0
pop    %rax
ret
movsd  0xe68(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    11d4 <bdtrc+0x84>
xorpd  0xe62(%rip),%xmm2
movapd %xmm2,%xmm0
movsd  %xmm1,(%rsp)
call   1070 <log1p@plt>
mulsd  (%rsp),%xmm0
call   1060 <expm1@plt>
xorpd  0xe42(%rip),%xmm0
pop    %rax
jmp    1040 <log@plt>
movsd  0xe24(%rip),%xmm0
subsd  %xmm2,%xmm0
call   1050 <pow@plt>
movsd  0xe13(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
jmp    1040 <log@plt>

LLVM IR (-O0):
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 %67
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 %26
24: ; preds = %20
br label %25
25: ; preds = %24, %15
store double 0.000000e+00, double* %4
br label %67
26: ; preds = %20
%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 0.000000e+00, double* %4
br label %67
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 %56
38: ; preds = %31
%39 = load double, double* %7
%40 = fcmp olt double %39, 1.000000e-02
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load double, double* %9
%43 = load double, double* %7
%44 = fneg double %43
%45 = call double @log1p(double %44)
%46 = fmul double %42, %45
%47 = call double @expm1(double %46)
%48 = fneg double %47
store double %48, double* %8
br label %55
49: ; preds = %38
%50 = load double, double* %7
%51 = fsub double 1.000000e+00, %50
%52 = load double, double* %9
%53 = call double @pow(double %51, double %52)
%54 = fsub double 1.000000e+00, %53
store double %54, double* %8
br label %55
55: ; preds = %49, %41
br label %64
56: ; preds = %31
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
%59 = sitofp i32 %58 to double
store double %59, double* %8
%60 = load double, double* %8
%61 = load double, double* %9
%62 = load double, double* %7
%63 = call double @betai(double %60, double %61, double %62)
store double %63, double* %8
br label %64
64: ; preds = %56, %55
%65 = load double, double* %8
%66 = call double @log(double %65)
store double %66, double* %4
br label %67
67: ; preds = %64, %30, %25, %19
%68 = load double, double* %4
ret double %68
}

LLVM IR (-O2):
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 %34, label %7
7: ; preds = %3
%8 = icmp slt i32 %0, 0
br i1 %8, label %34, label %9
9: ; preds = %7
%10 = icmp sgt i32 %1, %0
br i1 %10, label %11, label %34
11: ; preds = %9
%12 = sub nsw i32 %1, %0
%13 = sitofp i32 %12 to double
%14 = icmp eq i32 %0, 0
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = fcmp olt double %2, 1.000000e-02
br i1 %16, label %17, label %23
17: ; preds = %15
%18 = fneg double %2
%19 = tail call double @log1p(double %18)
%20 = fmul double %19, %13
%21 = tail call double @expm1(double %20)
%22 = fneg double %21
br label %31
23: ; preds = %15
%24 = fsub double 1.000000e+00, %2
%25 = tail call double @pow(double %24, double %13)
%26 = fsub double 1.000000e+00, %25
br label %31
27: ; preds = %11
%28 = add nuw nsw i32 %0, 1
%29 = sitofp i32 %28 to double
%30 = tail call double @betai(double %29, double %13, double %2)
br label %31
31: ; preds = %17, %23, %27
%32 = phi double [ %22, %17 ], [ %26, %23 ], [ %30, %27 ]
%33 = tail call double @log(double %32)
br label %34
34: ; preds = %3, %9, %7, %31
%35 = phi double [ %33, %31 ], [ 1.000000e+00, %7 ], [ 0.000000e+00, %9 ], [ 0.000000e+00, %3 ]
ret double %35
}