#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 PATH_MAX;
int /*<<< orphan*/ check_pie(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char datapath[PATH_MAX], fullpath[PATH_MAX];
  FILE *fp = fopen("modellist.txt", "r");
  if (!fp) {
    fprintf(stderr, "%s: Failed to open list file\n", argv[0]);
    return -1;
  }
  strcpy(datapath, getenv("srcdir"));
  strcat(datapath, "/../data/");
  while (!feof(fp)) {
    char filename[PATH_MAX];
    if (fscanf(fp, "%254s\n", filename) != 1) {
      fprintf(stderr, "%s: Failed to read filename\n", argv[0]);
      return -1;
    }
    printf("Testing model: %s\n", filename);
    strcpy(fullpath, datapath);
    strcat(fullpath, filename);
    check_pie(fullpath);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xdf9(%rip),%rdi
lea    0xe23(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1251 <main+0xb1>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd5(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1378 <main+0x1d8>
lea    0xdd4(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x58(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1297 <main+0xf7>
jmp    1361 <main+0x1c1>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd6f(%rip),%rsi
call   1080 <fscanf@plt>
cmp    $0x1,%eax
je     130b <main+0x16b>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd51(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1345 <main+0x1a5>
mov    -0x60(%rbp),%rsi
lea    0xd4b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdi
call   1040 <strcpy@plt>
mov    -0x60(%rbp),%rsi
mov    -0x50(%rbp),%rdi
call   10c0 <strcat@plt>
mov    -0x50(%rbp),%rdi
call   1070 <check_pie@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x34(%rbp),%eax
test   %eax,%eax
jne    1378 <main+0x1d8>
jmp    135c <main+0x1bc>
jmp    1279 <main+0xd9>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe25(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     129e <main+0xfe>
mov    %rax,%r12
mov    %r14,-0x30(%rbp)
lea    0xe2e(%rip),%rdi
call   1030 <getenv@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe1e(%rip),%rsi
mov    %r15,%rdi
call   10c0 <strcat@plt>
nopl   (%rax)
mov    %r12,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1292 <main+0xf2>
mov    %rsp,%r13
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r12,%rdi
lea    0xdea(%rip),%rsi
mov    %r14,%rdx
call   1080 <fscanf@plt>
cmp    $0x1,%eax
jne    12bd <main+0x11d>
lea    0xdfa(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1070 <check_pie@plt>
mov    %r13,%rsp
jmp    1220 <main+0x80>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    12e1 <main+0x141>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd5d(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    12e1 <main+0x141>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
lea    0xd70(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [14 x i8] c"modellist.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"%s: Failed to open list file\0A\00"
@.str.3 = [7 x i8] c"srcdir\00"
@.str.4 = [10 x i8] c"/../data/\00"
@.str.5 = [7 x i8] c"%254s\0A\00"
@.str.6 = [29 x i8] c"%s: Failed to read filename\0A\00"
@.str.7 = [19 x i8] c"Testing model: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
%17 = load i32, i32* @PATH_MAX
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %8
%20 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %9
%21 = load i32*, i32** %9
%22 = icmp ne i32* %21, null
br i1 %22, label %29, label %23
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
store i32 1, i32* %10
br label %64
29: ; preds = %2
%30 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @strcpy(i8* %16, i8* %30)
%32 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %60, %29
%34 = load i32*, i32** %9
%35 = call i32 @feof(i32* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %61
38: ; preds = %33
%39 = load i32, i32* @PATH_MAX
%40 = zext i32 %39 to i64
%41 = call i8* @llvm.stacksave()
store i8* %41, i8** %11
%42 = alloca i8, i64 %40
store i64 %40, i64* %12
%43 = load i32*, i32** %9
%44 = call i32 @fscanf(i32* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %52
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %50)
store i32 -1, i32* %3
store i32 1, i32* %10
br label %57
52: ; preds = %38
%53 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %42)
%54 = call i32 @strcpy(i8* %19, i8* %16)
%55 = call i32 @strcat(i8* %19, i8* %42)
%56 = call i32 @check_pie(i8* %19)
store i32 0, i32* %10
br label %57
57: ; preds = %52, %46
%58 = load i8*, i8** %11
%59 = load i32, i32* %10
switch i32 %59, label %64 [
i32 0, label %60
]
60: ; preds = %57
br label %33
61: ; preds = %33
%62 = load i32*, i32** %9
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %3
store i32 1, i32* %10
br label %64
64: ; preds = %61, %57, %23
%65 = load i8*, i8** %6
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [14 x i8] c"modellist.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"%s: Failed to open list file\0A\00"
@.str.3 = [7 x i8] c"srcdir\00"
@.str.4 = [10 x i8] c"/../data/\00"
@.str.5 = [7 x i8] c"%254s\0A\00"
@.str.6 = [29 x i8] c"%s: Failed to read filename\0A\00"
@.str.7 = [19 x i8] c"Testing model: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %39
13: ; preds = %2
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @strcpy(i8* %5, i8* %14)
%16 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @feof(i32* %7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %13, %30
%20 = load i32, i32* @PATH_MAX
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i8, i64 %21
%24 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %30, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %28)
br label %39
30: ; preds = %19
%31 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %23)
%32 = call i32 @strcpy(i8* %6, i8* %5)
%33 = call i32 @strcat(i8* %6, i8* %23)
%34 = call i32 @check_pie(i8* %6)
%35 = call i32 @feof(i32* %7)
%36 = icmp eq i32 %35, 0
br i1 %36, label %19, label %37
37: ; preds = %30, %13
%38 = call i32 @fclose(i32* %7)
br label %39
39: ; preds = %26, %37, %9
%40 = phi i32 [ 0, %37 ], [ -1, %9 ], [ -1, %26 ]
ret i32 %40
}