#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(double *);
double kahan_accum(double, double *, double const);
double *malloc(int);
int /*<<< orphan*/ stderr;
int emission_expectations_nodisk(int nstates, int nalpha, int nobs,
                                 double *expectations,
                                 const unsigned char *v_big,
                                 const double *d_big) {
  int errcode = 0;
  int i;
  double *compensations = malloc(nstates * nalpha * sizeof(double));
  for (i = 0; i < nstates * nalpha; ++i) {
    compensations[i] = 0.0;
  }
  unsigned char emission;
  int obs_index;
  int expectations_index;
  int posterior_index;
  for (obs_index = 0; obs_index < nobs; ++obs_index) {
    emission = v_big[obs_index];
    if (emission == 127) {
      continue;
    }
    if (emission >= nalpha) {
      fprintf(stderr, "an observation is out of range\n");
      errcode = -1;
      goto end;
    }
    for (i = 0; i < nstates; ++i) {
      expectations_index = i * nalpha + emission;
      posterior_index = obs_index * nstates + i;
      expectations[expectations_index] = kahan_accum(
          expectations[expectations_index], compensations + expectations_index,
          d_big[posterior_index]);
    }
  }
end:
  free(compensations);
  return errcode;
}


x86 assembly (clang, -O0):
<emission_expectations_nodisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x4(%rbp),%ecx
imul   -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    11b3 <emission_expectations_nodisk+0x73>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1183 <emission_expectations_nodisk+0x43>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a0 <emission_expectations_nodisk+0x160>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
movzbl -0x39(%rbp),%eax
cmp    $0x7f,%eax
jne    11e6 <emission_expectations_nodisk+0xa6>
jmp    1292 <emission_expectations_nodisk+0x152>
movzbl -0x39(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1214 <emission_expectations_nodisk+0xd4>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    12a5 <emission_expectations_nodisk+0x165>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    128d <emission_expectations_nodisk+0x14d>
mov    -0x30(%rbp),%eax
imul   -0x8(%rbp),%eax
movzbl -0x39(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
imul   -0x4(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rdi
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1040 <kahan_accum@plt>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    121b <emission_expectations_nodisk+0xdb>
jmp    1292 <emission_expectations_nodisk+0x152>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11ba <emission_expectations_nodisk+0x7a>
jmp    12a5 <emission_expectations_nodisk+0x165>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emission_expectations_nodisk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%rbx
mov    %r8,0x20(%rsp)
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,0x4(%rsp)
mov    %esi,%ebp
mov    %edi,(%rsp)
imul   %edi,%ebp
lea    0x0(,%rbp,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    119b <emission_expectations_nodisk+0x4b>
mov    %ebp,%edx
shl    $0x3,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
test   %r12d,%r12d
jle    1257 <emission_expectations_nodisk+0x107>
mov    %r14,0x8(%rsp)
movslq 0x4(%rsp),%rcx
movslq (%rsp),%rax
mov    %r12d,%edx
mov    %rdx,0x10(%rsp)
mov    %eax,%r12d
shl    $0x3,%rax
mov    %rax,0x18(%rsp)
shl    $0x3,%rcx
xor    %esi,%esi
mov    %r15,0x30(%rsp)
mov    0x8(%rsp),%r13
jmp    11f5 <emission_expectations_nodisk+0xa5>
nopl   0x0(%rax,%rax,1)
mov    0x28(%rsp),%rsi
add    $0x1,%rsi
add    0x18(%rsp),%rbx
cmp    0x10(%rsp),%rsi
je     1253 <emission_expectations_nodisk+0x103>
mov    0x20(%rsp),%rax
mov    %rsi,0x28(%rsp)
movzbl (%rax,%rsi,1),%eax
cmp    $0x7f,%eax
je     11e0 <emission_expectations_nodisk+0x90>
cmp    0x4(%rsp),%eax
jge    125b <emission_expectations_nodisk+0x10b>
cmpl   $0x0,(%rsp)
jle    11e0 <emission_expectations_nodisk+0x90>
mov    %eax,%r14d
shl    $0x3,%r14
xor    %ebp,%ebp
nopl   (%rax)
movsd  (%r15,%r14,1),%xmm0
lea    (%r14,%r13,1),%rdi
movsd  (%rbx,%rbp,8),%xmm1
mov    %rcx,%r15
call   1040 <kahan_accum@plt>
mov    %r15,%rcx
mov    0x30(%rsp),%r15
movsd  %xmm0,(%r15,%r14,1)
add    $0x1,%rbp
add    %rcx,%r14
cmp    %rbp,%r12
jne    1220 <emission_expectations_nodisk+0xd0>
jmp    11e0 <emission_expectations_nodisk+0x90>
xor    %ebx,%ebx
jmp    1275 <emission_expectations_nodisk+0x125>
xor    %ebx,%ebx
jmp    127a <emission_expectations_nodisk+0x12a>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    0x8(%rsp),%r14
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"an observation is out of range\0A\00"
define i32 @emission_expectations_nodisk(i32 %0, i32 %1, i32 %2, double* %3, i8* %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i8*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
%16 = alloca i8
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store i8* %4, i8** %11
store double* %5, double** %12
store i32 0, i32* %13
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = mul nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call double* @malloc(i32 %25)
store double* %26, double** %15
store i32 0, i32* %14
br label %27
27: ; preds = %38, %6
%28 = load i32, i32* %14
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = mul nsw i32 %29, %30
%32 = icmp slt i32 %28, %31
br i1 %32, label %33, label %41
33: ; preds = %27
%34 = load double*, double** %15
%35 = load i32, i32* %14
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double 0.000000e+00, double* %37
br label %38
38: ; preds = %33
%39 = load i32, i32* %14
%40 = add nsw i32 %39, 1
store i32 %40, i32* %14
br label %27
41: ; preds = %27
store i32 0, i32* %17
br label %42
42: ; preds = %104, %41
%43 = load i32, i32* %17
%44 = load i32, i32* %9
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %107
46: ; preds = %42
%47 = load i8*, i8** %11
%48 = load i32, i32* %17
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
store i8 %51, i8* %16
%52 = load i8, i8* %16
%53 = zext i8 %52 to i32
%54 = icmp eq i32 %53, 127
br i1 %54, label %55, label %56
55: ; preds = %46
br label %104
56: ; preds = %46
%57 = load i8, i8* %16
%58 = zext i8 %57 to i32
%59 = load i32, i32* %8
%60 = icmp sge i32 %58, %59
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %13
br label %108
64: ; preds = %56
store i32 0, i32* %14
br label %65
65: ; preds = %100, %64
%66 = load i32, i32* %14
%67 = load i32, i32* %7
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %103
69: ; preds = %65
%70 = load i32, i32* %14
%71 = load i32, i32* %8
%72 = mul nsw i32 %70, %71
%73 = load i8, i8* %16
%74 = zext i8 %73 to i32
%75 = add nsw i32 %72, %74
store i32 %75, i32* %18
%76 = load i32, i32* %17
%77 = load i32, i32* %7
%78 = mul nsw i32 %76, %77
%79 = load i32, i32* %14
%80 = add nsw i32 %78, %79
store i32 %80, i32* %19
%81 = load double*, double** %10
%82 = load i32, i32* %18
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %81, i64 %83
%85 = load double, double* %84
%86 = load double*, double** %15
%87 = load i32, i32* %18
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %86, i64 %88
%90 = load double*, double** %12
%91 = load i32, i32* %19
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = call double @kahan_accum(double %85, double* %89, double %94)
%96 = load double*, double** %10
%97 = load i32, i32* %18
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
store double %95, double* %99
br label %100
100: ; preds = %69
%101 = load i32, i32* %14
%102 = add nsw i32 %101, 1
store i32 %102, i32* %14
br label %65
103: ; preds = %65
br label %104
104: ; preds = %103, %55
%105 = load i32, i32* %17
%106 = add nsw i32 %105, 1
store i32 %106, i32* %17
br label %42
107: ; preds = %42
br label %108
108: ; preds = %107, %61
%109 = load double*, double** %15
%110 = call i32 @free(double* %109)
%111 = load i32, i32* %13
ret i32 %111
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"an observation is out of range\0A\00"
define i32 @emission_expectations_nodisk(i32 %0, i32 %1, i32 %2, double* nocapture %3, i8* nocapture %4, double* nocapture %5) {
%7 = mul nsw i32 %1, %0
%8 = shl i32 %7, 3
%9 = tail call double* @malloc(i32 %8)
%10 = icmp sgt i32 %7, 0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = bitcast double* %9 to i8*
%13 = zext i32 %7 to i64
%14 = shl nuw nsw i64 %13, 3
br label %15
15: ; preds = %11, %6
%16 = icmp sgt i32 %2, 0
br i1 %16, label %17, label %54
17: ; preds = %15
%18 = icmp sgt i32 %0, 0
%19 = sext i32 %1 to i64
%20 = sext i32 %0 to i64
%21 = zext i32 %2 to i64
%22 = zext i32 %0 to i64
br label %23
23: ; preds = %17, %51
%24 = phi i64 [ 0, %17 ], [ %52, %51 ]
%25 = getelementptr inbounds i8, i8* %4, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 127
br i1 %27, label %51, label %28
28: ; preds = %23
%29 = zext i8 %26 to i32
%30 = icmp slt i32 %29, %1
br i1 %30, label %31, label %35
31: ; preds = %28
br i1 %18, label %32, label %51
32: ; preds = %31
%33 = mul nsw i64 %24, %20
%34 = zext i8 %26 to i64
br label %38
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %54
38: ; preds = %32, %38
%39 = phi i64 [ 0, %32 ], [ %49, %38 ]
%40 = mul nsw i64 %39, %19
%41 = add nsw i64 %40, %34
%42 = add nsw i64 %39, %33
%43 = getelementptr inbounds double, double* %3, i64 %41
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %9, i64 %41
%46 = getelementptr inbounds double, double* %5, i64 %42
%47 = load double, double* %46
%48 = tail call double @kahan_accum(double %44, double* %45, double %47)
store double %48, double* %43
%49 = add nuw nsw i64 %39, 1
%50 = icmp eq i64 %49, %22
br i1 %50, label %51, label %38
51: ; preds = %38, %31, %23
%52 = add nuw nsw i64 %24, 1
%53 = icmp eq i64 %52, %21
br i1 %53, label %54, label %23
54: ; preds = %51, %15, %35
%55 = phi i32 [ -1, %35 ], [ 0, %15 ], [ 0, %51 ]
%56 = tail call i32 @free(double* %9)
ret i32 %55
}