#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*/ uint8_t;
typedef long uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(long);
int /*<<< orphan*/ stderr;
uint8_t *readFile(char *name, uint64_t *sz) {
  FILE *f = fopen(name, "rb");
  fseek(f, 0, SEEK_END);
  long fsize = ftell(f);
  fseek(f, 0, SEEK_SET);
  fprintf(stderr, "Loading file %s: size %d\n", name, (int)fsize);
  uint8_t *res = malloc(fsize);
  fread(res, fsize, 1, f);
  fclose(f);
  *sz = fsize;
  return res;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
lea    0xe20(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe7b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r12
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
mov    %r15,%rdx
mov    %r12d,%ecx
call   1050 <fprintf@plt>
mov    %r12,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Loading file %s: size %d\0A\00"
define i32* @readFile(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32*
store i8* %0, i8** %3
store i64* %1, i64** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = load i32, i32* @SEEK_END
%12 = call i32 @fseek(i32* %10, i32 0, i32 %11)
%13 = load i32*, i32** %5
%14 = call i64 @ftell(i32* %13)
store i64 %14, i64* %6
%15 = load i32*, i32** %5
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = load i64, i64* %6
%21 = trunc i64 %20 to i32
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %21)
%23 = load i64, i64* %6
%24 = call i32* @malloc(i64 %23)
store i32* %24, i32** %7
%25 = load i32*, i32** %7
%26 = load i64, i64* %6
%27 = load i32*, i32** %5
%28 = call i32 @fread(i32* %25, i64 %26, i32 1, i32* %27)
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
%31 = load i64, i64* %6
%32 = load i64*, i64** %4
store i64 %31, i64* %32
%33 = load i32*, i32** %7
ret i32* %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Loading file %s: size %d\0A\00"
define noalias i32* @readFile(i8* %0, i64* 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 i64 @ftell(i32* %3)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %3, i32 0, i32 %7)
%9 = load i32, i32* @stderr
%10 = trunc i64 %6 to i32
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %10)
%12 = tail call i32* @malloc(i64 %6)
%13 = tail call i32 @fread(i32* %12, i64 %6, i32 1, i32* %3)
%14 = tail call i32 @fclose(i32* %3)
store i64 %6, i64* %1
ret i32* %12
}