#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 calculate_threshold(int, int);
int log10(double);
double pow(int, double);
double reduce_factorial(int, int);
int calculate_cutoff(int branch_genome_size, int window_size,
                     int num_branch_snps) {
  double threshold = 0.0;
  int cutoff = 0;
  double pvalue = 0.0;
  double part1, part2, part3 = 0.0;
  threshold = calculate_threshold(branch_genome_size, window_size);
  while (pvalue <= threshold) {
    part1 = reduce_factorial(window_size, cutoff) -
            reduce_factorial(cutoff, cutoff);
    part2 = log10((num_branch_snps * 1.0) / branch_genome_size) * cutoff;
    part3 = log10(1.0 - ((num_branch_snps * 1.0) / branch_genome_size)) *
            (window_size - cutoff);
    pvalue = pvalue + pow(10, (part1 + part2 + part3));
    cutoff++;
  }
  cutoff--;
  return cutoff;
}


x86 assembly (clang, -O0):
<calculate_cutoff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <calculate_threshold@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     126b <calculate_cutoff+0x12b>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <reduce_factorial@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <reduce_factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe33(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <log10@plt>
imul   -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe07(%rip),%xmm0
mulsd  %xmm0,%xmm1
cvtsi2sdl -0x4(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xdf2(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1060 <log10@plt>
mov    -0x8(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
mov    $0xa,%edi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <calculate_cutoff+0x40>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_cutoff>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
call   1040 <calculate_threshold@plt>
mov    $0xffffffff,%ebp
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     1245 <calculate_cutoff+0x105>
movapd %xmm0,%xmm1
cvtsi2sd %r14d,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
divsd  %xmm0,%xmm3
movsd  0xe76(%rip),%xmm0
movsd  %xmm3,0x18(%rsp)
subsd  %xmm3,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0xffffffff,%ebp
mov    %r12d,%ebx
movsd  %xmm1,0x20(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,0x28(%rsp)
add    $0x1,%ebp
mov    %r12d,%edi
mov    %ebp,%esi
call   1030 <reduce_factorial@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
mov    %ebp,%esi
call   1030 <reduce_factorial@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <log10@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <log10@plt>
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
mov    $0xa,%edi
call   1050 <pow@plt>
movsd  0x28(%rsp),%xmm2
movsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm2
add    $0xffffffff,%ebx
ucomisd %xmm2,%xmm1
jae    11b0 <calculate_cutoff+0x70>
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calculate_cutoff(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %12
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call double @calculate_threshold(i32 %13, i32 %14)
store double %15, double* %7
br label %16
16: ; preds = %20, %3
%17 = load double, double* %9
%18 = load double, double* %7
%19 = fcmp ole double %17, %18
br i1 %19, label %20, label %61
20: ; preds = %16
%21 = load i32, i32* %5
%22 = load i32, i32* %8
%23 = call double @reduce_factorial(i32 %21, i32 %22)
%24 = load i32, i32* %8
%25 = load i32, i32* %8
%26 = call double @reduce_factorial(i32 %24, i32 %25)
%27 = fsub double %23, %26
store double %27, double* %10
%28 = load i32, i32* %6
%29 = sitofp i32 %28 to double
%30 = fmul double %29, 1.000000e+00
%31 = load i32, i32* %4
%32 = sitofp i32 %31 to double
%33 = fdiv double %30, %32
%34 = call i32 @log10(double %33)
%35 = load i32, i32* %8
%36 = mul nsw i32 %34, %35
%37 = sitofp i32 %36 to double
store double %37, double* %11
%38 = load i32, i32* %6
%39 = sitofp i32 %38 to double
%40 = fmul double %39, 1.000000e+00
%41 = load i32, i32* %4
%42 = sitofp i32 %41 to double
%43 = fdiv double %40, %42
%44 = fsub double 1.000000e+00, %43
%45 = call i32 @log10(double %44)
%46 = load i32, i32* %5
%47 = load i32, i32* %8
%48 = sub nsw i32 %46, %47
%49 = mul nsw i32 %45, %48
%50 = sitofp i32 %49 to double
store double %50, double* %12
%51 = load double, double* %9
%52 = load double, double* %10
%53 = load double, double* %11
%54 = fadd double %52, %53
%55 = load double, double* %12
%56 = fadd double %54, %55
%57 = call double @pow(i32 10, double %56)
%58 = fadd double %51, %57
store double %58, double* %9
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %16
61: ; preds = %16
%62 = load i32, i32* %8
%63 = add nsw i32 %62, -1
store i32 %63, i32* %8
%64 = load i32, i32* %8
ret i32 %64
}

LLVM IR (-O2):
define i32 @calculate_cutoff(i32 %0, i32 %1, i32 %2) {
%4 = tail call double @calculate_threshold(i32 %0, i32 %1)
%5 = fcmp ult double %4, 0.000000e+00
br i1 %5, label %30, label %6
6: ; preds = %3
%7 = sitofp i32 %2 to double
%8 = sitofp i32 %0 to double
%9 = fdiv double %7, %8
%10 = fsub double 1.000000e+00, %9
br label %11
11: ; preds = %6, %11
%12 = phi i32 [ 0, %6 ], [ %28, %11 ]
%13 = phi double [ 0.000000e+00, %6 ], [ %27, %11 ]
%14 = tail call double @reduce_factorial(i32 %1, i32 %12)
%15 = tail call double @reduce_factorial(i32 %12, i32 %12)
%16 = fsub double %14, %15
%17 = tail call i32 @log10(double %9)
%18 = mul nsw i32 %17, %12
%19 = sitofp i32 %18 to double
%20 = tail call i32 @log10(double %10)
%21 = sub nsw i32 %1, %12
%22 = mul nsw i32 %20, %21
%23 = sitofp i32 %22 to double
%24 = fadd double %16, %19
%25 = fadd double %24, %23
%26 = tail call double @pow(i32 10, double %25)
%27 = fadd double %13, %26
%28 = add nuw nsw i32 %12, 1
%29 = fcmp ugt double %27, %4
br i1 %29, label %30, label %11
30: ; preds = %11, %3
%31 = phi i32 [ -1, %3 ], [ %12, %11 ]
ret i32 %31
}