#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;
  }
  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    1286 <prussdrv_exec_program_at+0x126>
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    1286 <prussdrv_exec_program_at+0x126>
mov    -0x20(%rbp),%rdi
mov    0x2dd5(%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     125e <prussdrv_exec_program_at+0xfe>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1286 <prussdrv_exec_program_at+0x126>
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     120d <prussdrv_exec_program_at+0xad>
mov    %rax,%rbx
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
test   %rax,%rax
je     1205 <prussdrv_exec_program_at+0xa5>
mov    %rax,%rbp
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    %r13,%rbp
jne    120d <prussdrv_exec_program_at+0xad>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    %ebp,%edx
mov    %r14,%rcx
call   1070 <prussdrv_exec_code_at@plt>
mov    %eax,%r12d
jmp    120d <prussdrv_exec_program_at+0xad>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12d,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 %51
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 %51
28: ; preds = %17
%29 = load i32*, i32** %8
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
%32 = load i64, i64* %10
%33 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%34 = load i64, i64* %10
%35 = load i32*, i32** %8
%36 = call i64 @fread(i8* %33, i32 1, i64 %34, i32* %35)
%37 = icmp ne i64 %32, %36
br i1 %37, label %38, label %41
38: ; preds = %28
%39 = load i32*, i32** %8
%40 = call i32 @fclose(i32* %39)
store i32 -1, i32* %4
br label %51
41: ; preds = %28
%42 = load i32*, i32** %8
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %5
%45 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%46 = bitcast i8* %45 to i32*
%47 = load i64, i64* %10
%48 = trunc i64 %47 to i32
%49 = load i64, i64* %7
%50 = call i32 @prussdrv_exec_code_at(i32 %44, i32* %46, i32 %48, i64 %49)
store i32 %50, i32* %4
br label %51
51: ; preds = %41, %38, %25, %15
%52 = load i32, i32* %4
ret i32 %52
}

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 %25, 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 %25
15: ; preds = %8
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @fseek(i32* %6, i32 0, i32 %16)
%18 = call i64 @fread(i8* %5, i32 1, i64 %11, i32* %6)
%19 = icmp eq i64 %11, %18
%20 = tail call i32 @fclose(i32* %6)
br i1 %19, label %21, label %25
21: ; preds = %15
%22 = bitcast [8192 x i8]* %4 to i32*
%23 = trunc i64 %11 to i32
%24 = call i32 @prussdrv_exec_code_at(i32 %0, i32* %22, i32 %23, i64 %2)
br label %25
25: ; preds = %15, %3, %21, %13
%26 = phi i32 [ -1, %13 ], [ %24, %21 ], [ -1, %3 ], [ -1, %15 ]
ret i32 %26
}