#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;
  }
  pe_active(pe);
  rc = system("./tlp-4-003a.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    1282 <main+0x122>
mov    -0x84(%rbp),%edi
call   1080 <pe_active@plt>
lea    0xe31(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jge    1218 <main+0xb8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <main+0x122>
lea    -0x80(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x88(%rbp)
lea    0xdfe(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x88(%rbp)
jge    127b <main+0x11b>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <main+0x122>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
cmp    $0x2,%edi
jl     1170 <main+0x10>
mov    0x8(%rsi),%rsi
jmp    1177 <main+0x17>
lea    0xe89(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1060 <pe_init@plt>
test   %eax,%eax
js     11ef <main+0x8f>
mov    %eax,%edi
call   1080 <pe_active@plt>
lea    0xe8d(%rip),%rdi
call   1040 <system@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
js     120b <main+0xab>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0xe73(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
test   %ebx,%ebx
jns    120b <main+0xab>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
lea    0xe5f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1206 <main+0xa6>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbx
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-003a.sh\00"
@O_RDONLY = global i32 0
@.str.3 = [16 x i8] c"./tlp-4-003b.sh\00"
@.str.4 = [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 %46
27: ; preds = %21
%28 = load i32, i32* %7
%29 = call i32 @pe_active(i32 %28)
%30 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 -1, i32* %3
br label %46
34: ; preds = %27
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %8
%38 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 %38, i32* %9
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %43)
store i32 -1, i32* %3
br label %46
45: ; preds = %34
store i32 0, i32* %3
br label %46
46: ; preds = %45, %41, %33, %24
%47 = load i32, i32* %3
ret i32 %47
}

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-003a.sh\00"
@O_RDONLY = global i32 0
@.str.3 = [16 x i8] c"./tlp-4-003b.sh\00"
@.str.4 = [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 %30
17: ; preds = %9
%18 = call i32 @pe_active(i32 %12)
%19 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp slt i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %17
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %4, i32 %22)
%24 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp slt i32 %23, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %21, %17, %26, %14
%31 = phi i32 [ -1, %14 ], [ -1, %26 ], [ -1, %17 ], [ 0, %21 ]
ret i32 %31
}