#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 */
struct TM {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ backward_alldisk(struct TM const *, int /*<<< orphan*/ *,
                                    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_backward(const struct TM *ptm, const char *likelihoods_name,
                const char *scaling_name, const char *backward_name) {
  int errcode = 0;
  FILE *fin_l = NULL;
  FILE *fin_s = NULL;
  FILE *fout_b = NULL;
  if (!(fin_l = fopen(likelihoods_name, "rb"))) {
    fprintf(stderr, "failed to open the likelihoods 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 (!(fout_b = fopen(backward_name, "wb"))) {
    fprintf(stderr, "failed to open the backward vector file for writing\n");
    errcode = -1;
    goto end;
  }
  backward_alldisk(ptm, fin_l, fin_s, fout_b);
end:
  fsafeclose(fin_l);
  fsafeclose(fin_s);
  fsafeclose(fout_b);
  return errcode;
}


x86 assembly (clang, -O0):
<do_backward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11b6 <do_backward+0x76>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1249 <do_backward+0x109>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11f5 <do_backward+0xb5>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1249 <do_backward+0x109>
mov    -0x20(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1234 <do_backward+0xf4>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1249 <do_backward+0x109>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
call   1040 <backward_alldisk@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fsafeclose@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_backward>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %rdi,%r15
lea    0xea6(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11ae <do_backward+0x6e>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c0 <do_backward+0x80>
mov    %rax,%rbx
lea    0xee0(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11df <do_backward+0x9f>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <backward_alldisk@plt>
xor    %r15d,%r15d
jmp    11fc <do_backward+0xbc>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
jmp    11d0 <do_backward+0x90>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%r15d
xor    %ebx,%ebx
jmp    11fa <do_backward+0xba>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%r15d
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <fsafeclose@plt>
mov    %rbx,%rdi
call   1030 <fsafeclose@plt>
mov    %rbp,%rdi
call   1030 <fsafeclose@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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