#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(char *, char *, int /*<<< orphan*/ *);
int fread(void *, unsigned int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
void *malloc(unsigned int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void FileLoad(const char *filename, void **buffer, unsigned int *size_) {
  FILE *datafile = fopen(filename, "rb");
  unsigned int size;
  *buffer = NULL;
  if (size_)
    *size_ = 0;
  if (datafile == NULL) {
    char msg[2048];
    sprintf(msg, "%s couldn't be opened!", filename);
    fprintf("error.log", msg, NULL);
    return;
  }
  fseek(datafile, 0, SEEK_END);
  size = ftell(datafile);
  if (size_)
    *size_ = size;
  if (size == 0) {
    char msg[2048];
    sprintf(msg, "Size of %s is 0!", filename);
    fclose(datafile);
    return;
  }
  rewind(datafile);
  *buffer = malloc(size);
  if (*buffer == NULL) {
    char msg[2048];
    sprintf(msg, "Not enought memory to load %s!", filename);
    fclose(datafile);
    return;
  }
  if (fread(*buffer, size, 1, datafile) != 1) {
    fclose(datafile);
    return;
  }
  fclose(datafile);
}


x86 assembly (clang, -O0):
<FileLoad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11db <FileLoad+0x4b>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
jne    1219 <FileLoad+0x89>
lea    -0x830(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x830(%rbp),%rsi
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <fprintf@plt>
jmp    1302 <FileLoad+0x172>
mov    -0x20(%rbp),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     124d <FileLoad+0xbd>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x24(%rbp)
jne    127c <FileLoad+0xec>
lea    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdbb(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1302 <FileLoad+0x172>
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12ca <FileLoad+0x13a>
lea    -0x1830(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd7e(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1302 <FileLoad+0x172>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     12f9 <FileLoad+0x169>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1302 <FileLoad+0x172>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x1830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileLoad>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
movq   $0x0,(%r15)
test   %rbx,%rbx
je     11c9 <FileLoad+0x39>
movl   $0x0,(%rbx)
test   %r12,%r12
je     1236 <FileLoad+0xa6>
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11f2 <FileLoad+0x62>
mov    %ebp,(%rbx)
test   %ebp,%ebp
je     125e <FileLoad+0xce>
mov    %r12,%rdi
call   1050 <rewind@plt>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1267 <FileLoad+0xd7>
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %r12,%rdi
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xdc6(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
lea    0xdc8(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <fprintf@plt>
jmp    1281 <FileLoad+0xf1>
lea    0xdbf(%rip),%rsi
jmp    126e <FileLoad+0xde>
lea    0xdc7(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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