#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);
char *afs_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 ((*((unsigned int *)(pstrBuffer + 0x00))) != 0x00534641) {
    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):
<afs_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    11a4 <afs_load+0x34>
movq   $0x0,-0x8(%rbp)
jmp    12e6 <afs_load+0x176>
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <afs_load+0x60>
movq   $0x0,-0x8(%rbp)
jmp    12e6 <afs_load+0x176>
mov    -0x18(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11ff <afs_load+0x8f>
jmp    12d5 <afs_load+0x165>
mov    -0x28(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121b <afs_load+0xab>
jmp    12d5 <afs_load+0x165>
mov    -0x18(%rbp),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <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     1269 <afs_load+0xf9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    12d5 <afs_load+0x165>
mov    -0x20(%rbp),%rax
cmpl   $0x534641,(%rax)
je     128f <afs_load+0x11f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    12d5 <afs_load+0x165>
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     12d0 <afs_load+0x160>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    12d5 <afs_load+0x165>
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):
<afs_load>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     122e <afs_load+0xbe>
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     122e <afs_load+0xbe>
mov    %rax,%r14
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1060 <ftell@plt>
cmp    $0x4,%eax
jl     1224 <afs_load+0xb4>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1222 <afs_load+0xb2>
mov    %rax,%rbx
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    $0x4,%eax
jne    121a <afs_load+0xaa>
cmpl   $0x534641,(%rbx)
jne    121a <afs_load+0xaa>
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     1224 <afs_load+0xb4>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    1230 <afs_load+0xc0>
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* @afs_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 %72
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 %72
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 %68
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 %68
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 %68
44: ; preds = %32
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = bitcast i8* %46 to i32*
%48 = load i32, i32* %47
%49 = icmp ne i32 %48, 5457473
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = load i8*, i8** %5
%52 = call i32 @free(i8* %51)
store i8* null, i8** %5
br label %68
53: ; preds = %44
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i64 4
%56 = load i32, i32* %7
%57 = sub nsw i32 %56, 4
%58 = load i32*, i32** %4
%59 = call i32 @fread(i8* %55, i32 1, i32 %57, i32* %58)
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = sub nsw i32 %61, 4
%63 = icmp ne i32 %60, %62
br i1 %63, label %64, label %67
64: ; preds = %53
%65 = load i8*, i8** %5
%66 = call i32 @free(i8* %65)
store i8* null, i8** %5
br label %67
67: ; preds = %64, %53
br label %68
68: ; preds = %67, %50, %41, %31, %25
%69 = load i32*, i32** %4
%70 = call i32 @fclose(i32* %69)
%71 = load i8*, i8** %5
store i8* %71, i8** %2
br label %72
72: ; preds = %68, %16, %10
%73 = load i8*, i8** %2
ret i8* %73
}

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