#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(double const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int finite_alphabet_likelihoods_alldisk(int nstates, int nalpha,
                                        const double *emissions, FILE *fi_v,
                                        FILE *fo_l) {
  int errcode = 0;
  int i;
  int index;
  unsigned char emission;
  double one = 1.0;
  while (fread(&emission, sizeof(unsigned char), 1, fi_v)) {
    if (emission == 127) {
      for (i = 0; i < nstates; ++i) {
        fwrite(&one, sizeof(double), 1, fo_l);
      }
    } else {
      if (emission >= nalpha) {
        fprintf(stderr, "an observation is out of range\n");
        errcode = -1;
        goto end;
      }
      for (i = 0; i < nstates; ++i) {
        index = i * nalpha + emission;
        fwrite(emissions + index, sizeof(double), 1, fo_l);
      }
    }
  }
end:
  return errcode;
}


x86 assembly (clang, -O0):
<finite_alphabet_likelihoods_alldisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movsd  0xea7(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x2d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
je     1251 <finite_alphabet_likelihoods_alldisk+0x121>
movzbl -0x2d(%rbp),%eax
cmp    $0x7f,%eax
jne    11c6 <finite_alphabet_likelihoods_alldisk+0x96>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c1 <finite_alphabet_likelihoods_alldisk+0x91>
mov    -0x20(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1190 <finite_alphabet_likelihoods_alldisk+0x60>
jmp    124c <finite_alphabet_likelihoods_alldisk+0x11c>
movzbl -0x2d(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11f4 <finite_alphabet_likelihoods_alldisk+0xc4>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1256 <finite_alphabet_likelihoods_alldisk+0x126>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1247 <finite_alphabet_likelihoods_alldisk+0x117>
mov    -0x28(%rbp),%eax
imul   -0x8(%rbp),%eax
movzbl -0x2d(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11fb <finite_alphabet_likelihoods_alldisk+0xcb>
jmp    124c <finite_alphabet_likelihoods_alldisk+0x11c>
jmp    115e <finite_alphabet_likelihoods_alldisk+0x2e>
jmp    1256 <finite_alphabet_likelihoods_alldisk+0x126>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finite_alphabet_likelihoods_alldisk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%rbx
mov    %rdx,0x20(%rsp)
mov    %esi,%ebp
mov    %edi,%r14d
movabs $0x3ff0000000000000,%rax
mov    %rax,0x30(%rsp)
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rcx,0x28(%rsp)
call   1030 <fread@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     1261 <finite_alphabet_likelihoods_alldisk+0x131>
mov    %ebp,0x14(%rsp)
movslq %ebp,%r15
mov    %r14d,%eax
mov    %rax,0x18(%rsp)
shl    $0x3,%r15
lea    0x30(%rsp),%r13
mov    %r14d,0x10(%rsp)
jmp    11c7 <finite_alphabet_likelihoods_alldisk+0x97>
nopl   (%rax)
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    0x28(%rsp),%rcx
call   1030 <fread@plt>
test   %rax,%rax
mov    0x10(%rsp),%r14d
je     1243 <finite_alphabet_likelihoods_alldisk+0x113>
movzbl 0xf(%rsp),%eax
cmp    $0x7f,%eax
jne    1200 <finite_alphabet_likelihoods_alldisk+0xd0>
test   %r14d,%r14d
jle    11a0 <finite_alphabet_likelihoods_alldisk+0x70>
mov    0x10(%rsp),%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    $0xffffffff,%ebp
jne    11e0 <finite_alphabet_likelihoods_alldisk+0xb0>
jmp    11a0 <finite_alphabet_likelihoods_alldisk+0x70>
nopl   0x0(%rax)
cmp    0x14(%rsp),%eax
jge    1247 <finite_alphabet_likelihoods_alldisk+0x117>
test   %r14d,%r14d
jle    11a0 <finite_alphabet_likelihoods_alldisk+0x70>
mov    %eax,%eax
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,8),%r12
mov    0x18(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
add    %r15,%r12
add    $0xffffffffffffffff,%r14
jne    1220 <finite_alphabet_likelihoods_alldisk+0xf0>
jmp    11a0 <finite_alphabet_likelihoods_alldisk+0x70>
xor    %ecx,%ecx
jmp    1261 <finite_alphabet_likelihoods_alldisk+0x131>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ecx
mov    %ecx,%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 @finite_alphabet_likelihoods_alldisk(i32 %0, i32 %1, double* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca double
store i32 %0, i32* %6
store i32 %1, i32* %7
store double* %2, double** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 0, i32* %11
store double 1.000000e+00, double* %15
br label %16
16: ; preds = %66, %5
%17 = load i32*, i32** %9
%18 = call i64 @fread(i8* %14, i32 1, i32 1, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %67
20: ; preds = %16
%21 = load i8, i8* %14
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 127
br i1 %23, label %24, label %36
24: ; preds = %20
store i32 0, i32* %12
br label %25
25: ; preds = %32, %24
%26 = load i32, i32* %12
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i32*, i32** %10
%31 = call i32 @fwrite(double* %15, i32 8, i32 1, i32* %30)
br label %32
32: ; preds = %29
%33 = load i32, i32* %12
%34 = add nsw i32 %33, 1
store i32 %34, i32* %12
br label %25
35: ; preds = %25
br label %66
36: ; preds = %20
%37 = load i8, i8* %14
%38 = zext i8 %37 to i32
%39 = load i32, i32* %7
%40 = icmp sge i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %11
br label %68
44: ; preds = %36
store i32 0, i32* %12
br label %45
45: ; preds = %62, %44
%46 = load i32, i32* %12
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %65
49: ; preds = %45
%50 = load i32, i32* %12
%51 = load i32, i32* %7
%52 = mul nsw i32 %50, %51
%53 = load i8, i8* %14
%54 = zext i8 %53 to i32
%55 = add nsw i32 %52, %54
store i32 %55, i32* %13
%56 = load double*, double** %8
%57 = load i32, i32* %13
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load i32*, i32** %10
%61 = call i32 @fwrite(double* %59, i32 8, i32 1, i32* %60)
br label %62
62: ; preds = %49
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %45
65: ; preds = %45
br label %66
66: ; preds = %65, %35
br label %16
67: ; preds = %16
br label %68
68: ; preds = %67, %41
%69 = load i32, i32* %11
ret i32 %69
}

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