#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 *, 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_NoError(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)
    return;
  fseek(f, 0, SEEK_END);
  size = ftell(f);
  if (size_)
    *size_ = size;
  if (size == 0) {
    fclose(f);
    return;
  }
  rewind(f);
  *buffer = malloc(size);
  if (*buffer == NULL) {
    fclose(f);
    return;
  }
  if (fread(*buffer, size, 1, f) != 1) {
    fclose(f);
    free(*buffer);
    return;
  }
  fclose(f);
}


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    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11c9 <FileLoad_NoError+0x49>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
jne    11d9 <FileLoad_NoError+0x59>
jmp    12a6 <FileLoad_NoError+0x126>
mov    -0x20(%rbp),%rdi
mov    0x2e04(%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     1210 <FileLoad_NoError+0x90>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    1229 <FileLoad_NoError+0xa9>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12a6 <FileLoad_NoError+0x126>
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    1261 <FileLoad_NoError+0xe1>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12a6 <FileLoad_NoError+0x126>
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     129d <FileLoad_NoError+0x11d>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
jmp    12a6 <FileLoad_NoError+0x126>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileLoad_NoError>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xe6b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
movq   $0x0,(%r14)
test   %rbx,%rbx
je     11b0 <FileLoad_NoError+0x30>
movq   $0x0,(%rbx)
test   %r15,%r15
je     121a <FileLoad_NoError+0x9a>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   1070 <ftell@plt>
mov    %rax,%r12
test   %rbx,%rbx
je     11db <FileLoad_NoError+0x5b>
mov    %r12,(%rbx)
test   %r12,%r12
je     1226 <FileLoad_NoError+0xa6>
mov    %r15,%rdi
call   1060 <rewind@plt>
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1226 <FileLoad_NoError+0xa6>
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <fclose@plt>
cmp    $0x1,%ebx
jne    1239 <FileLoad_NoError+0xb9>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>
mov    (%r14),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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