#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 */
scalar_t__ finite_alphabet_likelihoods_alldisk(int, int, double const *,
                                               int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fsafeclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int do_finite_alphabet_likelihoods(int nstates, int nalpha,
                                   const double *emissions,
                                   const char *observation_name,
                                   const char *likelihood_name) {
  int errcode = 0;
  FILE *fin_v = NULL;
  FILE *fout_l = NULL;
  if (!(fin_v = fopen(observation_name, "rb"))) {
    fprintf(stderr, "failed to open the observation vector file for reading\n");
    errcode = -1;
    goto end;
  }
  if (!(fout_l = fopen(likelihood_name, "wb"))) {
    fprintf(stderr, "failed to open the likelihood vector file for writing\n");
    errcode = -1;
    goto end;
  }
  if (finite_alphabet_likelihoods_alldisk(nstates, nalpha, emissions, fin_v,
                                          fout_l)) {
    errcode = -1;
    goto end;
  }
end:
  fsafeclose(fin_v);
  fsafeclose(fout_l);
  return errcode;
}


x86 assembly (clang, -O0):
<do_finite_alphabet_likelihoods>:
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)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11b0 <do_finite_alphabet_likelihoods+0x70>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1221 <do_finite_alphabet_likelihoods+0xe1>
mov    -0x20(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11ef <do_finite_alphabet_likelihoods+0xaf>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1221 <do_finite_alphabet_likelihoods+0xe1>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1050 <finite_alphabet_likelihoods_alldisk@plt>
cmp    $0x0,%rax
je     121c <do_finite_alphabet_likelihoods+0xdc>
movl   $0xffffffff,-0x24(%rbp)
jmp    1221 <do_finite_alphabet_likelihoods+0xe1>
jmp    1221 <do_finite_alphabet_likelihoods+0xe1>
mov    -0x30(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_finite_alphabet_likelihoods>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%rbx
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%ebp
lea    0xea6(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     119b <do_finite_alphabet_likelihoods+0x5b>
lea    0xeca(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ad <do_finite_alphabet_likelihoods+0x6d>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1050 <finite_alphabet_likelihoods_alldisk@plt>
neg    %rax
sbb    %ebp,%ebp
jmp    11c9 <do_finite_alphabet_likelihoods+0x89>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
jmp    11bd <do_finite_alphabet_likelihoods+0x7d>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <fsafeclose@plt>
mov    %rbx,%rdi
call   1030 <fsafeclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"failed to open the observation vector file for reading\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [55 x i8] c"failed to open the likelihood vector file for writing\0A\00"
define i32 @do_finite_alphabet_likelihoods(i32 %0, i32 %1, double* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
store i32 %0, i32* %6
store i32 %1, i32* %7
store double* %2, double** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 0, i32* %11
store i32* null, i32** %12
store i32* null, i32** %13
%14 = load i8*, i8** %9
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %12
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %5
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %11
br label %37
20: ; preds = %5
%21 = load i8*, i8** %10
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %13
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %11
br label %37
27: ; preds = %20
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = load double*, double** %8
%31 = load i32*, i32** %12
%32 = load i32*, i32** %13
%33 = call i64 @finite_alphabet_likelihoods_alldisk(i32 %28, i32 %29, double* %30, i32* %31, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %27
store i32 -1, i32* %11
br label %37
36: ; preds = %27
br label %37
37: ; preds = %36, %35, %24, %17
%38 = load i32*, i32** %12
%39 = call i32 @fsafeclose(i32* %38)
%40 = load i32*, i32** %13
%41 = call i32 @fsafeclose(i32* %40)
%42 = load i32, i32* %11
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"failed to open the observation vector file for reading\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [55 x i8] c"failed to open the likelihood vector file for writing\0A\00"
define i32 @do_finite_alphabet_likelihoods(i32 %0, i32 %1, double* %2, i8* nocapture %3, i8* nocapture %4) {
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
br label %21
11: ; preds = %5
%12 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
br label %21
17: ; preds = %11
%18 = tail call i64 @finite_alphabet_likelihoods_alldisk(i32 %0, i32 %1, double* %2, i32* %6, i32* %12)
%19 = icmp ne i64 %18, 0
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %17, %14, %8
%22 = phi i32 [ -1, %14 ], [ -1, %8 ], [ %20, %17 ]
%23 = phi i32* [ null, %14 ], [ null, %8 ], [ %12, %17 ]
%24 = tail call i32 @fsafeclose(i32* %6)
%25 = tail call i32 @fsafeclose(i32* %23)
ret i32 %22
}