#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 fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ nbl_is_nmll(char *);
char *nbl_load(char *pstrFilename) {
  FILE *pFile = NULL;
  char *pstrBuffer = NULL;
  int iRead, iSize;
  if (pstrFilename == NULL)
    return NULL;
  pFile = fopen(pstrFilename, "rb");
  if (pFile == NULL)
    return NULL;
  fseek(pFile, 0, SEEK_END);
  iSize = ftell(pFile);
  if (iSize < 4)
    goto nbl_load_ret;
  pstrBuffer = malloc(iSize);
  if (pstrBuffer == NULL)
    goto nbl_load_ret;
  fseek(pFile, 0, SEEK_SET);
  iRead = fread(pstrBuffer, sizeof(char), 4, pFile);
  if (iRead != 4) {
    free(pstrBuffer);
    pstrBuffer = NULL;
    goto nbl_load_ret;
  }
  if (!nbl_is_nmll(pstrBuffer)) {
    free(pstrBuffer);
    pstrBuffer = NULL;
    goto nbl_load_ret;
  }
  iRead = fread(pstrBuffer + 4, sizeof(char), iSize - 4, pFile);
  if (iRead != iSize - 4) {
    free(pstrBuffer);
    pstrBuffer = NULL;
  }
nbl_load_ret:
  fclose(pFile);
  return pstrBuffer;
}


x86 assembly (clang, -O0):
<nbl_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <nbl_load+0x34>
movq   $0x0,-0x8(%rbp)
jmp    12f8 <nbl_load+0x178>
mov    -0x10(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <nbl_load+0x60>
movq   $0x0,-0x8(%rbp)
jmp    12f8 <nbl_load+0x178>
mov    -0x18(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    120f <nbl_load+0x8f>
jmp    12e7 <nbl_load+0x167>
mov    -0x28(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122b <nbl_load+0xab>
jmp    12e7 <nbl_load+0x167>
mov    -0x18(%rbp),%rdi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
je     1279 <nbl_load+0xf9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    12e7 <nbl_load+0x167>
mov    -0x20(%rbp),%rdi
call   1060 <nbl_is_nmll@plt>
cmp    $0x0,%eax
jne    12a1 <nbl_load+0x121>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    12e7 <nbl_load+0x167>
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x28(%rbp),%edx
sub    $0x4,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
je     12e2 <nbl_load+0x162>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    12e7 <nbl_load+0x167>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nbl_load>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1242 <nbl_load+0xc2>
lea    0xe6c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1242 <nbl_load+0xc2>
mov    %rax,%r14
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1070 <ftell@plt>
cmp    $0x4,%eax
jl     1238 <nbl_load+0xb8>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1236 <nbl_load+0xb6>
mov    %rax,%rbx
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    $0x4,%eax
jne    122e <nbl_load+0xae>
mov    %rbx,%rdi
call   1060 <nbl_is_nmll@plt>
test   %eax,%eax
je     122e <nbl_load+0xae>
mov    %rbx,%rdi
add    $0x4,%rdi
add    $0xfffffffc,%ebp
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    %ebp,%eax
je     1238 <nbl_load+0xb8>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    1244 <nbl_load+0xc4>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @nbl_load(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %32, label %3
3: ; preds = %1
%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 %32, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %4, i32 0, i32 %7)
%9 = tail call i32 @ftell(i32* %4)
%10 = icmp slt i32 %9, 4
br i1 %10, label %29, label %11
11: ; preds = %6
%12 = tail call i8* @malloc(i32 %9)
%13 = icmp eq i8* %12, null
br i1 %13, label %29, label %14
14: ; preds = %11
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %4, i32 0, i32 %15)
%17 = tail call i32 @fread(i8* %12, i32 1, i32 4, i32* %4)
%18 = icmp eq i32 %17, 4
br i1 %18, label %19, label %27
19: ; preds = %14
%20 = tail call i32 @nbl_is_nmll(i8* %12)
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %12, i64 4
%24 = add nsw i32 %9, -4
%25 = tail call i32 @fread(i8* %23, i32 1, i32 %24, i32* %4)
%26 = icmp eq i32 %25, %24
br i1 %26, label %29, label %27
27: ; preds = %22, %19, %14
%28 = tail call i32 @free(i8* %12)
br label %29
29: ; preds = %27, %22, %11, %6
%30 = phi i8* [ null, %6 ], [ null, %11 ], [ %12, %22 ], [ null, %27 ]
%31 = tail call i32 @fclose(i32* %4)
br label %32
32: ; preds = %3, %1, %29
%33 = phi i8* [ %30, %29 ], [ null, %1 ], [ null, %3 ]
ret i8* %33
}