#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long fread(int /*<<< orphan*/ *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
uint8_t *ReadEntireFile(char *name, long *pSize) {
  uint8_t *buf;
  long size;
  FILE *fp;
  if (!(fp = fopen(name, "rb")))
    return NULL;
  fseek(fp, 0L, SEEK_END);
  size = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  if (!(buf = (uint8_t *)malloc(size))) {
    fclose(fp);
    return NULL;
  }
  if (fread(buf, 1, size, fp) != size) {
    free(buf);
    fclose(fp);
    return NULL;
  }
  *pSize = size;
  fclose(fp);
  return buf;
}


x86 assembly (clang, -O0):
<ReadEntireFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ab <ReadEntireFile+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    126c <ReadEntireFile+0xfc>
mov    -0x30(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1211 <ReadEntireFile+0xa1>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    126c <ReadEntireFile+0xfc>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x28(%rbp),%rax
je     1250 <ReadEntireFile+0xe0>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    126c <ReadEntireFile+0xfc>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadEntireFile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
lea    0xe7d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f4 <ReadEntireFile+0x84>
mov    %rax,%rbx
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r12
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r12,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1204 <ReadEntireFile+0x94>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    %r12,%rax
jne    11f9 <ReadEntireFile+0x89>
mov    %r12,(%r14)
mov    %r13,%r15
jmp    1204 <ReadEntireFile+0x94>
xor    %r15d,%r15d
jmp    120c <ReadEntireFile+0x9c>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
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
define i32* @ReadEntireFile(i8* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
store i8* %0, i8** %4
store i64* %1, i64** %5
%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** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32* null, i32** %3
br label %47
13: ; preds = %2
%14 = load i32*, i32** %8
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i64 0, i32 %15)
%17 = load i32*, i32** %8
%18 = call i64 @ftell(i32* %17)
store i64 %18, i64* %7
%19 = load i32*, i32** %8
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %19, i64 0, i32 %20)
%22 = load i64, i64* %7
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i32*
store i32* %24, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %13
%27 = load i32*, i32** %8
%28 = call i32 @fclose(i32* %27)
store i32* null, i32** %3
br label %47
29: ; preds = %13
%30 = load i32*, i32** %6
%31 = load i64, i64* %7
%32 = load i32*, i32** %8
%33 = call i64 @fread(i32* %30, i32 1, i64 %31, i32* %32)
%34 = load i64, i64* %7
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load i32*, i32** %6
%38 = call i32 @free(i32* %37)
%39 = load i32*, i32** %8
%40 = call i32 @fclose(i32* %39)
store i32* null, i32** %3
br label %47
41: ; preds = %29
%42 = load i64, i64* %7
%43 = load i64*, i64** %5
store i64 %42, i64* %43
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
%46 = load i32*, i32** %6
store i32* %46, i32** %3
br label %47
47: ; preds = %41, %36, %26, %12
%48 = load i32*, i32** %3
ret i32* %48
}

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