#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__ emission_expectations_alldisk(int, int, double *,
                                         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_emission_expectations(int nstates, int nalpha, double *expectations,
                             const char *observation_name,
                             const char *posterior_name) {
  int errcode = 0;
  FILE *fin_v = NULL;
  FILE *fin_d = 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 (!(fin_d = fopen(posterior_name, "rb"))) {
    fprintf(stderr, "failed to open the posterior vector file for reading\n");
    errcode = -1;
    goto end;
  }
  if (emission_expectations_alldisk(nstates, nalpha, expectations, fin_v,
                                    fin_d)) {
    errcode = -1;
    goto end;
  }
end:
  fsafeclose(fin_v);
  fsafeclose(fin_d);
  return errcode;
}


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

x86 assembly (clang, -O2):
<do_emission_expectations>:
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_emission_expectations+0x5b>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ad <do_emission_expectations+0x6d>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1030 <emission_expectations_alldisk@plt>
neg    %rax
sbb    %ebp,%ebp
jmp    11c9 <do_emission_expectations+0x89>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
jmp    11bd <do_emission_expectations+0x7d>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <fsafeclose@plt>
mov    %rbx,%rdi
call   1040 <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 = [54 x i8] c"failed to open the posterior vector file for reading\0A\00"
define i32 @do_emission_expectations(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, 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 ([54 x i8], [54 x i8]* @.str.2, 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 @emission_expectations_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 = [54 x i8] c"failed to open the posterior vector file for reading\0A\00"
define i32 @do_emission_expectations(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, 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 ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %21
17: ; preds = %11
%18 = tail call i64 @emission_expectations_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
}