#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 char FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(unsigned char *);
scalar_t__ calloc(long, int);
int /*<<< orphan*/ fread(unsigned char *, int, long, unsigned char *);
int /*<<< orphan*/ fseek(unsigned char *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(unsigned char *);
unsigned char *create_book_buffer(FILE *book_file) {
  assert(book_file);
  long length = 0;
  fseek(book_file, 0, SEEK_END);
  length = ftell(book_file);
  fseek(book_file, 0, SEEK_SET);
  unsigned char *rtr_val = (unsigned char *)calloc(length, sizeof(*rtr_val));
  assert(rtr_val);
  fread(rtr_val, sizeof(*rtr_val), length, book_file);
  fseek(book_file, 0, SEEK_SET);
  return rtr_val;
}


x86 assembly (clang, -O0):
<create_book_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <assert@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x8(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_book_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <assert@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r14
mov    0x2e53(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <assert@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @create_book_buffer(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @assert(i8* %5)
store i64 0, i64* %3
%7 = load i8*, i8** %2
%8 = load i32, i32* @SEEK_END
%9 = call i32 @fseek(i8* %7, i32 0, i32 %8)
%10 = load i8*, i8** %2
%11 = call i64 @ftell(i8* %10)
store i64 %11, i64* %3
%12 = load i8*, i8** %2
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i8* %12, i32 0, i32 %13)
%15 = load i64, i64* %3
%16 = call i64 @calloc(i64 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @assert(i8* %18)
%20 = load i8*, i8** %4
%21 = load i64, i64* %3
%22 = load i8*, i8** %2
%23 = call i32 @fread(i8* %20, i32 1, i64 %21, i8* %22)
%24 = load i8*, i8** %2
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i8* %24, i32 0, i32 %25)
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @create_book_buffer(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = load i32, i32* @SEEK_END
%4 = tail call i32 @fseek(i8* %0, i32 0, i32 %3)
%5 = tail call i64 @ftell(i8* %0)
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i8* %0, i32 0, i32 %6)
%8 = tail call i64 @calloc(i64 %5, i32 1)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @assert(i8* %9)
%11 = tail call i32 @fread(i8* %9, i32 1, i64 %5, i8* %0)
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i8* %0, i32 0, i32 %12)
ret i8* %9
}