#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 log(double);
double log1p(double);
double pow(double, double);
void genotype_likelihood(const int *phred_quals, const int num_phred_quals,
                         const int num_alt_phred_quals, double *ref_hom,
                         double *alt_hom, double *het) {
  int i;
  double pn;
  double log_pn;
  double log_1_pn;
  *ref_hom = 0;
  *alt_hom = 0;
  *het = 0;
  for (i = 0; i < num_phred_quals - num_alt_phred_quals; i++) {
    pn = (pow(10.0, -1.0 * (phred_quals[i]) / 10.0));
    log_pn = log(pn);
    log_1_pn = log1p(-pn);
    *ref_hom = *ref_hom + log_1_pn;
    *alt_hom = *alt_hom + log_pn;
    *het = *het + log(0.5);
  }
  for (i = num_phred_quals - num_alt_phred_quals; i < num_phred_quals; i++) {
    pn = (pow(10.0, -1.0 * (phred_quals[i]) / 10.0));
    log_pn = log(pn);
    log_1_pn = log1p(-pn);
    *ref_hom = *ref_hom + log_pn;
    *alt_hom = *alt_hom + log_1_pn;
    *het = *het + log(0.5);
  }
}


x86 assembly (clang, -O0):
<genotype_likelihood>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    1259 <genotype_likelihood+0x129>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  0xe74(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe60(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe54(%rip),%xmm0
call   1040 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <log1p@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xdce(%rip),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1176 <genotype_likelihood+0x46>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1340 <genotype_likelihood+0x210>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  0xd8d(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xd79(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd6d(%rip),%xmm0
call   1040 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <log1p@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xce7(%rip),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1262 <genotype_likelihood+0x132>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genotype_likelihood>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdi,%r12
movq   $0x0,(%rcx)
movq   $0x0,(%r8)
movq   $0x0,(%r9)
mov    %esi,0x18(%rsp)
mov    %edx,0x1c(%rsp)
sub    %edx,%esi
mov    %esi,0xc(%rsp)
test   %esi,%esi
jle    11f4 <genotype_likelihood+0xc4>
mov    0xc(%rsp),%ebp
xor    %r13d,%r13d
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2sdl (%r12,%r13,4),%xmm1
divsd  0xe6f(%rip),%xmm1
movsd  0xe6f(%rip),%xmm0
call   1040 <pow@plt>
movaps %xmm0,0x20(%rsp)
call   1030 <log@plt>
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
xorpd  0xe64(%rip),%xmm0
call   1050 <log1p@plt>
addsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
movsd  0x10(%rsp),%xmm0
addsd  (%r15),%xmm0
movsd  %xmm0,(%r15)
movsd  (%r14),%xmm0
addsd  0xe2a(%rip),%xmm0
movsd  %xmm0,(%r14)
add    $0x1,%r13
cmp    %r13,%rbp
jne    1180 <genotype_likelihood+0x50>
cmpl   $0x0,0x1c(%rsp)
jle    1284 <genotype_likelihood+0x154>
movslq 0xc(%rsp),%rbp
movslq 0x18(%rsp),%r13
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2sdl (%r12,%rbp,4),%xmm1
divsd  0xddf(%rip),%xmm1
movsd  0xddf(%rip),%xmm0
call   1040 <pow@plt>
movaps %xmm0,0x20(%rsp)
call   1030 <log@plt>
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
xorpd  0xdd4(%rip),%xmm0
call   1050 <log1p@plt>
movsd  0x10(%rsp),%xmm1
addsd  (%rbx),%xmm1
movsd  %xmm1,(%rbx)
addsd  (%r15),%xmm0
movsd  %xmm0,(%r15)
movsd  (%r14),%xmm0
addsd  0xd9a(%rip),%xmm0
movsd  %xmm0,(%r14)
add    $0x1,%rbp
cmp    %r13,%rbp
jl     1210 <genotype_likelihood+0xe0>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @genotype_likelihood(i32* %0, i32 %1, i32 %2, double* %3, double* %4, double* %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
%17 = load double*, double** %10
store double 0.000000e+00, double* %17
%18 = load double*, double** %11
store double 0.000000e+00, double* %18
%19 = load double*, double** %12
store double 0.000000e+00, double* %19
store i32 0, i32* %13
br label %20
20: ; preds = %56, %6
%21 = load i32, i32* %13
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = sub nsw i32 %22, %23
%25 = icmp slt i32 %21, %24
br i1 %25, label %26, label %59
26: ; preds = %20
%27 = load i32*, i32** %7
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = sitofp i32 %31 to double
%33 = fmul double -1.000000e+00, %32
%34 = fdiv double %33, 1.000000e+01
%35 = call double @pow(double 1.000000e+01, double %34)
store double %35, double* %14
%36 = load double, double* %14
%37 = call double @log(double %36)
store double %37, double* %15
%38 = load double, double* %14
%39 = fneg double %38
%40 = call double @log1p(double %39)
store double %40, double* %16
%41 = load double*, double** %10
%42 = load double, double* %41
%43 = load double, double* %16
%44 = fadd double %42, %43
%45 = load double*, double** %10
store double %44, double* %45
%46 = load double*, double** %11
%47 = load double, double* %46
%48 = load double, double* %15
%49 = fadd double %47, %48
%50 = load double*, double** %11
store double %49, double* %50
%51 = load double*, double** %12
%52 = load double, double* %51
%53 = call double @log(double 5.000000e-01)
%54 = fadd double %52, %53
%55 = load double*, double** %12
store double %54, double* %55
br label %56
56: ; preds = %26
%57 = load i32, i32* %13
%58 = add nsw i32 %57, 1
store i32 %58, i32* %13
br label %20
59: ; preds = %20
%60 = load i32, i32* %8
%61 = load i32, i32* %9
%62 = sub nsw i32 %60, %61
store i32 %62, i32* %13
br label %63
63: ; preds = %97, %59
%64 = load i32, i32* %13
%65 = load i32, i32* %8
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %100
67: ; preds = %63
%68 = load i32*, i32** %7
%69 = load i32, i32* %13
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
%72 = load i32, i32* %71
%73 = sitofp i32 %72 to double
%74 = fmul double -1.000000e+00, %73
%75 = fdiv double %74, 1.000000e+01
%76 = call double @pow(double 1.000000e+01, double %75)
store double %76, double* %14
%77 = load double, double* %14
%78 = call double @log(double %77)
store double %78, double* %15
%79 = load double, double* %14
%80 = fneg double %79
%81 = call double @log1p(double %80)
store double %81, double* %16
%82 = load double*, double** %10
%83 = load double, double* %82
%84 = load double, double* %15
%85 = fadd double %83, %84
%86 = load double*, double** %10
store double %85, double* %86
%87 = load double*, double** %11
%88 = load double, double* %87
%89 = load double, double* %16
%90 = fadd double %88, %89
%91 = load double*, double** %11
store double %90, double* %91
%92 = load double*, double** %12
%93 = load double, double* %92
%94 = call double @log(double 5.000000e-01)
%95 = fadd double %93, %94
%96 = load double*, double** %12
store double %95, double* %96
br label %97
97: ; preds = %67
%98 = load i32, i32* %13
%99 = add nsw i32 %98, 1
store i32 %99, i32* %13
br label %63
100: ; preds = %63
ret void
}

LLVM IR (-O2):
define void @genotype_likelihood(i32* nocapture %0, i32 %1, i32 %2, double* nocapture %3, double* nocapture %4, double* nocapture %5) {
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
%7 = sub i32 %1, %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %16
11: ; preds = %16, %6
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %52
13: ; preds = %11
%14 = sext i32 %7 to i64
%15 = sext i32 %1 to i64
br label %34
16: ; preds = %9, %16
%17 = phi i64 [ 0, %9 ], [ %32, %16 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, -1.000000e+01
%22 = tail call double @pow(double 1.000000e+01, double %21)
%23 = tail call double @log(double %22)
%24 = fneg double %22
%25 = tail call double @log1p(double %24)
%26 = load double, double* %3
%27 = fadd double %25, %26
store double %27, double* %3
%28 = load double, double* %4
%29 = fadd double %23, %28
store double %29, double* %4
%30 = load double, double* %5
%31 = fadd double %30, 0xBFE62E42FEFA39EF
store double %31, double* %5
%32 = add nuw nsw i64 %17, 1
%33 = icmp eq i64 %32, %10
br i1 %33, label %11, label %16
34: ; preds = %13, %34
%35 = phi i64 [ %14, %13 ], [ %50, %34 ]
%36 = getelementptr inbounds i32, i32* %0, i64 %35
%37 = load i32, i32* %36
%38 = sitofp i32 %37 to double
%39 = fdiv double %38, -1.000000e+01
%40 = tail call double @pow(double 1.000000e+01, double %39)
%41 = tail call double @log(double %40)
%42 = fneg double %40
%43 = tail call double @log1p(double %42)
%44 = load double, double* %3
%45 = fadd double %41, %44
store double %45, double* %3
%46 = load double, double* %4
%47 = fadd double %43, %46
store double %47, double* %4
%48 = load double, double* %5
%49 = fadd double %48, 0xBFE62E42FEFA39EF
store double %49, double* %5
%50 = add nsw i64 %35, 1
%51 = icmp slt i64 %50, %15
br i1 %51, label %34, label %52
52: ; preds = %34, %11
ret void
}