#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 /*<<< orphan*/ free(double *);
double kahan_accum(double, double *, double);
double *malloc(int);
int transition_expectations_nodisk(int nstates, int nobs, const double *trans,
                                   double *expectations, const double *l_big,
                                   const double *f_big, const double *b_big) {
  int i;
  double *compensations = malloc(nstates * nstates * sizeof(double));
  for (i = 0; i < nstates * nstates; ++i) {
    compensations[i] = 0.0;
  }
  const double *f_prev = f_big;
  const double *l_curr = l_big + nstates;
  const double *b_curr = b_big + nstates * (nobs - 2);
  int source, sink;
  int index;
  double x;
  for (i = 0; i < nobs - 1; i++) {
    for (source = 0; source < nstates; ++source) {
      for (sink = 0; sink < nstates; ++sink) {
        index = source * nstates + sink;
        x = f_prev[source] * trans[index] * l_curr[sink] * b_curr[sink];
        expectations[index] =
            kahan_accum(expectations[index], compensations + index, x);
      }
    }
    f_prev += nstates;
    l_curr += nstates;
    b_curr -= nstates;
  }
  free(compensations);
  return 0;
}


x86 assembly (clang, -O0):
<transition_expectations_nodisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x4(%rbp),%ecx
imul   -0x4(%rbp),%ecx
cmp    %ecx,%eax
jge    11a1 <transition_expectations_nodisk+0x71>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1171 <transition_expectations_nodisk+0x41>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%edx
sub    $0x2,%edx
imul   %edx,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1304 <transition_expectations_nodisk+0x1d4>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12b2 <transition_expectations_nodisk+0x182>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    129f <transition_expectations_nodisk+0x16f>
mov    -0x54(%rbp),%eax
imul   -0x4(%rbp),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x50(%rbp),%rax
movslq -0x58(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rdi
movslq -0x5c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
movsd  -0x68(%rbp),%xmm1
call   1040 <kahan_accum@plt>
mov    -0x18(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    120c <transition_expectations_nodisk+0xdc>
jmp    12a4 <transition_expectations_nodisk+0x174>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f9 <transition_expectations_nodisk+0xc9>
mov    -0x4(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e1 <transition_expectations_nodisk+0xb1>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transition_expectations_nodisk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,%r14
mov    %r8,%r12
mov    %rcx,0x28(%rsp)
mov    %rdx,0x20(%rsp)
mov    %esi,%ebp
mov    %edi,0x8(%rsp)
mov    %edi,%ebx
imul   %ebx,%ebx
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
je     118c <transition_expectations_nodisk+0x4c>
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r15,0x10(%rsp)
cmp    $0x2,%ebp
jl     12db <transition_expectations_nodisk+0x19b>
mov    0xa0(%rsp),%rax
mov    0x8(%rsp),%esi
movslq %esi,%rdi
lea    -0x1(%rbp),%ecx
mov    %ecx,0xc(%rsp)
add    $0xfffffffe,%ebp
imul   %esi,%ebp
movslq %ebp,%rcx
lea    (%rax,%rcx,8),%rbx
mov    %esi,%eax
lea    0x0(,%rdi,8),%rsi
mov    %rsi,0x18(%rsp)
neg    %rsi
mov    %rsi,0x30(%rsp)
mov    %rdi,0x38(%rsp)
lea    (%r12,%rdi,8),%rbp
mov    %rax,0x48(%rsp)
lea    0x0(,%rax,8),%rdi
xor    %eax,%eax
mov    %rdi,0x50(%rsp)
jmp    1225 <transition_expectations_nodisk+0xe5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x38(%rsp),%rax
lea    (%r14,%rax,8),%r14
mov    0x40(%rsp),%rax
add    $0x1,%eax
add    0x30(%rsp),%rbx
add    0x18(%rsp),%rbp
cmp    0xc(%rsp),%eax
je     12db <transition_expectations_nodisk+0x19b>
mov    %rax,0x40(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    1200 <transition_expectations_nodisk+0xc0>
mov    0x10(%rsp),%r13
mov    0x28(%rsp),%rdx
mov    0x20(%rsp),%rcx
xor    %esi,%esi
mov    %rbp,0x58(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %r15d,%r15d
mov    %rsi,0x60(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  (%r14,%rsi,8),%xmm1
mulsd  (%rcx,%r15,1),%xmm1
mulsd  0x0(%rbp,%r15,1),%xmm1
mulsd  (%rbx,%r15,1),%xmm1
movsd  (%rdx,%r15,1),%xmm0
lea    0x0(%r13,%r15,1),%rdi
mov    %rbx,%r12
mov    %rdx,%rbp
mov    %rcx,%rbx
call   1040 <kahan_accum@plt>
mov    0x60(%rsp),%rsi
mov    %rbx,%rcx
mov    %rbp,%rdx
mov    0x50(%rsp),%rdi
mov    0x58(%rsp),%rbp
mov    %r12,%rbx
movsd  %xmm0,(%rdx,%r15,1)
add    $0x8,%r15
cmp    %r15,%rdi
jne    1260 <transition_expectations_nodisk+0x120>
add    $0x1,%rsi
mov    0x18(%rsp),%r8
add    %r8,%rcx
add    %r8,%rdx
add    %r8,%r13
cmp    0x48(%rsp),%rsi
jne    1250 <transition_expectations_nodisk+0x110>
jmp    1200 <transition_expectations_nodisk+0xc0>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @transition_expectations_nodisk(i32 %0, i32 %1, double* %2, double* %3, double* %4, double* %5, double* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca double*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca double
store i32 %0, i32* %8
store i32 %1, i32* %9
store double* %2, double** %10
store double* %3, double** %11
store double* %4, double** %12
store double* %5, double** %13
store double* %6, double** %14
%24 = load i32, i32* %8
%25 = load i32, i32* %8
%26 = mul nsw i32 %24, %25
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 8
%29 = trunc i64 %28 to i32
%30 = call double* @malloc(i32 %29)
store double* %30, double** %16
store i32 0, i32* %15
br label %31
31: ; preds = %42, %7
%32 = load i32, i32* %15
%33 = load i32, i32* %8
%34 = load i32, i32* %8
%35 = mul nsw i32 %33, %34
%36 = icmp slt i32 %32, %35
br i1 %36, label %37, label %45
37: ; preds = %31
%38 = load double*, double** %16
%39 = load i32, i32* %15
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
store double 0.000000e+00, double* %41
br label %42
42: ; preds = %37
%43 = load i32, i32* %15
%44 = add nsw i32 %43, 1
store i32 %44, i32* %15
br label %31
45: ; preds = %31
%46 = load double*, double** %13
store double* %46, double** %17
%47 = load double*, double** %12
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
store double* %50, double** %18
%51 = load double*, double** %14
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = sub nsw i32 %53, 2
%55 = mul nsw i32 %52, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %51, i64 %56
store double* %57, double** %19
store i32 0, i32* %15
br label %58
58: ; preds = %138, %45
%59 = load i32, i32* %15
%60 = load i32, i32* %9
%61 = sub nsw i32 %60, 1
%62 = icmp slt i32 %59, %61
br i1 %62, label %63, label %141
63: ; preds = %58
store i32 0, i32* %20
br label %64
64: ; preds = %121, %63
%65 = load i32, i32* %20
%66 = load i32, i32* %8
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %124
68: ; preds = %64
store i32 0, i32* %21
br label %69
69: ; preds = %117, %68
%70 = load i32, i32* %21
%71 = load i32, i32* %8
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %120
73: ; preds = %69
%74 = load i32, i32* %20
%75 = load i32, i32* %8
%76 = mul nsw i32 %74, %75
%77 = load i32, i32* %21
%78 = add nsw i32 %76, %77
store i32 %78, i32* %22
%79 = load double*, double** %17
%80 = load i32, i32* %20
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %79, i64 %81
%83 = load double, double* %82
%84 = load double*, double** %10
%85 = load i32, i32* %22
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
%88 = load double, double* %87
%89 = fmul double %83, %88
%90 = load double*, double** %18
%91 = load i32, i32* %21
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = fmul double %89, %94
%96 = load double*, double** %19
%97 = load i32, i32* %21
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = fmul double %95, %100
store double %101, double* %23
%102 = load double*, double** %11
%103 = load i32, i32* %22
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %102, i64 %104
%106 = load double, double* %105
%107 = load double*, double** %16
%108 = load i32, i32* %22
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %23
%112 = call double @kahan_accum(double %106, double* %110, double %111)
%113 = load double*, double** %11
%114 = load i32, i32* %22
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds double, double* %113, i64 %115
store double %112, double* %116
br label %117
117: ; preds = %73
%118 = load i32, i32* %21
%119 = add nsw i32 %118, 1
store i32 %119, i32* %21
br label %69
120: ; preds = %69
br label %121
121: ; preds = %120
%122 = load i32, i32* %20
%123 = add nsw i32 %122, 1
store i32 %123, i32* %20
br label %64
124: ; preds = %64
%125 = load i32, i32* %8
%126 = load double*, double** %17
%127 = sext i32 %125 to i64
%128 = getelementptr inbounds double, double* %126, i64 %127
store double* %128, double** %17
%129 = load i32, i32* %8
%130 = load double*, double** %18
%131 = sext i32 %129 to i64
%132 = getelementptr inbounds double, double* %130, i64 %131
store double* %132, double** %18
%133 = load i32, i32* %8
%134 = load double*, double** %19
%135 = sext i32 %133 to i64
%136 = sub i64 0, %135
%137 = getelementptr inbounds double, double* %134, i64 %136
store double* %137, double** %19
br label %138
138: ; preds = %124
%139 = load i32, i32* %15
%140 = add nsw i32 %139, 1
store i32 %140, i32* %15
br label %58
141: ; preds = %58
%142 = load double*, double** %16
%143 = call i32 @free(double* %142)
ret i32 0
}

LLVM IR (-O2):
define i32 @transition_expectations_nodisk(i32 %0, i32 %1, double* nocapture %2, double* nocapture %3, double* nocapture %4, double* nocapture %5, double* nocapture %6) {
%8 = mul nsw i32 %0, %0
%9 = shl i32 %8, 3
%10 = tail call double* @malloc(i32 %9)
%11 = icmp eq i32 %8, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = bitcast double* %10 to i8*
%14 = zext i32 %8 to i64
%15 = shl nuw nsw i64 %14, 3
br label %16
16: ; preds = %12, %7
%17 = sext i32 %0 to i64
%18 = add i32 %1, -1
%19 = icmp sgt i32 %1, 1
br i1 %19, label %20, label %65
20: ; preds = %16
%21 = add nsw i32 %1, -2
%22 = mul nsw i32 %21, %0
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %6, i64 %23
%25 = icmp sgt i32 %0, 0
%26 = sub nsw i64 0, %17
%27 = zext i32 %0 to i64
br label %28
28: ; preds = %20, %60
%29 = phi double* [ %4, %20 ], [ %33, %60 ]
%30 = phi i32 [ 0, %20 ], [ %63, %60 ]
%31 = phi double* [ %5, %20 ], [ %61, %60 ]
%32 = phi double* [ %24, %20 ], [ %62, %60 ]
%33 = getelementptr inbounds double, double* %29, i64 %17
br i1 %25, label %34, label %60
34: ; preds = %28, %57
%35 = phi i64 [ %58, %57 ], [ 0, %28 ]
%36 = mul nsw i64 %35, %17
%37 = getelementptr inbounds double, double* %31, i64 %35
br label %38
38: ; preds = %34, %38
%39 = phi i64 [ 0, %34 ], [ %55, %38 ]
%40 = add nsw i64 %39, %36
%41 = load double, double* %37
%42 = getelementptr inbounds double, double* %2, i64 %40
%43 = load double, double* %42
%44 = fmul double %41, %43
%45 = getelementptr inbounds double, double* %33, i64 %39
%46 = load double, double* %45
%47 = fmul double %44, %46
%48 = getelementptr inbounds double, double* %32, i64 %39
%49 = load double, double* %48
%50 = fmul double %47, %49
%51 = getelementptr inbounds double, double* %3, i64 %40
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %10, i64 %40
%54 = tail call double @kahan_accum(double %52, double* %53, double %50)
store double %54, double* %51
%55 = add nuw nsw i64 %39, 1
%56 = icmp eq i64 %55, %27
br i1 %56, label %57, label %38
57: ; preds = %38
%58 = add nuw nsw i64 %35, 1
%59 = icmp eq i64 %58, %27
br i1 %59, label %60, label %34
60: ; preds = %57, %28
%61 = getelementptr inbounds double, double* %31, i64 %17
%62 = getelementptr inbounds double, double* %32, i64 %26
%63 = add nuw nsw i32 %30, 1
%64 = icmp eq i32 %63, %18
br i1 %64, label %65, label %28
65: ; preds = %60, %16
%66 = tail call i32 @free(double* %10)
ret i32 0
}