#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 sum_loglikely_vector(double *, int);
void MatrixLikelihood(double smx[20][20], double *pri, double *ct, double *ll) {
  double term[20];
  int root, child;
  for (root = 0; root < 20; root++) {
    term[root] = log(pri[root]);
    for (child = 0; child < 20; child++)
      term[root] += ct[child] * smx[root][child];
  }
  *ll = sum_loglikely_vector(term, 20);
}


x86 assembly (clang, -O0):
<MatrixLikelihood>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0xc4(%rbp)
cmpl   $0x14,-0xc4(%rbp)
jge    120d <MatrixLikelihood+0xed>
mov    -0x10(%rbp),%rax
movslq -0xc4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <log@plt>
movslq -0xc4(%rbp),%rax
movsd  %xmm0,-0xc0(%rbp,%rax,8)
ff ff
movl   $0x0,-0xc8(%rbp)
cmpl   $0x14,-0xc8(%rbp)
jge    11f4 <MatrixLikelihood+0xd4>
mov    -0x18(%rbp),%rax
movslq -0xc8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc4(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0xc8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movslq -0xc4(%rbp),%rax
movsd  -0xc0(%rbp,%rax,8),%xmm1
ff ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xc0(%rbp,%rax,8)
ff ff
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    1181 <MatrixLikelihood+0x61>
jmp    11f9 <MatrixLikelihood+0xd9>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1145 <MatrixLikelihood+0x25>
lea    -0xc0(%rbp),%rdi
mov    $0x14,%esi
call   1030 <sum_loglikely_vector@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MatrixLikelihood>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
add    $0x98,%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
movsd  (%r15,%r13,8),%xmm0
call   1040 <log@plt>
movsd  (%r12),%xmm1
mulsd  -0x98(%rbx),%xmm1
ff
movsd  0x8(%r12),%xmm2
addsd  %xmm0,%xmm1
mulsd  -0x90(%rbx),%xmm2
ff
addsd  %xmm1,%xmm2
movsd  0x10(%r12),%xmm0
mulsd  -0x88(%rbx),%xmm0
ff
addsd  %xmm2,%xmm0
movsd  0x18(%r12),%xmm1
mulsd  -0x80(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x20(%r12),%xmm0
mulsd  -0x78(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x28(%r12),%xmm1
mulsd  -0x70(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x30(%r12),%xmm0
mulsd  -0x68(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x38(%r12),%xmm1
mulsd  -0x60(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x40(%r12),%xmm0
mulsd  -0x58(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x48(%r12),%xmm1
mulsd  -0x50(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x50(%r12),%xmm0
mulsd  -0x48(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x58(%r12),%xmm1
mulsd  -0x40(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x60(%r12),%xmm0
mulsd  -0x38(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x68(%r12),%xmm1
mulsd  -0x30(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x70(%r12),%xmm0
mulsd  -0x28(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x78(%r12),%xmm1
mulsd  -0x20(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x80(%r12),%xmm0
mulsd  -0x18(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x88(%r12),%xmm1
mulsd  -0x10(%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  0x90(%r12),%xmm0
mulsd  -0x8(%rbx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x98(%r12),%xmm1
mulsd  (%rbx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp,%r13,8)
add    $0x1,%r13
add    $0xa0,%rbx
cmp    $0x14,%r13
jne    1150 <MatrixLikelihood+0x30>
mov    %rsp,%rdi
mov    $0x14,%esi
call   1030 <sum_loglikely_vector@plt>
movsd  %xmm0,(%r14)
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @MatrixLikelihood([20 x double]* %0, double* %1, double* %2, double* %3) {
%5 = alloca [20 x double]*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca [20 x double]
%10 = alloca i32
%11 = alloca i32
store [20 x double]* %0, [20 x double]** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
store i32 0, i32* %10
br label %12
12: ; preds = %51, %4
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 20
br i1 %14, label %15, label %54
15: ; preds = %12
%16 = load double*, double** %6
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = call double @log(double %20)
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20 x double], [20 x double]* %9, i64 0, i64 %23
store double %21, double* %24
store i32 0, i32* %11
br label %25
25: ; preds = %47, %15
%26 = load i32, i32* %11
%27 = icmp slt i32 %26, 20
br i1 %27, label %28, label %50
28: ; preds = %25
%29 = load double*, double** %7
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load [20 x double]*, [20 x double]** %5
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [20 x double], [20 x double]* %34, i64 %36
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [20 x double], [20 x double]* %37, i64 0, i64 %39
%41 = load double, double* %40
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [20 x double], [20 x double]* %9, i64 0, i64 %43
%45 = load double, double* %44
%46 = call double @llvm.fmuladd.f64(double %33, double %41, double %45)
store double %46, double* %44
br label %47
47: ; preds = %28
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %25
50: ; preds = %25
br label %51
51: ; preds = %50
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %12
54: ; preds = %12
%55 = getelementptr inbounds [20 x double], [20 x double]* %9, i64 0, i64 0
%56 = call double @sum_loglikely_vector(double* %55, i32 20)
%57 = load double*, double** %8
store double %56, double* %57
ret void
}

LLVM IR (-O2):
define void @MatrixLikelihood([20 x double]* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture writeonly %3) {
%5 = alloca [20 x double]
%6 = bitcast [20 x double]* %5 to i8*
%7 = getelementptr inbounds double, double* %2, i64 1
%8 = getelementptr inbounds double, double* %2, i64 2
%9 = getelementptr inbounds double, double* %2, i64 3
%10 = getelementptr inbounds double, double* %2, i64 4
%11 = getelementptr inbounds double, double* %2, i64 5
%12 = getelementptr inbounds double, double* %2, i64 6
%13 = getelementptr inbounds double, double* %2, i64 7
%14 = getelementptr inbounds double, double* %2, i64 8
%15 = getelementptr inbounds double, double* %2, i64 9
%16 = getelementptr inbounds double, double* %2, i64 10
%17 = getelementptr inbounds double, double* %2, i64 11
%18 = getelementptr inbounds double, double* %2, i64 12
%19 = getelementptr inbounds double, double* %2, i64 13
%20 = getelementptr inbounds double, double* %2, i64 14
%21 = getelementptr inbounds double, double* %2, i64 15
%22 = getelementptr inbounds double, double* %2, i64 16
%23 = getelementptr inbounds double, double* %2, i64 17
%24 = getelementptr inbounds double, double* %2, i64 18
%25 = getelementptr inbounds double, double* %2, i64 19
br label %26
26: ; preds = %4, %26
%27 = phi i64 [ 0, %4 ], [ %112, %26 ]
%28 = getelementptr inbounds double, double* %1, i64 %27
%29 = load double, double* %28
%30 = tail call double @log(double %29)
%31 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 %27
%32 = load double, double* %2
%33 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 0
%34 = load double, double* %33
%35 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %30)
%36 = load double, double* %7
%37 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 1
%38 = load double, double* %37
%39 = tail call double @llvm.fmuladd.f64(double %36, double %38, double %35)
%40 = load double, double* %8
%41 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 2
%42 = load double, double* %41
%43 = tail call double @llvm.fmuladd.f64(double %40, double %42, double %39)
%44 = load double, double* %9
%45 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 3
%46 = load double, double* %45
%47 = tail call double @llvm.fmuladd.f64(double %44, double %46, double %43)
%48 = load double, double* %10
%49 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 4
%50 = load double, double* %49
%51 = tail call double @llvm.fmuladd.f64(double %48, double %50, double %47)
%52 = load double, double* %11
%53 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 5
%54 = load double, double* %53
%55 = tail call double @llvm.fmuladd.f64(double %52, double %54, double %51)
%56 = load double, double* %12
%57 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 6
%58 = load double, double* %57
%59 = tail call double @llvm.fmuladd.f64(double %56, double %58, double %55)
%60 = load double, double* %13
%61 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 7
%62 = load double, double* %61
%63 = tail call double @llvm.fmuladd.f64(double %60, double %62, double %59)
%64 = load double, double* %14
%65 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 8
%66 = load double, double* %65
%67 = tail call double @llvm.fmuladd.f64(double %64, double %66, double %63)
%68 = load double, double* %15
%69 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 9
%70 = load double, double* %69
%71 = tail call double @llvm.fmuladd.f64(double %68, double %70, double %67)
%72 = load double, double* %16
%73 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 10
%74 = load double, double* %73
%75 = tail call double @llvm.fmuladd.f64(double %72, double %74, double %71)
%76 = load double, double* %17
%77 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 11
%78 = load double, double* %77
%79 = tail call double @llvm.fmuladd.f64(double %76, double %78, double %75)
%80 = load double, double* %18
%81 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 12
%82 = load double, double* %81
%83 = tail call double @llvm.fmuladd.f64(double %80, double %82, double %79)
%84 = load double, double* %19
%85 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 13
%86 = load double, double* %85
%87 = tail call double @llvm.fmuladd.f64(double %84, double %86, double %83)
%88 = load double, double* %20
%89 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 14
%90 = load double, double* %89
%91 = tail call double @llvm.fmuladd.f64(double %88, double %90, double %87)
%92 = load double, double* %21
%93 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 15
%94 = load double, double* %93
%95 = tail call double @llvm.fmuladd.f64(double %92, double %94, double %91)
%96 = load double, double* %22
%97 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 16
%98 = load double, double* %97
%99 = tail call double @llvm.fmuladd.f64(double %96, double %98, double %95)
%100 = load double, double* %23
%101 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 17
%102 = load double, double* %101
%103 = tail call double @llvm.fmuladd.f64(double %100, double %102, double %99)
%104 = load double, double* %24
%105 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 18
%106 = load double, double* %105
%107 = tail call double @llvm.fmuladd.f64(double %104, double %106, double %103)
%108 = load double, double* %25
%109 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %27, i64 19
%110 = load double, double* %109
%111 = tail call double @llvm.fmuladd.f64(double %108, double %110, double %107)
store double %111, double* %31
%112 = add nuw nsw i64 %27, 1
%113 = icmp eq i64 %112, 20
br i1 %113, label %114, label %26
114: ; preds = %26
%115 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 0
%116 = call double @sum_loglikely_vector(double* %115, i32 20)
store double %116, double* %3
ret void
}