#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*/ posterior_alldisk(int, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int do_posterior(int nstates, const char *forward_name,
                 const char *scaling_name, const char *backward_name,
                 const char *posterior_name) {
  int errcode = 0;
  FILE *fin_f = NULL;
  FILE *fin_s = NULL;
  FILE *fin_b = NULL;
  FILE *fout_d = NULL;
  if (!(fin_f = fopen(forward_name, "rb"))) {
    fprintf(stderr, "failed to open the forward vector file for reading\n");
    errcode = -1;
    goto end;
  }
  if (!(fin_s = fopen(scaling_name, "rb"))) {
    fprintf(stderr, "failed to open the scaling 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;
  }
  if (!(fout_d = fopen(posterior_name, "wb"))) {
    fprintf(stderr, "failed to open the posterior vector file for writing\n");
    errcode = -1;
    goto end;
  }
  posterior_alldisk(nstates, fin_f, fin_s, fin_b, fout_d);
end:
  fsafeclose(fin_f);
  fsafeclose(fin_s);
  fsafeclose(fin_b);
  fsafeclose(fout_d);
  return errcode;
}


x86 assembly (clang, -O0):
<do_posterior>:
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)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11c1 <do_posterior+0x81>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1296 <do_posterior+0x156>
mov    -0x18(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1200 <do_posterior+0xc0>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1296 <do_posterior+0x156>
mov    -0x20(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    123f <do_posterior+0xff>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1296 <do_posterior+0x156>
mov    -0x28(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    127e <do_posterior+0x13e>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1296 <do_posterior+0x156>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
call   1050 <posterior_alldisk@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x2c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_posterior>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r13
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%rax
mov    %edi,%r12d
lea    0xe9f(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11d7 <do_posterior+0x97>
lea    0xe88(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e9 <do_posterior+0xa9>
mov    %rax,%r15
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     123d <do_posterior+0xfd>
mov    %rax,%rbx
lea    0xef6(%rip),%rsi
mov    %r13,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     125a <do_posterior+0x11a>
mov    %rax,%rbp
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1050 <posterior_alldisk@plt>
xor    %r12d,%r12d
jmp    120b <do_posterior+0xcb>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
jmp    11f9 <do_posterior+0xb9>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%r12d
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <fsafeclose@plt>
mov    %r15,%rdi
call   1030 <fsafeclose@plt>
mov    %rbx,%rdi
call   1030 <fsafeclose@plt>
mov    %rbp,%rdi
call   1030 <fsafeclose@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%r12d
jmp    1207 <do_posterior+0xc7>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%r12d
jmp    1209 <do_posterior+0xc9>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [52 x i8] c"failed to open the forward vector file for reading\0A\00"
@.str.2 = [52 x i8] c"failed to open the scaling factor file for reading\0A\00"
@.str.3 = [53 x i8] c"failed to open the backward vector file for reading\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [54 x i8] c"failed to open the posterior vector file for writing\0A\00"
define i32 @do_posterior(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %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
store i32* null, i32** %14
store i32* null, i32** %15
%16 = load i8*, i8** %7
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %12
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %11
br label %50
22: ; preds = %5
%23 = load i8*, i8** %8
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %13
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %11
br label %50
29: ; preds = %22
%30 = load i8*, i8** %9
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %31, i32** %14
%32 = icmp ne i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %11
br label %50
36: ; preds = %29
%37 = load i8*, i8** %10
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %38, i32** %15
%39 = icmp ne i32* %38, null
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %11
br label %50
43: ; preds = %36
%44 = load i32, i32* %6
%45 = load i32*, i32** %12
%46 = load i32*, i32** %13
%47 = load i32*, i32** %14
%48 = load i32*, i32** %15
%49 = call i32 @posterior_alldisk(i32 %44, i32* %45, i32* %46, i32* %47, i32* %48)
br label %50
50: ; preds = %43, %40, %33, %26, %19
%51 = load i32*, i32** %12
%52 = call i32 @fsafeclose(i32* %51)
%53 = load i32*, i32** %13
%54 = call i32 @fsafeclose(i32* %53)
%55 = load i32*, i32** %14
%56 = call i32 @fsafeclose(i32* %55)
%57 = load i32*, i32** %15
%58 = call i32 @fsafeclose(i32* %57)
%59 = load i32, i32* %11
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [52 x i8] c"failed to open the forward vector file for reading\0A\00"
@.str.2 = [52 x i8] c"failed to open the scaling factor file for reading\0A\00"
@.str.3 = [53 x i8] c"failed to open the backward vector file for reading\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [54 x i8] c"failed to open the posterior vector file for writing\0A\00"
define i32 @do_posterior(i32 %0, i8* nocapture %1, i8* nocapture %2, i8* nocapture %3, i8* nocapture %4) {
%6 = tail call i32* @fopen(i8* %1, 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 ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %31
11: ; preds = %5
%12 = tail call i32* @fopen(i8* %2, 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 ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %31
17: ; preds = %11
%18 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
br label %31
23: ; preds = %17
%24 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = tail call i32 @posterior_alldisk(i32 %0, i32* %6, i32* %12, i32* %18, i32* %24)
br label %31
31: ; preds = %29, %26, %20, %14, %8
%32 = phi i32 [ 0, %29 ], [ -1, %26 ], [ -1, %20 ], [ -1, %14 ], [ -1, %8 ]
%33 = phi i32* [ %12, %29 ], [ %12, %26 ], [ %12, %20 ], [ null, %14 ], [ null, %8 ]
%34 = phi i32* [ %18, %29 ], [ %18, %26 ], [ null, %20 ], [ null, %14 ], [ null, %8 ]
%35 = phi i32* [ %24, %29 ], [ null, %26 ], [ null, %20 ], [ null, %14 ], [ null, %8 ]
%36 = tail call i32 @fsafeclose(i32* %6)
%37 = tail call i32 @fsafeclose(i32* %33)
%38 = tail call i32 @fsafeclose(i32* %34)
%39 = tail call i32 @fsafeclose(i32* %35)
ret i32 %32
}