#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 */
struct stat {
  size_t st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, size_t, size_t, int /*<<< orphan*/ *);
void *malloc(size_t);
int /*<<< orphan*/ stat(char *, struct stat *);
size_t load_dat(char *filename, void **target, size_t item_size) {
  struct stat sb;
  stat(filename, &sb);
  *target = malloc(sb.st_size);
  FILE *f = fopen(filename, "rb");
  assert(fread(*target, item_size, sb.st_size / item_size, f));
  fclose(f);
  return sb.st_size / item_size;
}


x86 assembly (clang, -O0):
<load_dat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,%rdx
mov    -0x28(%rbp),%rcx
call   1030 <fread@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_dat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%rsi
call   1060 <stat@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,(%r12)
lea    0xe70(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    (%r12),%rdi
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
je     11b8 <load_dat+0x58>
mov    %rbx,%rax
xor    %edx,%edx
div    %r15
mov    %rax,%rbx
jmp    11c1 <load_dat+0x61>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%ebx
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [3 x i8] c"rb\00"
define i64 @load_dat(i8* %0, i8** %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca %struct.stat
%8 = alloca i32*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = call i32 @stat(i8* %9, %struct.stat* %7)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%12 = load i64, i64* %11
%13 = call i8* @malloc(i64 %12)
%14 = load i8**, i8*** %5
store i8* %13, i8** %14
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = load i64, i64* %6
%20 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%21 = load i64, i64* %20
%22 = load i64, i64* %6
%23 = udiv i64 %21, %22
%24 = load i32*, i32** %8
%25 = call i32 @fread(i8* %18, i64 %19, i64 %23, i32* %24)
%26 = call i32 @assert(i32 %25)
%27 = load i32*, i32** %8
%28 = call i32 @fclose(i32* %27)
%29 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* %6
%32 = udiv i64 %30, %31
ret i64 %32
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [3 x i8] c"rb\00"
define i64 @load_dat(i8* nocapture %0, i8** nocapture %1, i64 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i32 @stat(i8* %0, %struct.stat* %4)
%7 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%8 = load i64, i64* %7
%9 = tail call i8* @malloc(i64 %8)
store i8* %9, i8** %1
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %1
%12 = udiv i64 %8, %2
%13 = tail call i32 @fread(i8* %11, i64 %2, i64 %12, i32* %10)
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @fclose(i32* %10)
ret i64 %12
}