#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*/ assert(int);
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*/ *);
char *malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *file_content(const char *filename, int *length) {
  assert(filename && length);
  FILE *file = fopen(filename, "r");
  if (!file)
    return 0;
  fseek(file, 0, SEEK_END);
  *length = ftell(file);
  rewind(file);
  char *data = malloc(sizeof(char) * *length);
  fread(data, sizeof(char), *length, file);
  fclose(file);
  return data;
}


x86 assembly (clang, -O0):
<file_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x29(%rbp)
je     11ab <file_content+0x2b>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <file_content+0x64>
movq   $0x0,-0x8(%rbp)
jmp    1251 <file_content+0xd1>
mov    -0x20(%rbp),%rdi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_content>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1206 <file_content+0x86>
mov    %rax,%rbx
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    (%r14),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1209 <file_content+0x89>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i8* @file_content(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br label %13
13: ; preds = %10, %2
%14 = phi i1 [ false, %2 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %13
store i8* null, i8** %3
br label %45
22: ; preds = %13
%23 = load i32*, i32** %6
%24 = load i32, i32* @SEEK_END
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = load i32*, i32** %6
%27 = call i32 @ftell(i32* %26)
%28 = load i32*, i32** %5
store i32 %27, i32* %28
%29 = load i32*, i32** %6
%30 = call i32 @rewind(i32* %29)
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = load i32*, i32** %5
%39 = load i32, i32* %38
%40 = load i32*, i32** %6
%41 = call i32 @fread(i8* %37, i32 1, i32 %39, i32* %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = load i8*, i8** %7
store i8* %44, i8** %3
br label %45
45: ; preds = %22, %21
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define noalias i8* @file_content(i8* %0, i32* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i32* %1, null
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %19, label %10
10: ; preds = %2
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %8, i32 0, i32 %11)
%13 = tail call i32 @ftell(i32* %8)
store i32 %13, i32* %1
%14 = tail call i32 @rewind(i32* %8)
%15 = load i32, i32* %1
%16 = tail call i8* @malloc(i32 %15)
%17 = tail call i32 @fread(i8* %16, i32 1, i32 %15, i32* %8)
%18 = tail call i32 @fclose(i32* %8)
br label %19
19: ; preds = %2, %10
%20 = phi i8* [ %16, %10 ], [ null, %2 ]
ret i8* %20
}