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


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    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f5 <load_file_data+0x85>
cmpq   $0x0,-0x28(%rbp)
je     11d0 <load_file_data+0x60>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe3d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11e9 <load_file_data+0x79>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1288 <load_file_data+0x118>
mov    -0x30(%rbp),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    125d <load_file_data+0xed>
movl   $0x1,-0x4(%rbp)
jmp    1288 <load_file_data+0x118>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-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   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11fc <load_file_data+0x8c>
mov    %rax,%rbx
mov    0x2e49(%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    %eax,(%r12)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    (%r12),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1225 <load_file_data+0xb5>
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    122b <load_file_data+0xbb>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
test   %r15,%r15
je     1216 <load_file_data+0xa6>
lea    0xdf2(%rip),%rsi
mov    %r15,%rdx
jmp    1220 <load_file_data+0xb0>
lea    0xe14(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"LOAD_FILE_DATA: Could not open library \22%s\22.\0A\00"
@.str.2 = [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
define i32 @load_file_data(i8* %0, i8** nocapture writeonly %1, i32* nocapture %2, i8* %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = icmp eq i8* %3, null
%9 = load i32, i32* @stderr
br i1 %8, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %26
12: ; preds = %7
%13 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %26
14: ; preds = %4
%15 = load i32, i32* @SEEK_END
%16 = tail call i32 @fseek(i32* %5, i32 0, i32 %15)
%17 = tail call i32 @ftell(i32* %5)
store i32 %17, i32* %2
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %5, i32 0, i32 %18)
%20 = load i32, i32* %2
%21 = tail call i8* @malloc(i32 %20)
store i8* %21, i8** %1
%22 = icmp eq i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %14
%24 = tail call i32 @fread(i8* %21, i32 1, i32 %20, i32* %5)
%25 = tail call i32 @fclose(i32* %5)
br label %26
26: ; preds = %14, %10, %12, %23
%27 = phi i32 [ 0, %23 ], [ 1, %12 ], [ 1, %10 ], [ 1, %14 ]
ret i32 %27
}