#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fsafeclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ transition_expectations_alldisk(int, double const *,
                                                   double *,
                                                   int /*<<< orphan*/ *,
                                                   int /*<<< orphan*/ *,
                                                   int /*<<< orphan*/ *);
int do_transition_expectations(int nstates, const double *trans,
                               double *expectations,
                               const char *likelihoods_name,
                               const char *forward_name,
                               const char *backward_name) {
  int errcode = 0;
  FILE *fin_l = NULL;
  FILE *fin_f = NULL;
  FILE *fin_b = NULL;
  if (!(fin_l = fopen(likelihoods_name, "rb"))) {
    fprintf(stderr, "failed to open the likelihoods vector file for reading\n");
    errcode = -1;
    goto end;
  }
  if (!(fin_f = fopen(forward_name, "rb"))) {
    fprintf(stderr, "failed to open the forward factor file for reading\n");
    errcode = -1;
    goto end;
  }
  if (!(fin_b = fopen(backward_name, "rb"))) {
    fprintf(stderr, "failed to open the backward vector file for reading\n");
    errcode = -1;
    goto end;
  }
  transition_expectations_alldisk(nstates, trans, expectations, fin_l, fin_f,
                                  fin_b);
end:
  fsafeclose(fin_l);
  fsafeclose(fin_f);
  fsafeclose(fin_b);
  return errcode;
}


x86 assembly (clang, -O0):
<do_transition_expectations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11bd <do_transition_expectations+0x7d>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x34(%rbp)
jmp    1257 <do_transition_expectations+0x117>
mov    -0x28(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11fc <do_transition_expectations+0xbc>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x34(%rbp)
jmp    1257 <do_transition_expectations+0x117>
mov    -0x30(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    123b <do_transition_expectations+0xfb>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x34(%rbp)
jmp    1257 <do_transition_expectations+0x117>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%r9
call   1030 <transition_expectations_alldisk@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fsafeclose@plt>
mov    -0x48(%rbp),%rdi
call   1040 <fsafeclose@plt>
mov    -0x50(%rbp),%rdi
call   1040 <fsafeclose@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_transition_expectations>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r13
mov    %r8,%r12
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r15d
lea    0xe9c(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11cb <do_transition_expectations+0x8b>
mov    %rbp,0x8(%rsp)
mov    %rbx,0x10(%rsp)
lea    0xe7b(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11dd <do_transition_expectations+0x9d>
mov    %rax,%r12
lea    0xe64(%rip),%rsi
mov    %r13,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fc <do_transition_expectations+0xbc>
mov    %rax,%rbx
mov    %r15d,%edi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    %r14,%rcx
mov    %r12,%r8
mov    %rax,%r9
call   1030 <transition_expectations_alldisk@plt>
xor    %ebp,%ebp
jmp    1218 <do_transition_expectations+0xd8>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
jmp    11ed <do_transition_expectations+0xad>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
xor    %r12d,%r12d
jmp    1216 <do_transition_expectations+0xd6>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <fsafeclose@plt>
mov    %r12,%rdi
call   1040 <fsafeclose@plt>
mov    %rbx,%rdi
call   1040 <fsafeclose@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 likelihoods vector file for reading\0A\00"
@.str.2 = [52 x i8] c"failed to open the forward factor file for reading\0A\00"
@.str.3 = [53 x i8] c"failed to open the backward vector file for reading\0A\00"
define i32 @do_transition_expectations(i32 %0, double* %1, double* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
store i32 %0, i32* %7
store double* %1, double** %8
store double* %2, double** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
store i32 0, i32* %13
store i32* null, i32** %14
store i32* null, i32** %15
store i32* null, i32** %16
%17 = load i8*, i8** %10
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %14
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %6
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %13
br label %45
23: ; preds = %6
%24 = load i8*, i8** %11
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %15
%26 = icmp ne i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %13
br label %45
30: ; preds = %23
%31 = load i8*, i8** %12
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %32, i32** %16
%33 = icmp ne i32* %32, null
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %13
br label %45
37: ; preds = %30
%38 = load i32, i32* %7
%39 = load double*, double** %8
%40 = load double*, double** %9
%41 = load i32*, i32** %14
%42 = load i32*, i32** %15
%43 = load i32*, i32** %16
%44 = call i32 @transition_expectations_alldisk(i32 %38, double* %39, double* %40, i32* %41, i32* %42, i32* %43)
br label %45
45: ; preds = %37, %34, %27, %20
%46 = load i32*, i32** %14
%47 = call i32 @fsafeclose(i32* %46)
%48 = load i32*, i32** %15
%49 = call i32 @fsafeclose(i32* %48)
%50 = load i32*, i32** %16
%51 = call i32 @fsafeclose(i32* %50)
%52 = load i32, i32* %13
ret i32 %52
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"failed to open the likelihoods vector file for reading\0A\00"
@.str.2 = [52 x i8] c"failed to open the forward factor file for reading\0A\00"
@.str.3 = [53 x i8] c"failed to open the backward vector file for reading\0A\00"
define i32 @do_transition_expectations(i32 %0, double* %1, double* %2, i8* nocapture %3, i8* nocapture %4, i8* nocapture %5) {
%7 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
br label %26
12: ; preds = %6
%13 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %26
18: ; preds = %12
%19 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
br label %26
24: ; preds = %18
%25 = tail call i32 @transition_expectations_alldisk(i32 %0, double* %1, double* %2, i32* %7, i32* %13, i32* %19)
br label %26
26: ; preds = %24, %21, %15, %9
%27 = phi i32 [ 0, %24 ], [ -1, %21 ], [ -1, %15 ], [ -1, %9 ]
%28 = phi i32* [ %13, %24 ], [ %13, %21 ], [ null, %15 ], [ null, %9 ]
%29 = phi i32* [ %19, %24 ], [ null, %21 ], [ null, %15 ], [ null, %9 ]
%30 = tail call i32 @fsafeclose(i32* %7)
%31 = tail call i32 @fsafeclose(i32* %28)
%32 = tail call i32 @fsafeclose(i32* %29)
ret i32 %27
}