#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 *, char *);
int /*<<< orphan*/ fread(void *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
void *malloc(unsigned long);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, unsigned long);
void *FileLoad(char *filename, unsigned long *size, char *mode) {
  FILE *f;
  void *buffer;
  unsigned long filesize;
  if (size)
    *size = 0;
  f = fopen(filename, mode);
  if (f == NULL)
    return NULL;
  fseek(f, 0, SEEK_END);
  filesize = ftell(f);
  fseek(f, 0, SEEK_SET);
  buffer = malloc(filesize + 10);
  if (buffer == NULL) {
    fclose(f);
    return NULL;
  }
  memset(buffer, 0, filesize + 10);
  fread(buffer, filesize, 1, f);
  fclose(f);
  if (size)
    *size = filesize;
  return buffer;
}


x86 assembly (clang, -O0):
<FileLoad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119a <FileLoad+0x2a>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c3 <FileLoad+0x53>
movq   $0x0,-0x8(%rbp)
jmp    127a <FileLoad+0x10a>
mov    -0x28(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x38(%rbp),%rdi
add    $0xa,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122a <FileLoad+0xba>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <FileLoad+0x10a>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
add    $0xa,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
je     1272 <FileLoad+0x102>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileLoad>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
test   %rsi,%rsi
je     1188 <FileLoad+0x18>
movq   $0x0,(%r14)
mov    %rdx,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121c <FileLoad+0xac>
mov    %rax,%rbx
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r12
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0xa(%r12),%r13
mov    %r13,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1214 <FileLoad+0xa4>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13,%rdx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     121f <FileLoad+0xaf>
mov    %r12,(%r14)
jmp    121f <FileLoad+0xaf>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @FileLoad(i8* nocapture %0, i64* writeonly %1, i8* nocapture %2) {
%4 = icmp eq i64* %1, null
br i1 %4, label %6, label %5
5: ; preds = %3
store i64 0, i64* %1
br label %6
6: ; preds = %5, %3
%7 = tail call i32* @fopen(i8* %0, i8* %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %25, label %9
9: ; preds = %6
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %7, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %7)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %7, i32 0, i32 %13)
%15 = add i64 %12, 10
%16 = tail call i8* @malloc(i64 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = tail call i32 @fclose(i32* %7)
br label %25
20: ; preds = %9
%21 = tail call i32 @memset(i8* %16, i32 0, i64 %15)
%22 = tail call i32 @fread(i8* %16, i64 %12, i32 1, i32* %7)
%23 = tail call i32 @fclose(i32* %7)
br i1 %4, label %25, label %24
24: ; preds = %20
store i64 %12, i64* %1
br label %25
25: ; preds = %20, %24, %6, %18
%26 = phi i8* [ null, %18 ], [ null, %6 ], [ %16, %24 ], [ %16, %20 ]
ret i8* %26
}