#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 */
scalar_t__ BUFSIZ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
long fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
scalar_t__ strnlen(char const *, scalar_t__);
unsigned char *load_file(size_t *load_len, const char *filename) {
  if (strnlen(filename, BUFSIZ) == BUFSIZ) {
    ;
    *load_len = 0;
    return "";
  }
  long size = 0;
  FILE *fd = fopen(filename, "rb");
  if (fd == NULL) {
    ;
    *load_len = 0;
    return "";
  }
  if ((0 != fseek(fd, 0, SEEK_END)) || (-1 == (size = ftell(fd)))) {
    ;
    fclose(fd);
    *load_len = 0;
    return "";
  } else {
    fclose(fd);
  }
  if (size == 0) {
    ;
    *load_len = 0;
    return "";
  }
  unsigned char *buffer = (unsigned char *)malloc(size);
  if (buffer == NULL) {
    ;
    *load_len = 0;
    return "";
  }
  fd = fopen(filename, "rb");
  if (fd == NULL) {
    ;
    free(buffer);
    *load_len = 0;
    return "";
  }
  if (size != fread(buffer, 1, size, fd)) {
    ;
    free(buffer);
    fclose(fd);
    *load_len = 0;
    return "";
  } else {
    fclose(fd);
    *load_len = size;
    return buffer;
  }
}


x86 assembly (clang, -O0):
<load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%rsi
call   1060 <strnlen@plt>
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%rax
jne    11ce <load_file+0x4e>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xe3d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1392 <load_file+0x212>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1210 <load_file+0x90>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xdfb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1392 <load_file+0x212>
mov    -0x28(%rbp),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1252 <load_file+0xd2>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    1276 <load_file+0xf6>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xd95(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1392 <load_file+0x212>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12a5 <load_file+0x125>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xd66(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1392 <load_file+0x212>
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12d8 <load_file+0x158>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xd33(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1392 <load_file+0x212>
mov    -0x18(%rbp),%rdi
lea    0xd1d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    131b <load_file+0x19b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xcf0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1392 <load_file+0x212>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     1376 <load_file+0x1f6>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xc95(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1392 <load_file+0x212>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r14
mov    0x2e40(%rip),%rax
mov    (%rax),%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1060 <strnlen@plt>
lea    0xe55(%rip),%r15
cmp    %rbx,%rax
je     11e9 <load_file+0x69>
lea    0xe47(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11e9 <load_file+0x69>
mov    %rax,%rbx
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rax,%rax
je     1201 <load_file+0x81>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %r12d,%r12d
mov    %r12,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1070 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     11e1 <load_file+0x61>
mov    %rax,%r12
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %r12,%r12
je     11e9 <load_file+0x69>
mov    %r12,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     11e9 <load_file+0x69>
mov    %rax,%r13
lea    0xdca(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     126b <load_file+0xeb>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    %rax,%r12
jne    1278 <load_file+0xf8>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r13,%r15
jmp    11ec <load_file+0x6c>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11e9 <load_file+0x69>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11e1 <load_file+0x61>

LLVM IR (-O0):
@BUFSIZ = global i64 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i8* @load_file(i64* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i8*
store i64* %0, i64** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = load i64, i64* @BUFSIZ
%11 = call i64 @strnlen(i8* %9, i64 %10)
%12 = load i64, i64* @BUFSIZ
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i64*, i64** %4
store i64 0, i64* %15
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %80
16: ; preds = %2
store i64 0, i64* %6
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i64*, i64** %4
store i64 0, i64* %22
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %80
23: ; preds = %16
%24 = load i32*, i32** %7
%25 = load i32, i32* @SEEK_END
%26 = call i64 @fseek(i32* %24, i32 0, i32 %25)
%27 = icmp ne i64 0, %26
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = load i32*, i32** %7
%30 = call i64 @ftell(i32* %29)
store i64 %30, i64* %6
%31 = icmp eq i64 -1, %30
br i1 %31, label %32, label %36
32: ; preds = %28, %23
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
%35 = load i64*, i64** %4
store i64 0, i64* %35
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %80
36: ; preds = %28
%37 = load i32*, i32** %7
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36
%40 = load i64, i64* %6
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i64*, i64** %4
store i64 0, i64* %43
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %80
44: ; preds = %39
%45 = load i64, i64* %6
%46 = call i64 @malloc(i64 %45)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %8
%48 = load i8*, i8** %8
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = load i64*, i64** %4
store i64 0, i64* %51
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %80
52: ; preds = %44
%53 = load i8*, i8** %5
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %54, i32** %7
%55 = load i32*, i32** %7
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %61
57: ; preds = %52
%58 = load i8*, i8** %8
%59 = call i32 @free(i8* %58)
%60 = load i64*, i64** %4
store i64 0, i64* %60
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %80
61: ; preds = %52
%62 = load i64, i64* %6
%63 = load i8*, i8** %8
%64 = load i64, i64* %6
%65 = load i32*, i32** %7
%66 = call i64 @fread(i8* %63, i32 1, i64 %64, i32* %65)
%67 = icmp ne i64 %62, %66
br i1 %67, label %68, label %74
68: ; preds = %61
%69 = load i8*, i8** %8
%70 = call i32 @free(i8* %69)
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
%73 = load i64*, i64** %4
store i64 0, i64* %73
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %80
74: ; preds = %61
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
%77 = load i64, i64* %6
%78 = load i64*, i64** %4
store i64 %77, i64* %78
%79 = load i8*, i8** %8
store i8* %79, i8** %3
br label %80
80: ; preds = %74, %68, %57, %50, %42, %32, %21, %14
%81 = load i8*, i8** %3
ret i8* %81
}

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