#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int serializer_read_from_file(char *readInto, int bufferSize,
                              const char *filename) {
  FILE *file = fopen(filename, "rb");
  char *buffer;
  int fileLength;
  fseek(file, 0, SEEK_END);
  fileLength = ftell(file);
  rewind(file);
  buffer = (char *)malloc(sizeof(char) * fileLength);
  fread(buffer, fileLength, 1, file);
  memcpy(readInto, buffer, bufferSize);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<serializer_read_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
movslq -0x2c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serializer_read_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xe6b(%rip),%rsi
mov    %rdx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbp,%rdi
call   1060 <ftell@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1050 <rewind@plt>
mov    %r12d,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <memcpy@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @serializer_read_from_file(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = load i32, i32* @SEEK_END
%14 = call i32 @fseek(i32* %12, i32 0, i32 %13)
%15 = load i32*, i32** %7
%16 = call i32 @ftell(i32* %15)
store i32 %16, i32* %9
%17 = load i32*, i32** %7
%18 = call i32 @rewind(i32* %17)
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = load i32, i32* %9
%27 = load i32*, i32** %7
%28 = call i32 @fread(i8* %25, i32 %26, i32 1, i32* %27)
%29 = load i8*, i8** %4
%30 = load i8*, i8** %8
%31 = load i32, i32* %5
%32 = call i32 @memcpy(i8* %29, i8* %30, i32 %31)
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @serializer_read_from_file(i8* %0, i32 %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %4, i32 0, i32 %5)
%7 = tail call i32 @ftell(i32* %4)
%8 = tail call i32 @rewind(i32* %4)
%9 = tail call i64 @malloc(i32 %7)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @fread(i8* %10, i32 %7, i32 1, i32* %4)
%12 = tail call i32 @memcpy(i8* %0, i8* %10, i32 %1)
%13 = tail call i32 @fclose(i32* %4)
ret i32 0
}