#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 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*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void FileLoad(const char *filename, void **buffer, unsigned int *size_) {
  FILE *f = fopen(filename, "rb");
  unsigned int size;
  *buffer = NULL;
  if (size_)
    *size_ = 0;
  if (f == NULL) {
    printf("%s couldn't be opened!", filename);
    return;
  }
  fseek(f, 0, SEEK_END);
  size = ftell(f);
  if (size_)
    *size_ = size;
  if (size == 0) {
    printf("Size of %s is 0!", filename);
    fclose(f);
    return;
  }
  rewind(f);
  *buffer = malloc(size);
  if (*buffer == NULL) {
    printf("Not enought memory to load %s!", filename);
    fclose(f);
    return;
  }
  if (fread(*buffer, size, 1, f) != 1) {
    printf("Error while reading.");
    fclose(f);
    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    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11c8 <FileLoad+0x48>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
jne    11ea <FileLoad+0x6a>
mov    -0x8(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d7 <FileLoad+0x157>
mov    -0x20(%rbp),%rdi
mov    0x2df3(%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     121e <FileLoad+0x9e>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x24(%rbp)
jne    1248 <FileLoad+0xc8>
mov    -0x8(%rbp),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12d7 <FileLoad+0x157>
mov    -0x20(%rbp),%rdi
call   1060 <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    1291 <FileLoad+0x111>
mov    -0x8(%rbp),%rsi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12d7 <FileLoad+0x157>
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     12ce <FileLoad+0x14e>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12d7 <FileLoad+0x157>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileLoad>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe68(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
movq   $0x0,(%r15)
test   %rbx,%rbx
je     11b2 <FileLoad+0x32>
movl   $0x0,(%rbx)
test   %r12,%r12
je     121d <FileLoad+0x9d>
mov    0x2e2a(%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     11db <FileLoad+0x5b>
mov    %ebp,(%rbx)
test   %ebp,%ebp
je     1236 <FileLoad+0xb6>
mov    %r12,%rdi
call   1060 <rewind@plt>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     123f <FileLoad+0xbf>
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1250 <FileLoad+0xd0>
lea    0xe36(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1250 <FileLoad+0xd0>
lea    0xddf(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
lea    0xddd(%rip),%rdi
jmp    1246 <FileLoad+0xc6>
lea    0xde5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <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 = [21 x i8] c"Error while reading.\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
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %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 i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32*, i32** %6
store i32 0, i32* %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 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %69
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 i32 @ftell(i32* %26)
store i32 %27, i32* %8
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* %8
%32 = load i32*, i32** %6
store i32 %31, i32* %32
br label %33
33: ; preds = %30, %22
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = call i32 (i8*, ...) @printf(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 %69
41: ; preds = %33
%42 = load i32*, i32** %7
%43 = call i32 @rewind(i32* %42)
%44 = load i32, i32* %8
%45 = call i8* @malloc(i32 %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 (i8*, ...) @printf(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 %69
55: ; preds = %41
%56 = load i8**, i8*** %5
%57 = load i8*, i8** %56
%58 = load i32, i32* %8
%59 = load i32*, i32** %7
%60 = call i32 @fread(i8* %57, i32 %58, i32 1, i32* %59)
%61 = icmp ne i32 %60, 1
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%64 = load i32*, i32** %7
%65 = call i32 @fclose(i32* %64)
br label %69
66: ; preds = %55
%67 = load i32*, i32** %7
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %66, %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 = [21 x i8] c"Error while reading.\00"
define void @FileLoad(i8* %0, i8** nocapture writeonly %1, i32* 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 i32* %2, null
br i1 %5, label %7, label %6
6: ; preds = %3
store i32 0, i32* %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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %36
11: ; preds = %7
%12 = load i32, i32* @SEEK_END
%13 = tail call i32 @fseek(i32* %4, i32 0, i32 %12)
%14 = tail call i32 @ftell(i32* %4)
br i1 %5, label %16, label %15
15: ; preds = %11
store i32 %14, i32* %2
br label %16
16: ; preds = %15, %11
%17 = icmp eq i32 %14, 0
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) 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 %36
21: ; preds = %16
%22 = tail call i32 @rewind(i32* %4)
%23 = tail call i8* @malloc(i32 %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 (i8*, ...) @printf(i8* dereferenceable(1) 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 %36
28: ; preds = %21
%29 = tail call i32 @fread(i8* %23, i32 %14, i32 1, i32* %4)
%30 = icmp eq i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%33 = tail call i32 @fclose(i32* %4)
br label %36
34: ; preds = %28
%35 = tail call i32 @fclose(i32* %4)
br label %36
36: ; preds = %34, %31, %25, %18, %9
ret void
}