#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 *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int loadFile(char *path, unsigned char **buffer) {
  FILE *f = fopen(path, "rb");
  fseek(f, 0, SEEK_END);
  int length = ftell(f);
  rewind(f);
  *buffer = malloc(length);
  fread(*buffer, 1, length, f);
  fclose(f);
  return length;
}


x86 assembly (clang, -O0):
<loadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xe82(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @loadFile(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = load i32, i32* @SEEK_END
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %5
%13 = call i32 @ftell(i32* %12)
store i32 %13, i32* %6
%14 = load i32*, i32** %5
%15 = call i32 @rewind(i32* %14)
%16 = load i32, i32* %6
%17 = call i8* @malloc(i32 %16)
%18 = load i8**, i8*** %4
store i8* %17, i8** %18
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = load i32, i32* %6
%22 = load i32*, i32** %5
%23 = call i32 @fread(i8* %20, i32 1, i32 %21, i32* %22)
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* %6
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @loadFile(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %3, i32 0, i32 %4)
%6 = tail call i32 @ftell(i32* %3)
%7 = tail call i32 @rewind(i32* %3)
%8 = tail call i8* @malloc(i32 %6)
store i8* %8, i8** %1
%9 = tail call i32 @fread(i8* %8, i32 1, i32 %6, i32* %3)
%10 = tail call i32 @fclose(i32* %3)
ret i32 %6
}