#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*/ SEEK_SET;
unsigned char *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int load_file_data(char *file_name, unsigned char **data, int *size) {
  FILE *fop;
  fop = fopen(file_name, "rb");
  if (fop == NULL) {
    fprintf(stderr, "LOAD_FILE_DATA: Could not open file \"%s\".\n", file_name);
    return 0;
  }
  fseek(fop, 0, SEEK_END);
  *size = (int)ftell(fop);
  fseek(fop, 0, SEEK_SET);
  *data = calloc(*size, 1);
  if (*data == NULL) {
    fclose(fop);
    return 0;
  }
  if (fread(*data, 1, *size, fop) != (size_t)*size) {
    fprintf(stderr, "LOAD_FILE_DATA: Could not read all %d bytes of \"%s\"!",
            *size, file_name);
    return 0;
  }
  fclose(fop);
  return 1;
}


x86 assembly (clang, -O0):
<load_file_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ca <load_file_data+0x5a>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a8 <load_file_data+0x138>
mov    -0x28(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
mov    0x2dd6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1240 <load_file_data+0xd0>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a8 <load_file_data+0x138>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
je     1298 <load_file_data+0x128>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a8 <load_file_data+0x138>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1211 <load_file_data+0xa1>
mov    %rax,%rbp
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbp,%rdi
call   1070 <ftell@plt>
mov    %eax,0x0(%r13)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    0x0(%r13),%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1207 <load_file_data+0x97>
mov    $0x1,%r15d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
movslq 0x0(%r13),%rdx
cmp    %rdx,%rax
jne    1230 <load_file_data+0xc0>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    124d <load_file_data+0xdd>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
xor    %r15d,%r15d
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    124d <load_file_data+0xdd>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
xor    %r15d,%r15d
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"LOAD_FILE_DATA: Could not open file \22%s\22.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [53 x i8] c"LOAD_FILE_DATA: Could not read all %d bytes of \22%s\22!\00"
define i32 @load_file_data(i8* %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%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 = load i32*, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %5
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 0, i32* %4
br label %58
17: ; preds = %3
%18 = load i32*, i32** %8
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = load i32*, i32** %8
%22 = call i64 @ftell(i32* %21)
%23 = trunc i64 %22 to i32
%24 = load i32*, i32** %7
store i32 %23, i32* %24
%25 = load i32*, i32** %8
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = call i8* @calloc(i32 %29, i32 1)
%31 = load i8**, i8*** %6
store i8* %30, i8** %31
%32 = load i8**, i8*** %6
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %17
%36 = load i32*, i32** %8
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %4
br label %58
38: ; preds = %17
%39 = load i8**, i8*** %6
%40 = load i8*, i8** %39
%41 = load i32*, i32** %7
%42 = load i32, i32* %41
%43 = load i32*, i32** %8
%44 = call i64 @fread(i8* %40, i32 1, i32 %42, i32* %43)
%45 = load i32*, i32** %7
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = icmp ne i64 %44, %47
br i1 %48, label %49, label %55
49: ; preds = %38
%50 = load i32, i32* @stderr
%51 = load i32*, i32** %7
%52 = load i32, i32* %51
%53 = load i8*, i8** %5
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %52, i8* %53)
store i32 0, i32* %4
br label %58
55: ; preds = %38
%56 = load i32*, i32** %8
%57 = call i32 @fclose(i32* %56)
store i32 1, i32* %4
br label %58
58: ; preds = %55, %49, %35, %13
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"LOAD_FILE_DATA: Could not open file \22%s\22.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [53 x i8] c"LOAD_FILE_DATA: Could not read all %d bytes of \22%s\22!\00"
define i32 @load_file_data(i8* %0, i8** nocapture writeonly %1, i32* nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %31
9: ; preds = %3
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %4, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %4)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %2
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %4, i32 0, i32 %14)
%16 = load i32, i32* %2
%17 = tail call i8* @calloc(i32 %16, i32 1)
store i8* %17, i8** %1
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = tail call i32 @fclose(i32* %4)
br label %31
21: ; preds = %9
%22 = tail call i64 @fread(i8* %17, i32 1, i32 %16, i32* %4)
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = icmp eq i64 %22, %24
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %0)
br label %31
29: ; preds = %21
%30 = tail call i32 @fclose(i32* %4)
br label %31
31: ; preds = %29, %26, %19, %6
%32 = phi i32 [ 0, %6 ], [ 0, %19 ], [ 0, %26 ], [ 1, %29 ]
ret i32 %32
}