#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*/ rewind(int /*<<< orphan*/ *);
void FileLoad_NoError(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)
    return;
  fseek(datafile, 0, SEEK_END);
  size = ftell(datafile);
  if (size_)
    *size_ = size;
  if (size == 0) {
    if (datafile != NULL)
      fclose(datafile);
    return;
  }
  rewind(datafile);
  *buffer = malloc(size);
  if (*buffer == NULL) {
    fclose(datafile);
    return;
  }
  if (fread(*buffer, size, 1, datafile) != 1) {
    fclose(datafile);
    return;
  }
  fclose(datafile);
}


x86 assembly (clang, -O0):
<FileLoad_NoError>:
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    0xe71(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11b8 <FileLoad_NoError+0x48>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
jne    11c8 <FileLoad_NoError+0x58>
jmp    128e <FileLoad_NoError+0x11e>
mov    -0x20(%rbp),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11fc <FileLoad_NoError+0x8c>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x24(%rbp)
jne    121f <FileLoad_NoError+0xaf>
cmpq   $0x0,-0x20(%rbp)
je     121a <FileLoad_NoError+0xaa>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    128e <FileLoad_NoError+0x11e>
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x24(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1256 <FileLoad_NoError+0xe6>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    128e <FileLoad_NoError+0x11e>
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     1285 <FileLoad_NoError+0x115>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    128e <FileLoad_NoError+0x11e>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileLoad_NoError>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
movq   $0x0,(%r14)
test   %rbx,%rbx
je     119e <FileLoad_NoError+0x2e>
movl   $0x0,(%rbx)
test   %r15,%r15
je     1206 <FileLoad_NoError+0x96>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11c7 <FileLoad_NoError+0x57>
mov    %ebp,(%rbx)
test   %ebp,%ebp
je     11f4 <FileLoad_NoError+0x84>
mov    %r15,%rdi
call   1050 <rewind@plt>
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11f4 <FileLoad_NoError+0x84>
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define void @FileLoad_NoError(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 %20
19: ; preds = %16
br label %66
20: ; preds = %16
%21 = load i32*, i32** %7
%22 = load i32, i32* @SEEK_END
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32*, i32** %7
%25 = call i32 @ftell(i32* %24)
store i32 %25, i32* %8
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* %8
%30 = load i32*, i32** %6
store i32 %29, i32* %30
br label %31
31: ; preds = %28, %20
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32*, i32** %7
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %34
br label %66
41: ; preds = %31
%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 %53
50: ; preds = %41
%51 = load i32*, i32** %7
%52 = call i32 @fclose(i32* %51)
br label %66
53: ; preds = %41
%54 = load i8**, i8*** %5
%55 = load i8*, i8** %54
%56 = load i32, i32* %8
%57 = load i32*, i32** %7
%58 = call i32 @fread(i8* %55, i32 %56, i32 1, i32* %57)
%59 = icmp ne i32 %58, 1
br i1 %59, label %60, label %63
60: ; preds = %53
%61 = load i32*, i32** %7
%62 = call i32 @fclose(i32* %61)
br label %66
63: ; preds = %53
%64 = load i32*, i32** %7
%65 = call i32 @fclose(i32* %64)
br label %66
66: ; preds = %63, %60, %50, %40, %19
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define void @FileLoad_NoError(i8* nocapture %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 %24, label %9
9: ; preds = %7
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %4, i32 0, i32 %10)
%12 = tail call i32 @ftell(i32* %4)
br i1 %5, label %14, label %13
13: ; preds = %9
store i32 %12, i32* %2
br label %14
14: ; preds = %13, %9
%15 = icmp eq i32 %12, 0
br i1 %15, label %22, label %16
16: ; preds = %14
%17 = tail call i32 @rewind(i32* %4)
%18 = tail call i8* @malloc(i32 %12)
store i8* %18, i8** %1
%19 = icmp eq i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @fread(i8* %18, i32 %12, i32 1, i32* %4)
br label %22
22: ; preds = %16, %14, %20
%23 = tail call i32 @fclose(i32* %4)
br label %24
24: ; preds = %22, %7
ret void
}