#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 DBL_MAX;
double exp(int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
double *naive_calc_prob_dist(int const *, int const, int const);
int /*<<< orphan*/ probvec_tailsum(double *, int const, int const);
double *pruned_calc_prob_dist(int const *, int const, int const);
void snpcaller(const int *phred_quals, const int num_phred_quals,
               const int num_alt_phred_quals, const int naive,
               double *snp_pvalue, double *snp_likelihood) {
  double *probvec = NULL;
  *snp_pvalue = DBL_MAX;
  *snp_likelihood = DBL_MAX;
  if (naive) {
    probvec =
        naive_calc_prob_dist(phred_quals, num_phred_quals, num_alt_phred_quals);
    *snp_pvalue =
        exp(probvec_tailsum(probvec, num_alt_phred_quals, num_phred_quals + 1));
  } else {
    probvec = pruned_calc_prob_dist(phred_quals, num_phred_quals,
                                    num_alt_phred_quals);
    *snp_pvalue = exp(
        probvec_tailsum(probvec, num_alt_phred_quals, num_alt_phred_quals + 1));
  }
  if (NULL != probvec) {
    free(probvec);
  }
}


x86 assembly (clang, -O0):
<snpcaller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e64(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    0x2e51(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x0,-0x14(%rbp)
je     11de <snpcaller+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <naive_calc_prob_dist@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
call   1030 <probvec_tailsum@plt>
mov    %eax,%edi
call   1060 <exp@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1212 <snpcaller+0xc2>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <pruned_calc_prob_dist@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
call   1030 <probvec_tailsum@plt>
mov    %eax,%edi
call   1060 <exp@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
je     1227 <snpcaller+0xd7>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snpcaller>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %edx,%r15d
mov    %esi,%ebp
mov    0x2e7a(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,(%r8)
movsd  (%rax),%xmm0
movsd  %xmm0,(%r9)
test   %ecx,%ecx
je     118b <snpcaller+0x3b>
mov    %ebp,%esi
mov    %r15d,%edx
call   1050 <naive_calc_prob_dist@plt>
mov    %rax,%rbx
jmp    119b <snpcaller+0x4b>
mov    %ebp,%esi
mov    %r15d,%edx
call   1070 <pruned_calc_prob_dist@plt>
mov    %rax,%rbx
mov    %r15d,%ebp
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <probvec_tailsum@plt>
mov    %eax,%edi
call   1060 <exp@plt>
movsd  %xmm0,(%r14)
test   %rbx,%rbx
je     11ce <snpcaller+0x7e>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MAX = global double 0.000000e+00
define void @snpcaller(i32* %0, i32 %1, i32 %2, i32 %3, double* %4, double* %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double* %4, double** %11
store double* %5, double** %12
store double* null, double** %13
%14 = load double, double* @DBL_MAX
%15 = load double*, double** %11
store double %14, double* %15
%16 = load double, double* @DBL_MAX
%17 = load double*, double** %12
store double %16, double* %17
%18 = load i32, i32* %10
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %6
%21 = load i32*, i32** %7
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = call double* @naive_calc_prob_dist(i32* %21, i32 %22, i32 %23)
store double* %24, double** %13
%25 = load double*, double** %13
%26 = load i32, i32* %9
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
%29 = call i32 @probvec_tailsum(double* %25, i32 %26, i32 %28)
%30 = call double @exp(i32 %29)
%31 = load double*, double** %11
store double %30, double* %31
br label %44
32: ; preds = %6
%33 = load i32*, i32** %7
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = call double* @pruned_calc_prob_dist(i32* %33, i32 %34, i32 %35)
store double* %36, double** %13
%37 = load double*, double** %13
%38 = load i32, i32* %9
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
%41 = call i32 @probvec_tailsum(double* %37, i32 %38, i32 %40)
%42 = call double @exp(i32 %41)
%43 = load double*, double** %11
store double %42, double* %43
br label %44
44: ; preds = %32, %20
%45 = load double*, double** %13
%46 = icmp ne double* null, %45
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load double*, double** %13
%49 = call i32 @free(double* %48)
br label %50
50: ; preds = %47, %44
ret void
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
define void @snpcaller(i32* %0, i32 %1, i32 %2, i32 %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = load double, double* @DBL_MAX
store double %7, double* %4
%8 = load double, double* @DBL_MAX
store double %8, double* %5
%9 = icmp eq i32 %3, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call double* @naive_calc_prob_dist(i32* %0, i32 %1, i32 %2)
br label %14
12: ; preds = %6
%13 = tail call double* @pruned_calc_prob_dist(i32* %0, i32 %1, i32 %2)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %2, %12 ], [ %1, %10 ]
%16 = phi double* [ %13, %12 ], [ %11, %10 ]
%17 = add nsw i32 %15, 1
%18 = tail call i32 @probvec_tailsum(double* %16, i32 %2, i32 %17)
%19 = tail call double @exp(i32 %18)
store double %19, double* %4
%20 = icmp eq double* %16, null
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = tail call i32 @free(double* %16)
br label %23
23: ; preds = %21, %14
ret void
}