#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 */
int log(double);
extern double _dtram_get_loglikelihood(int *count_matrices,
                                       double *transition_matrices,
                                       int n_therm_states, int n_conf_states) {
  int i, n = n_therm_states * n_conf_states * n_conf_states;
  double sum = 0.0;
  for (i = 0; i < n; ++i) {
    if (count_matrices[i] > 0)
      sum += count_matrices[i] * log(transition_matrices[i]);
  }
  return sum;
}


x86 assembly (clang, -O0):
<_dtram_get_loglikelihood>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11aa <_dtram_get_loglikelihood+0x9a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    1197 <_dtram_get_loglikelihood+0x87>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <log@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    119c <_dtram_get_loglikelihood+0x8c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <_dtram_get_loglikelihood+0x33>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dtram_get_loglikelihood>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
imul   %ecx,%edx
imul   %ecx,%edx
test   %edx,%edx
jle    1184 <_dtram_get_loglikelihood+0x74>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1149 <_dtram_get_loglikelihood+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1187 <_dtram_get_loglikelihood+0x77>
mov    (%r15,%rbx,4),%ebp
test   %ebp,%ebp
jle    1140 <_dtram_get_loglikelihood+0x30>
movsd  %xmm0,0x8(%rsp)
movsd  (%r14,%rbx,8),%xmm0
call   1030 <log@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
jmp    1140 <_dtram_get_loglikelihood+0x30>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @_dtram_get_loglikelihood(i32* %0, double* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32* %0, i32** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = mul nsw i32 %12, %13
%15 = load i32, i32* %8
%16 = mul nsw i32 %14, %15
store i32 %16, i32* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %9
br label %17
17: ; preds = %45, %4
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = load i32*, i32** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %21
%29 = load i32*, i32** %5
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load double*, double** %6
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = call i32 @log(double %38)
%40 = mul nsw i32 %33, %39
%41 = sitofp i32 %40 to double
%42 = load double, double* %11
%43 = fadd double %42, %41
store double %43, double* %11
br label %44
44: ; preds = %28, %21
br label %45
45: ; preds = %44
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %17
48: ; preds = %17
%49 = load double, double* %11
ret double %49
}

LLVM IR (-O2):
define double @_dtram_get_loglikelihood(i32* nocapture %0, double* nocapture %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %3, %2
%6 = mul i32 %5, %3
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %4
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %23
%11 = phi i64 [ 0, %8 ], [ %25, %23 ]
%12 = phi double [ 0.000000e+00, %8 ], [ %24, %23 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %11
%14 = load i32, i32* %13
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = getelementptr inbounds double, double* %1, i64 %11
%18 = load double, double* %17
%19 = tail call i32 @log(double %18)
%20 = mul nsw i32 %19, %14
%21 = sitofp i32 %20 to double
%22 = fadd double %12, %21
br label %23
23: ; preds = %10, %16
%24 = phi double [ %22, %16 ], [ %12, %10 ]
%25 = add nuw nsw i64 %11, 1
%26 = icmp eq i64 %25, %9
br i1 %26, label %27, label %10
27: ; preds = %23, %4
%28 = phi double [ 0.000000e+00, %4 ], [ %24, %23 ]
ret double %28
}