#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*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
void load_data(char filename[], char **data, int *data_sz) {
  FILE *fp = fopen(filename, "rb");
  if (fp == NULL) {
    *data_sz = -1;
    return;
  }
  fseek(fp, 0L, SEEK_END);
  *data_sz = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  *data = malloc((*data_sz) * sizeof(char));
  fread(*data, sizeof(char), *data_sz, fp);
  fclose(fp);
  return;
}


x86 assembly (clang, -O0):
<load_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <load_data+0x42>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    121f <load_data+0xbf>
mov    -0x20(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e3 <load_data+0x83>
mov    %rax,%rbx
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,(%r15)
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    (%r15),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
movl   $0xffffffff,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @load_data(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32*, i32** %6
store i32 -1, i32* %13
br label %39
14: ; preds = %3
%15 = load i32*, i32** %7
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i64 0, i32 %16)
%18 = load i32*, i32** %7
%19 = call i32 @ftell(i32* %18)
%20 = load i32*, i32** %6
store i32 %19, i32* %20
%21 = load i32*, i32** %7
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i64 0, i32 %22)
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
%30 = load i8**, i8*** %5
store i8* %29, i8** %30
%31 = load i8**, i8*** %5
%32 = load i8*, i8** %31
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = load i32*, i32** %7
%36 = call i32 @fread(i8* %32, i32 1, i32 %34, i32* %35)
%37 = load i32*, i32** %7
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %14, %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @load_data(i8* nocapture %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 %7
6: ; preds = %3
store i32 -1, i32* %2
br label %17
7: ; preds = %3
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %4, i64 0, i32 %8)
%10 = tail call i32 @ftell(i32* %4)
store i32 %10, i32* %2
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %4, i64 0, i32 %11)
%13 = load i32, i32* %2
%14 = tail call i8* @malloc(i32 %13)
store i8* %14, i8** %1
%15 = tail call i32 @fread(i8* %14, i32 1, i32 %13, i32* %4)
%16 = tail call i32 @fclose(i32* %4)
br label %17
17: ; preds = %7, %6
ret void
}