#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 /*<<< orphan*/ 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], *delim;
    fscanf(fp, "%s\n", &filename);
    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    $0x70,%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,-0x60(%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,-0x58(%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    1329 <main+0x189>
lea    0xdd4(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x60(%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    1312 <main+0x172>
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,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   1080 <fscanf@plt>
mov    -0x68(%rbp),%rsi
lea    0xd5f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
call   1040 <strcpy@plt>
mov    -0x68(%rbp),%rsi
mov    -0x58(%rbp),%rdi
call   10c0 <strcat@plt>
mov    -0x58(%rbp),%rdi
call   1070 <check_pie@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
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,%r12
mov    0x2e38(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe23(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12a2 <main+0x102>
mov    %rax,%r15
lea    0xe30(%rip),%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe20(%rip),%rsi
mov    %r14,%rdi
call   10c0 <strcat@plt>
mov    %r15,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
mov    %r14,-0x30(%rbp)
jne    1296 <main+0xf6>
mov    %r13,%r14
xchg   %ax,%ax
mov    %rsp,%r13
mov    (%r14),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r15,%rdi
lea    0xdfb(%rip),%rsi
mov    %r12,%rdx
call   1080 <fscanf@plt>
lea    0xddd(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1070 <check_pie@plt>
mov    %r13,%rsp
mov    %r15,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1230 <main+0x90>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    12c0 <main+0x120>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xd58(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
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 = [4 x i8] c"%s\0A\00"
@.str.6 = [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
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %6
%17 = alloca i8, i64 %15
store i64 %15, i64* %7
%18 = load i32, i32* @PATH_MAX
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %8
%21 = 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* %21, i32** %9
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
br i1 %23, label %30, label %24
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 -1, i32* %3
store i32 1, i32* %10
br label %55
30: ; preds = %2
%31 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @strcpy(i8* %17, i8* %31)
%33 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %39, %30
%35 = load i32*, i32** %9
%36 = call i32 @feof(i32* %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %52
39: ; preds = %34
%40 = load i32, i32* @PATH_MAX
%41 = zext i32 %40 to i64
%42 = call i8* @llvm.stacksave()
store i8* %42, i8** %11
%43 = alloca i8, i64 %41
store i64 %41, i64* %12
%44 = load i32*, i32** %9
%45 = bitcast i8* %43 to i8**
%46 = call i32 @fscanf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %43)
%48 = call i32 @strcpy(i8* %20, i8* %17)
%49 = call i32 @strcat(i8* %20, i8* %43)
%50 = call i32 @check_pie(i8* %20)
%51 = load i8*, i8** %11
br label %34
52: ; preds = %34
%53 = load i32*, i32** %9
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %3
store i32 1, i32* %10
br label %55
55: ; preds = %52, %24
%56 = load i8*, i8** %6
%57 = load i32, i32* %3
ret i32 %57
}

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 = [4 x i8] c"%s\0A\00"
@.str.6 = [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 %34
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 %32
19: ; preds = %13, %19
%20 = load i32, i32* @PATH_MAX
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i8, i64 %21
%24 = bitcast i8* %23 to i8**
%25 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %23)
%27 = call i32 @strcpy(i8* %6, i8* %5)
%28 = call i32 @strcat(i8* %6, i8* %23)
%29 = call i32 @check_pie(i8* %6)
%30 = call i32 @feof(i32* %7)
%31 = icmp eq i32 %30, 0
br i1 %31, label %19, label %32
32: ; preds = %19, %13
%33 = call i32 @fclose(i32* %7)
br label %34
34: ; preds = %32, %9
%35 = phi i32 [ 0, %32 ], [ -1, %9 ]
ret i32 %35
}