#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 */
struct timeb {
  int dummy;
};

/* Variables and functions */
int ceil(double);
int /*<<< orphan*/ ftime(struct timeb *);
double invbinocdf2(double, int, int, double);
int /*<<< orphan*/ printf(char *, long, ...);
long time_difference(struct timeb, struct timeb);
int get_max_n_transcripts(int n_transcripts_cl, int n_cl, double cdf_threshold,
                          int n_transcripts_bck) {
  double p;
  double r = 0.001;
  int max_n_transcripts;
  int function_verbose = 0;
  struct timeb ti, tf;
  long tdif;
  if (function_verbose == 1) {
    printf("get_max_n_transcripts\tn_transcripts_cl=%d\tn_cl=%d\tcdf_threshold="
           "%1.10g\tn_transcripts_bck=%d\n",
           n_transcripts_cl, n_cl, cdf_threshold, n_transcripts_bck);
    ftime(&ti);
  }
  p = invbinocdf2(cdf_threshold, n_transcripts_cl, n_cl, r);
  if (p <= 0)
    p = r;
  max_n_transcripts = ceil(p * n_transcripts_bck) + 1;
  if (function_verbose == 1) {
    ftime(&tf);
    tdif = time_difference(ti, tf);
    printf("p=%1.6g\n", p);
    printf("max_n_transcripts=%d\n", max_n_transcripts);
    printf("\tget_max_n_transcripts:\t%ld ms cpu time\n", tdif);
  }
  return max_n_transcripts;
}


x86 assembly (clang, -O0):
<get_max_n_transcripts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jne    11aa <get_max_n_transcripts+0x5a>
movslq -0x4(%rbp),%rsi
mov    -0x8(%rbp),%edx
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%ecx
lea    0xe6e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    -0x38(%rbp),%rdi
call   1070 <ftime@plt>
movsd  -0x10(%rbp),%xmm0
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
movsd  -0x28(%rbp),%xmm1
call   1050 <invbinocdf2@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11dc <get_max_n_transcripts+0x8c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <ceil@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x30(%rbp)
jne    124f <get_max_n_transcripts+0xff>
lea    -0x40(%rbp),%rdi
call   1070 <ftime@plt>
mov    -0x38(%rbp),%edi
mov    -0x40(%rbp),%esi
call   1060 <time_difference@plt>
mov    %rax,-0x48(%rbp)
cvttsd2si -0x20(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x2c(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_max_n_transcripts>:
push   %rbx
mov    %edx,%ebx
movsd  0xed5(%rip),%xmm1
call   1040 <invbinocdf2@plt>
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
cmpnlesd %xmm1,%xmm2
andpd  %xmm2,%xmm0
movsd  0xeb7(%rip),%xmm1
andnpd %xmm1,%xmm2
orpd   %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm1,%xmm0
call   1030 <ceil@plt>
add    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeb = type { i32 }
@.str = [93 x i8] c"get_max_n_transcripts\09n_transcripts_cl=%d\09n_cl=%d\09cdf_threshold=%1.10g\09n_transcripts_bck=%d\0A\00"
@.str.1 = [9 x i8] c"p=%1.6g\0A\00"
@.str.2 = [22 x i8] c"max_n_transcripts=%d\0A\00"
@.str.3 = [41 x i8] c"\09get_max_n_transcripts:\09%ld ms cpu time\0A\00"
define i32 @get_max_n_transcripts(i32 %0, i32 %1, double %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.timeb
%14 = alloca %struct.timeb
%15 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 1.000000e-03, double* %10
store i32 0, i32* %12
%16 = load i32, i32* %12
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %26
18: ; preds = %4
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = load i32, i32* %6
%22 = load double, double* %7
%23 = load i32, i32* %8
%24 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i64 %20, i32 %21, double %22, i32 %23)
%25 = call i32 @ftime(%struct.timeb* %13)
br label %26
26: ; preds = %18, %4
%27 = load double, double* %7
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = load double, double* %10
%31 = call double @invbinocdf2(double %27, i32 %28, i32 %29, double %30)
store double %31, double* %9
%32 = load double, double* %9
%33 = fcmp ole double %32, 0.000000e+00
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = load double, double* %10
store double %35, double* %9
br label %36
36: ; preds = %34, %26
%37 = load double, double* %9
%38 = load i32, i32* %8
%39 = sitofp i32 %38 to double
%40 = fmul double %37, %39
%41 = call i32 @ceil(double %40)
%42 = add nsw i32 %41, 1
store i32 %42, i32* %11
%43 = load i32, i32* %12
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %60
45: ; preds = %36
%46 = call i32 @ftime(%struct.timeb* %14)
%47 = getelementptr inbounds %struct.timeb, %struct.timeb* %13, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.timeb, %struct.timeb* %14, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i64 @time_difference(i32 %48, i32 %50)
store i64 %51, i64* %15
%52 = load double, double* %9
%53 = fptosi double %52 to i64
%54 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %53)
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %56)
%58 = load i64, i64* %15
%59 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i64 %58)
br label %60
60: ; preds = %45, %36
%61 = load i32, i32* %11
ret i32 %61
}

LLVM IR (-O2):
%struct.timeb = type { i32 }
define i32 @get_max_n_transcripts(i32 %0, i32 %1, double %2, i32 %3) {
%5 = tail call double @invbinocdf2(double %2, i32 %0, i32 %1, double 1.000000e-03)
%6 = fcmp ugt double %5, 0.000000e+00
%7 = select i1 %6, double %5, double 1.000000e-03
%8 = sitofp i32 %3 to double
%9 = fmul double %7, %8
%10 = tail call i32 @ceil(double %9)
%11 = add nsw i32 %10, 1
ret i32 %11
}