#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pe_active(int);
int pe_init();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int system(char *);
int main(int argc, char *argv[]) {
  char file[100];
  int pe;
  int fd;
  int rc;
  if (argc > 1) {
    strcpy(file, argv[1]);
  } else {
    strcpy(file, "/test/file");
  }
  if ((pe = pe_init()) < 0) {
    fprintf(stderr, "Failed to initialize PE!\n");
    return -1;
  }
  rc = system("./tlp-4-004a.sh");
  if (rc < 0) {
    return -1;
  }
  pe_active(pe);
  rc = system("./tlp-4-004b.sh");
  if (rc < 0) {
    return -1;
  }
  fd = open(file, O_RDONLY);
  rc = system("./tlp-4-003b.sh");
  if (fd < 0) {
    fprintf(stderr, "Open failed %d!\n", errno);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1199 <main+0x39>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
jmp    11a9 <main+0x49>
lea    -0x80(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x0,%al
call   1060 <pe_init@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x0,%eax
jge    11e2 <main+0x82>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <main+0x14d>
lea    0xe3c(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jge    120d <main+0xad>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <main+0x14d>
mov    -0x84(%rbp),%edi
call   1080 <pe_active@plt>
lea    0xe16(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jge    1243 <main+0xe3>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <main+0x14d>
lea    -0x80(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x88(%rbp)
lea    0xde3(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x88(%rbp)
jge    12a6 <main+0x146>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%edx
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <main+0x14d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jl     1171 <main+0x11>
mov    0x8(%rsi),%rsi
jmp    1178 <main+0x18>
lea    0xe88(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1060 <pe_init@plt>
test   %eax,%eax
js     1200 <main+0xa0>
mov    %eax,%ebp
lea    0xe91(%rip),%rdi
call   1040 <system@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     121c <main+0xbc>
mov    %ebp,%edi
call   1080 <pe_active@plt>
lea    0xe85(%rip),%rdi
call   1040 <system@plt>
test   %eax,%eax
js     121c <main+0xbc>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
lea    0xe72(%rip),%rdi
call   1040 <system@plt>
xor    %ebx,%ebx
test   %ebp,%ebp
jns    121c <main+0xbc>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1217 <main+0xb7>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/test/file\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Failed to initialize PE!\0A\00"
@.str.2 = [16 x i8] c"./tlp-4-004a.sh\00"
@.str.3 = [16 x i8] c"./tlp-4-004b.sh\00"
@O_RDONLY = global i32 0
@.str.4 = [16 x i8] c"./tlp-4-003b.sh\00"
@.str.5 = [17 x i8] c"Open failed %d!\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %13, i8* %16)
br label %21
18: ; preds = %2
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %12
%22 = call i32 (...) @pe_init()
store i32 %22, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %51
27: ; preds = %21
%28 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -1, i32* %3
br label %51
32: ; preds = %27
%33 = load i32, i32* %7
%34 = call i32 @pe_active(i32 %33)
%35 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 -1, i32* %3
br label %51
39: ; preds = %32
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* @O_RDONLY
%42 = call i32 @open(i8* %40, i32 %41)
store i32 %42, i32* %8
%43 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 %43, i32* %9
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %48)
store i32 -1, i32* %3
br label %51
50: ; preds = %39
store i32 0, i32* %3
br label %51
51: ; preds = %50, %46, %38, %31, %24
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [11 x i8] c"/test/file\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Failed to initialize PE!\0A\00"
@.str.2 = [16 x i8] c"./tlp-4-004a.sh\00"
@.str.3 = [16 x i8] c"./tlp-4-004b.sh\00"
@O_RDONLY = global i32 0
@.str.4 = [16 x i8] c"./tlp-4-003b.sh\00"
@.str.5 = [17 x i8] c"Open failed %d!\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %2, %6
%10 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = call i32 @strcpy(i8* %4, i8* %10)
%12 = call i32 (...) @pe_init()
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %33
17: ; preds = %9
%18 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp slt i32 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = call i32 @pe_active(i32 %12)
%22 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp slt i32 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %20
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %4, i32 %25)
%27 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp slt i32 %26, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %24, %20, %17, %29, %14
%34 = phi i32 [ -1, %14 ], [ -1, %29 ], [ -1, %17 ], [ -1, %20 ], [ 0, %24 ]
ret i32 %34
}