#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(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
unsigned char *response_read_file(const char *filename, size_t *length) {
  FILE *file = fopen(filename, "rb");
  fseek(file, 0L, SEEK_END);
  *length = ftell(file);
  unsigned char *content = malloc(sizeof(unsigned char) * (*length + 1));
  rewind(file);
  fread(content, sizeof(unsigned char), *length, file);
  fclose(file);
  return content;
}


x86 assembly (clang, -O0):
<response_read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<response_read_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xe81(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,(%r14)
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    (%r14),%rdx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i8* @response_read_file(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %3
store i64* %1, i64** %4
%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** %5
%9 = load i32*, i32** %5
%10 = load i32, i32* @SEEK_END
%11 = call i32 @fseek(i32* %9, i64 0, i32 %10)
%12 = load i32*, i32** %5
%13 = call i64 @ftell(i32* %12)
%14 = load i64*, i64** %4
store i64 %13, i64* %14
%15 = load i64*, i64** %4
%16 = load i64, i64* %15
%17 = add i64 %16, 1
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %6
%21 = load i32*, i32** %5
%22 = call i32 @rewind(i32* %21)
%23 = load i8*, i8** %6
%24 = load i64*, i64** %4
%25 = load i64, i64* %24
%26 = load i32*, i32** %5
%27 = call i32 @fread(i8* %23, i32 1, i64 %25, i32* %26)
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %6
ret i8* %30
}

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