#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*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_END;
char *calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *read_entire_file(FILE *file) {
  fseek(file, 0L, SEEK_END);
  int file_len = ftell(file);
  rewind(file);
  char *contents = calloc(file_len + 1, sizeof(char));
  if (!contents) {
    printf("Could not allocate memory\n");
    exit(EXIT_FAILURE);
  }
  fread(contents, file_len, 1, file);
  return contents;
}


x86 assembly (clang, -O0):
<read_entire_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <read_entire_file+0x70>
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_entire_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1070 <ftell@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1050 <rewind@plt>
lea    0x1(%r14),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11cd <read_entire_file+0x5d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [27 x i8] c"Could not allocate memory\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @read_entire_file(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = load i32, i32* @SEEK_END
%7 = call i32 @fseek(i32* %5, i64 0, i32 %6)
%8 = load i32*, i32** %2
%9 = call i32 @ftell(i32* %8)
store i32 %9, i32* %3
%10 = load i32*, i32** %2
%11 = call i32 @rewind(i32* %10)
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = call i8* @calloc(i32 %13, i32 1)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %1
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %1
%22 = load i8*, i8** %4
%23 = load i32, i32* %3
%24 = load i32*, i32** %2
%25 = call i32 @fread(i8* %22, i32 %23, i32 1, i32* %24)
%26 = load i8*, i8** %4
ret i8* %26
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@EXIT_FAILURE = global i32 0
@str = [26 x i8] c"Could not allocate memory\00"
define noalias i8* @read_entire_file(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i32 @fseek(i32* %0, i64 0, i32 %2)
%4 = tail call i32 @ftell(i32* %0)
%5 = tail call i32 @rewind(i32* %0)
%6 = add nsw i32 %4, 1
%7 = tail call i8* @calloc(i32 %6, i32 1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = tail call i32 @fread(i8* %7, i32 %4, i32 1, i32* %0)
ret i8* %7
}