#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 */
char *createDiskData();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long long fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *loadDataFromDiskFile(char *fileName) {
  char *diskData;
  long long bytesRead;
  FILE *diskFile = fopen(fileName, "rb");
  if (diskFile == NULL)
    return NULL;
  diskData = createDiskData();
  bytesRead = fread(diskData, sizeof(char), (32 * 64 * 256), diskFile);
  if (!bytesRead || bytesRead != (32 * 64 * 256)) {
    if (diskFile)
      fclose(diskFile);
    free(diskData);
    return NULL;
  }
  fclose(diskFile);
  return diskData;
}


x86 assembly (clang, -O0):
<loadDataFromDiskFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1188 <loadDataFromDiskFile+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1202 <loadDataFromDiskFile+0xb2>
mov    $0x0,%al
call   1060 <createDiskData@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80000,%edx
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c7 <loadDataFromDiskFile+0x77>
cmpq   $0x80000,-0x20(%rbp)
je     11f1 <loadDataFromDiskFile+0xa1>
cmpq   $0x0,-0x28(%rbp)
je     11db <loadDataFromDiskFile+0x8b>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1202 <loadDataFromDiskFile+0xb2>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadDataFromDiskFile>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a4 <loadDataFromDiskFile+0x54>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <createDiskData@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x80000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    $0x80000,%r15
je     11a7 <loadDataFromDiskFile+0x57>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i8* @loadDataFromDiskFile(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = tail call i8* (...) @createDiskData()
%6 = tail call i64 @fread(i8* %5, i32 1, i32 524288, i32* %2)
%7 = icmp eq i64 %6, 524288
%8 = tail call i32 @fclose(i32* %2)
br i1 %7, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @free(i8* %5)
br label %11
11: ; preds = %4, %1, %9
%12 = phi i8* [ null, %9 ], [ null, %1 ], [ %5, %4 ]
ret i8* %12
}