#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 /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
long fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int prussdrv_exec_code_at(int, unsigned int const *, int, size_t);
int prussdrv_exec_program_at(int prunum, const char *filename, size_t addr) {
  FILE *fPtr;
  unsigned char fileDataArray[8192];
  long fileSize = 0;
  fPtr = fopen(filename, "rb");
  if (fPtr == NULL) {
    ;
    return -1;
  } else {
    ;
  }
  fseek(fPtr, 0, SEEK_END);
  fileSize = ftell(fPtr);
  if (fileSize == 0) {
    ;
    fclose(fPtr);
    return -1;
  } else if (fileSize > 8192) {
    ;
    fclose(fPtr);
    return -1;
  }
  fseek(fPtr, 0, SEEK_SET);
  if (fileSize != fread((unsigned char *)fileDataArray, 1, fileSize, fPtr)) {
    ;
    fclose(fPtr);
    return -1;
  }
  fclose(fPtr);
  return prussdrv_exec_code_at(prunum, (const unsigned int *)fileDataArray,
                               (int)fileSize, addr);
}


x86 assembly (clang, -O0):
<prussdrv_exec_program_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x2028(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ac <prussdrv_exec_program_at+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <prussdrv_exec_program_at+0x151>
jmp    11b1 <prussdrv_exec_program_at+0x51>
mov    -0x20(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x2028(%rbp)
cmpq   $0x0,-0x2028(%rbp)
jne    11f8 <prussdrv_exec_program_at+0x98>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <prussdrv_exec_program_at+0x151>
cmpq   $0x2000,-0x2028(%rbp)
jle    121e <prussdrv_exec_program_at+0xbe>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <prussdrv_exec_program_at+0x151>
jmp    1223 <prussdrv_exec_program_at+0xc3>
mov    -0x20(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x2028(%rbp),%rax
mov    %rax,-0x2030(%rbp)
lea    -0x2020(%rbp),%rdi
mov    -0x2028(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
mov    -0x2030(%rbp),%rax
cmp    %rcx,%rax
je     1289 <prussdrv_exec_program_at+0x129>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <prussdrv_exec_program_at+0x151>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    -0x2028(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
call   1070 <prussdrv_exec_code_at@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prussdrv_exec_program_at>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    %rdx,%r14
mov    %rsi,%rax
mov    %edi,%r15d
lea    0xe7f(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     11ca <prussdrv_exec_program_at+0x6a>
mov    %rax,%rbp
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbp,%rdi
call   1050 <ftell@plt>
test   %rax,%rax
je     11c2 <prussdrv_exec_program_at+0x62>
mov    %rax,%rbx
cmp    $0x2001,%rax
jl     11df <prussdrv_exec_program_at+0x7f>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r12d,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1040 <fclose@plt>
cmp    %r13,%rbx
jne    11ca <prussdrv_exec_program_at+0x6a>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    %ebx,%edx
mov    %r14,%rcx
call   1070 <prussdrv_exec_code_at@plt>
mov    %eax,%r12d
jmp    11ca <prussdrv_exec_program_at+0x6a>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @prussdrv_exec_program_at(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca [8192 x i8]
%10 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %10
%11 = load i8*, i8** %6
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %58
16: ; preds = %3
br label %17
17: ; preds = %16
%18 = load i32*, i32** %8
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = load i32*, i32** %8
%22 = call i64 @ftell(i32* %21)
store i64 %22, i64* %10
%23 = load i64, i64* %10
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32*, i32** %8
%27 = call i32 @fclose(i32* %26)
store i32 -1, i32* %4
br label %58
28: ; preds = %17
%29 = load i64, i64* %10
%30 = icmp sgt i64 %29, 8192
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32*, i32** %8
%33 = call i32 @fclose(i32* %32)
store i32 -1, i32* %4
br label %58
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i32*, i32** %8
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @fseek(i32* %36, i32 0, i32 %37)
%39 = load i64, i64* %10
%40 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%41 = load i64, i64* %10
%42 = load i32*, i32** %8
%43 = call i64 @fread(i8* %40, i32 1, i64 %41, i32* %42)
%44 = icmp ne i64 %39, %43
br i1 %44, label %45, label %48
45: ; preds = %35
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
store i32 -1, i32* %4
br label %58
48: ; preds = %35
%49 = load i32*, i32** %8
%50 = call i32 @fclose(i32* %49)
%51 = load i32, i32* %5
%52 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%53 = bitcast i8* %52 to i32*
%54 = load i64, i64* %10
%55 = trunc i64 %54 to i32
%56 = load i64, i64* %7
%57 = call i32 @prussdrv_exec_code_at(i32 %51, i32* %53, i32 %55, i64 %56)
store i32 %57, i32* %4
br label %58
58: ; preds = %48, %45, %31, %25, %15
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @prussdrv_exec_program_at(i32 %0, i8* nocapture %1, i64 %2) {
%4 = alloca [8192 x i8]
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %29, label %8
8: ; preds = %3
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %6, i32 0, i32 %9)
%11 = tail call i64 @ftell(i32* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @fclose(i32* %6)
br label %29
15: ; preds = %8
%16 = icmp sgt i64 %11, 8192
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @fclose(i32* %6)
br label %29
19: ; preds = %15
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %6, i32 0, i32 %20)
%22 = call i64 @fread(i8* %5, i32 1, i64 %11, i32* %6)
%23 = icmp eq i64 %11, %22
%24 = tail call i32 @fclose(i32* %6)
br i1 %23, label %25, label %29
25: ; preds = %19
%26 = bitcast [8192 x i8]* %4 to i32*
%27 = trunc i64 %11 to i32
%28 = call i32 @prussdrv_exec_code_at(i32 %0, i32* %26, i32 %27, i64 %2)
br label %29
29: ; preds = %19, %3, %25, %17, %13
%30 = phi i32 [ -1, %13 ], [ -1, %17 ], [ %28, %25 ], [ -1, %3 ], [ -1, %19 ]
ret i32 %30
}