#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 *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int 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];
  int 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,
                               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)
movl   $0x0,-0x2024(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <prussdrv_exec_program_at+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <prussdrv_exec_program_at+0x11a>
jmp    11b0 <prussdrv_exec_program_at+0x50>
mov    -0x20(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x0,-0x2024(%rbp)
jne    11f5 <prussdrv_exec_program_at+0x95>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <prussdrv_exec_program_at+0x11a>
mov    -0x20(%rbp),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x2024(%rbp),%eax
mov    %eax,-0x2028(%rbp)
lea    -0x2020(%rbp),%rdi
mov    -0x2024(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,%ecx
mov    -0x2028(%rbp),%eax
cmp    %ecx,%eax
je     1255 <prussdrv_exec_program_at+0xf5>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <prussdrv_exec_program_at+0x11a>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    -0x2024(%rbp),%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     120a <prussdrv_exec_program_at+0xaa>
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   %eax,%eax
je     1202 <prussdrv_exec_program_at+0xa2>
mov    %eax,%ebp
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    %r13d,%ebp
jne    120a <prussdrv_exec_program_at+0xaa>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    %ebp,%edx
mov    %r14,%rcx
call   1070 <prussdrv_exec_code_at@plt>
mov    %eax,%r12d
jmp    120a <prussdrv_exec_program_at+0xaa>
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 i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %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 %50
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 i32 @ftell(i32* %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = icmp eq i32 %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 %50
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 i32, i32* %10
%33 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* %10
%35 = load i32*, i32** %8
%36 = call i32 @fread(i8* %33, i32 1, i32 %34, i32* %35)
%37 = icmp ne i32 %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 %50
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 i32, i32* %10
%48 = load i64, i64* %7
%49 = call i32 @prussdrv_exec_code_at(i32 %44, i32* %46, i32 %47, i64 %48)
store i32 %49, i32* %4
br label %50
50: ; preds = %41, %38, %25, %15
%51 = load i32, i32* %4
ret i32 %51
}

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