#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 unsigned int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(void *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
void *malloc(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
void LoadDataFile(const char *filename, unsigned *count, void **data,
                  uint32_t record_size) {
  FILE *fp;
  uint32_t ch;
  printf("Loading \"%s\" ... ", filename);
  fp = fopen(filename, "rb");
  if (fp) {
    fseek(fp, 0, SEEK_END);
    *count = ftell(fp) / record_size;
    fseek(fp, 0, SEEK_SET);
    for (ch = 0; ch < *count; ch++) {
      data[ch] = malloc(record_size);
      if (!data[ch]) {
        printf("Out of memory!\nHit [ENTER]");
        exit(1);
      }
      fread(data[ch], 1, record_size, fp);
    }
    fclose(fp);
  }
  printf("done!\n");
}


x86 assembly (clang, -O0):
<LoadDataFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     128f <LoadDataFile+0x10f>
mov    -0x28(%rbp),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ftell@plt>
xor    %edx,%edx
divl   -0x1c(%rbp)
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jae    1286 <LoadDataFile+0x106>
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
jne    125c <LoadDataFile+0xdc>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120d <LoadDataFile+0x8d>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LoadDataFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe56(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe57(%rip),%rsi
mov    %r12,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1246 <LoadDataFile+0xb6>
mov    %rax,%r12
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12,%rdi
call   1070 <ftell@plt>
xor    %edx,%edx
div    %ebp
mov    %eax,(%r15)
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
cmpl   $0x0,(%r15)
je     123e <LoadDataFile+0xae>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     125a <LoadDataFile+0xca>
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
add    $0x1,%rbx
mov    (%r15),%eax
cmp    %rax,%rbx
jb     1210 <LoadDataFile+0x80>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xde3(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
lea    0xdb4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Loading \22%s\22 ... \00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [27 x i8] c"Out of memory!\0AHit [ENTER]\00"
@.str.3 = [7 x i8] c"done!\0A\00"
define void @LoadDataFile(i8* %0, i32* %1, i8** %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %65
17: ; preds = %4
%18 = load i32*, i32** %9
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = load i32*, i32** %9
%22 = call i32 @ftell(i32* %21)
%23 = load i32, i32* %8
%24 = udiv i32 %22, %23
%25 = load i32*, i32** %6
store i32 %24, i32* %25
%26 = load i32*, i32** %9
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i32 0, i32 %27)
store i32 0, i32* %10
br label %29
29: ; preds = %59, %17
%30 = load i32, i32* %10
%31 = load i32*, i32** %6
%32 = load i32, i32* %31
%33 = icmp ult i32 %30, %32
br i1 %33, label %34, label %62
34: ; preds = %29
%35 = load i32, i32* %8
%36 = call i8* @malloc(i32 %35)
%37 = load i8**, i8*** %7
%38 = load i32, i32* %10
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
store i8* %36, i8** %40
%41 = load i8**, i8*** %7
%42 = load i32, i32* %10
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = icmp ne i8* %45, null
br i1 %46, label %50, label %47
47: ; preds = %34
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %34
%51 = load i8**, i8*** %7
%52 = load i32, i32* %10
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = load i32, i32* %8
%57 = load i32*, i32** %9
%58 = call i32 @fread(i8* %55, i32 1, i32 %56, i32* %57)
br label %59
59: ; preds = %50
%60 = load i32, i32* %10
%61 = add i32 %60, 1
store i32 %61, i32* %10
br label %29
62: ; preds = %29
%63 = load i32*, i32** %9
%64 = call i32 @fclose(i32* %63)
br label %65
65: ; preds = %62, %4
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"Loading \22%s\22 ... \00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [27 x i8] c"Out of memory!\0AHit [ENTER]\00"
@str = [6 x i8] c"done!\00"
define void @LoadDataFile(i8* %0, i32* nocapture %1, i8** nocapture writeonly %2, i32 %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %33, label %8
8: ; preds = %4
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %6, i32 0, i32 %9)
%11 = tail call i32 @ftell(i32* %6)
%12 = udiv i32 %11, %3
store i32 %12, i32* %1
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %6, i32 0, i32 %13)
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %8, %25
%18 = phi i64 [ %27, %25 ], [ 0, %8 ]
%19 = tail call i8* @malloc(i32 %3)
%20 = getelementptr inbounds i8*, i8** %2, i64 %18
store i8* %19, i8** %20
%21 = icmp eq i8* %19, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = tail call i32 @fread(i8* %19, i32 1, i32 %3, i32* %6)
%27 = add nuw nsw i64 %18, 1
%28 = load i32, i32* %1
%29 = zext i32 %28 to i64
%30 = icmp ult i64 %27, %29
br i1 %30, label %17, label %31
31: ; preds = %25, %8
%32 = tail call i32 @fclose(i32* %6)
br label %33
33: ; preds = %31, %4
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret void
}