#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 *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
unsigned char *_load_pdx_data(char *name, long *out_length) {
  int len;
  FILE *fp;
  unsigned char *buf = NULL;
  fp = fopen(name, "rb");
  if (!fp)
    return NULL;
  fseek(fp, 0, SEEK_END);
  len = (int)ftell(fp);
  fseek(fp, 0, SEEK_SET);
  buf = (unsigned char *)malloc(sizeof(unsigned char) * len);
  if (!buf) {
    goto error_end;
  }
  len = (int)fread(buf, 1, len, fp);
  if (len < 0) {
    goto error_end;
  }
  fclose(fp);
  *out_length = len;
  return buf;
error_end:
  if (fp)
    fclose(fp);
  if (buf)
    free(buf);
  return NULL;
}


x86 assembly (clang, -O0):
<_load_pdx_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b4 <_load_pdx_data+0x44>
movq   $0x0,-0x8(%rbp)
jmp    1283 <_load_pdx_data+0x113>
mov    -0x28(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120b <_load_pdx_data+0x9b>
jmp    1253 <_load_pdx_data+0xe3>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1232 <_load_pdx_data+0xc2>
jmp    1253 <_load_pdx_data+0xe3>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1283 <_load_pdx_data+0x113>
cmpq   $0x0,-0x28(%rbp)
je     1267 <_load_pdx_data+0xf7>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
je     127b <_load_pdx_data+0x10b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_load_pdx_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1215 <_load_pdx_data+0xa5>
mov    %rax,%rbx
mov    0x2e4e(%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    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r12d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1203 <_load_pdx_data+0x93>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   $0x80000000,%r12d
jne    120d <_load_pdx_data+0x9d>
movslq %r12d,%rax
mov    %rax,(%r14)
jmp    1218 <_load_pdx_data+0xa8>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1215 <_load_pdx_data+0xa5>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
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
define i8* @_load_pdx_data(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i8* null, i8** %8
%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** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i8* null, i8** %3
br label %62
14: ; preds = %2
%15 = load i32*, i32** %7
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %7
%19 = call i64 @ftell(i32* %18)
%20 = trunc i64 %19 to i32
store i32 %20, i32* %6
%21 = load i32*, i32** %7
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp ne i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %14
br label %49
33: ; preds = %14
%34 = load i8*, i8** %8
%35 = load i32, i32* %6
%36 = load i32*, i32** %7
%37 = call i64 @fread(i8* %34, i32 1, i32 %35, i32* %36)
%38 = trunc i64 %37 to i32
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
br label %49
42: ; preds = %33
%43 = load i32*, i32** %7
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = load i64*, i64** %5
store i64 %46, i64* %47
%48 = load i8*, i8** %8
store i8* %48, i8** %3
br label %62
49: ; preds = %41, %32
%50 = load i32*, i32** %7
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
br label %55
55: ; preds = %52, %49
%56 = load i8*, i8** %8
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i8*, i8** %8
%60 = call i32 @free(i8* %59)
br label %61
61: ; preds = %58, %55
store i8* null, i8** %3
br label %62
62: ; preds = %61, %42, %13
%63 = load i8*, i8** %3
ret i8* %63
}

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