#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*/ Debug_ErrorMsgArg(char *, char const *);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(void *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
void *malloc(size_t);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void FileLoad(const char *filename, void **buffer, size_t *size_) {
  FILE *f = fopen(filename, "rb");
  size_t size;
  *buffer = NULL;
  if (size_)
    *size_ = 0;
  if (f == NULL) {
    Debug_ErrorMsgArg("%s couldn't be opened!", filename);
    return;
  }
  fseek(f, 0, SEEK_END);
  size = ftell(f);
  if (size_)
    *size_ = size;
  if (size == 0) {
    Debug_ErrorMsgArg("Size of %s is 0!", filename);
    fclose(f);
    return;
  }
  rewind(f);
  *buffer = malloc(size);
  if (*buffer == NULL) {
    Debug_ErrorMsgArg("Not enought memory to load %s!", filename);
    fclose(f);
    return;
  }
  if (fread(*buffer, size, 1, f) != 1) {
    Debug_ErrorMsgArg("Error while reading: %s", filename);
    fclose(f);
    free(*buffer);
    return;
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<FileLoad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11d9 <FileLoad+0x49>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
jne    11f9 <FileLoad+0x69>
mov    -0x8(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   10b0 <Debug_ErrorMsgArg@plt>
jmp    12f6 <FileLoad+0x166>
mov    -0x20(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1230 <FileLoad+0xa0>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    1259 <FileLoad+0xc9>
mov    -0x8(%rbp),%rsi
lea    0xdd4(%rip),%rdi
call   10b0 <Debug_ErrorMsgArg@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12f6 <FileLoad+0x166>
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12a1 <FileLoad+0x111>
mov    -0x8(%rbp),%rsi
lea    0xd9d(%rip),%rdi
call   10b0 <Debug_ErrorMsgArg@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12f6 <FileLoad+0x166>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     12ed <FileLoad+0x15d>
mov    -0x8(%rbp),%rsi
lea    0xd7c(%rip),%rdi
call   10b0 <Debug_ErrorMsgArg@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
jmp    12f6 <FileLoad+0x166>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileLoad>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
movq   $0x0,(%r15)
test   %rbx,%rbx
je     11c4 <FileLoad+0x34>
movq   $0x0,(%rbx)
test   %r12,%r12
je     1250 <FileLoad+0xc0>
mov    0x2e14(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12,%rdi
call   1070 <ftell@plt>
mov    %rax,%r13
test   %rbx,%rbx
je     11f3 <FileLoad+0x63>
mov    %r13,(%rbx)
test   %r13,%r13
je     1268 <FileLoad+0xd8>
mov    %r12,%rdi
call   1060 <rewind@plt>
mov    %r13,%rdi
call   1080 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1271 <FileLoad+0xe1>
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1280 <FileLoad+0xf0>
lea    0xe1b(%rip),%rdi
mov    %r14,%rsi
call   10b0 <Debug_ErrorMsgArg@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    (%r15),%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xdac(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    10b0 <Debug_ErrorMsgArg@plt>
lea    0xdab(%rip),%rdi
jmp    1278 <FileLoad+0xe8>
lea    0xdb3(%rip),%rdi
mov    %r14,%rsi
call   10b0 <Debug_ErrorMsgArg@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [23 x i8] c"%s couldn't be opened!\00"
@SEEK_END = global i32 0
@.str.2 = [17 x i8] c"Size of %s is 0!\00"
@.str.3 = [31 x i8] c"Not enought memory to load %s!\00"
@.str.4 = [24 x i8] c"Error while reading: %s\00"
define void @FileLoad(i8* %0, i8** %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64* %2, i64** %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i8**, i8*** %5
store i8* null, i8** %11
%12 = load i64*, i64** %6
%13 = icmp ne i64* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i64*, i64** %6
store i64 0, i64* %15
br label %16
16: ; preds = %14, %3
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %73
22: ; preds = %16
%23 = load i32*, i32** %7
%24 = load i32, i32* @SEEK_END
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = load i32*, i32** %7
%27 = call i64 @ftell(i32* %26)
store i64 %27, i64* %8
%28 = load i64*, i64** %6
%29 = icmp ne i64* %28, null
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i64, i64* %8
%32 = load i64*, i64** %6
store i64 %31, i64* %32
br label %33
33: ; preds = %30, %22
%34 = load i64, i64* %8
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
br label %73
41: ; preds = %33
%42 = load i32*, i32** %7
%43 = call i32 @rewind(i32* %42)
%44 = load i64, i64* %8
%45 = call i8* @malloc(i64 %44)
%46 = load i8**, i8*** %5
store i8* %45, i8** %46
%47 = load i8**, i8*** %5
%48 = load i8*, i8** %47
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %55
50: ; preds = %41
%51 = load i8*, i8** %4
%52 = call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
br label %73
55: ; preds = %41
%56 = load i8**, i8*** %5
%57 = load i8*, i8** %56
%58 = load i64, i64* %8
%59 = load i32*, i32** %7
%60 = call i32 @fread(i8* %57, i64 %58, i32 1, i32* %59)
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %70
62: ; preds = %55
%63 = load i8*, i8** %4
%64 = call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %63)
%65 = load i32*, i32** %7
%66 = call i32 @fclose(i32* %65)
%67 = load i8**, i8*** %5
%68 = load i8*, i8** %67
%69 = call i32 @free(i8* %68)
br label %73
70: ; preds = %55
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
br label %73
73: ; preds = %70, %62, %50, %36, %19
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [23 x i8] c"%s couldn't be opened!\00"
@SEEK_END = global i32 0
@.str.2 = [17 x i8] c"Size of %s is 0!\00"
@.str.3 = [31 x i8] c"Not enought memory to load %s!\00"
@.str.4 = [24 x i8] c"Error while reading: %s\00"
define void @FileLoad(i8* %0, i8** nocapture %1, i64* writeonly %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %1
%5 = icmp eq i64* %2, null
br i1 %5, label %7, label %6
6: ; preds = %3
store i64 0, i64* %2
br label %7
7: ; preds = %6, %3
%8 = icmp eq i32* %4, null
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %38
11: ; preds = %7
%12 = load i32, i32* @SEEK_END
%13 = tail call i32 @fseek(i32* %4, i32 0, i32 %12)
%14 = tail call i64 @ftell(i32* %4)
br i1 %5, label %16, label %15
15: ; preds = %11
store i64 %14, i64* %2
br label %16
16: ; preds = %15, %11
%17 = icmp eq i64 %14, 0
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = tail call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%20 = tail call i32 @fclose(i32* %4)
br label %38
21: ; preds = %16
%22 = tail call i32 @rewind(i32* %4)
%23 = tail call i8* @malloc(i64 %14)
store i8* %23, i8** %1
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = tail call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%27 = tail call i32 @fclose(i32* %4)
br label %38
28: ; preds = %21
%29 = tail call i32 @fread(i8* %23, i64 %14, i32 1, i32* %4)
%30 = icmp eq i32 %29, 1
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = tail call i32 @Debug_ErrorMsgArg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%33 = tail call i32 @fclose(i32* %4)
%34 = load i8*, i8** %1
%35 = tail call i32 @free(i8* %34)
br label %38
36: ; preds = %28
%37 = tail call i32 @fclose(i32* %4)
br label %38
38: ; preds = %36, %31, %25, %18, %9
ret void
}