#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned int fread(char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
char *malloc(unsigned int);
int /*<<< orphan*/ printf(char *);
char *fileAsString(FILE *file) {
  unsigned int length;
  char *contents = NULL;
  if (file) {
    fseek(file, 0, SEEK_END);
    length = ftell(file);
    fseek(file, 0, SEEK_SET);
    contents = malloc(length + 1);
    if (contents && length == fread(contents, 1, length, file))
      printf("Read file.\n");
    fclose(file);
    contents[length] = 0;
  }
  return contents;
}


x86 assembly (clang, -O0):
<fileAsString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1215 <fileAsString+0xb5>
mov    -0x8(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1201 <fileAsString+0xa1>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jne    1201 <fileAsString+0xa1>
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileAsString>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11e2 <fileAsString+0x82>
mov    %rdi,%rbx
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%r14d
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x1(%r14),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11d0 <fileAsString+0x70>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    %eax,%r14d
jne    11d0 <fileAsString+0x70>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14d,%eax
movb   $0x0,(%r15,%rax,1)
jmp    11e5 <fileAsString+0x85>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str = [12 x i8] c"Read file.\0A\00"
define i8* @fileAsString(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
store i32* %0, i32** %2
store i8* null, i8** %4
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %37
7: ; preds = %1
%8 = load i32*, i32** %2
%9 = load i32, i32* @SEEK_END
%10 = call i32 @fseek(i32* %8, i32 0, i32 %9)
%11 = load i32*, i32** %2
%12 = call i32 @ftell(i32* %11)
store i32 %12, i32* %3
%13 = load i32*, i32** %2
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseek(i32* %13, i32 0, i32 %14)
%16 = load i32, i32* %3
%17 = add i32 %16, 1
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %30
21: ; preds = %7
%22 = load i32, i32* %3
%23 = load i8*, i8** %4
%24 = load i32, i32* %3
%25 = load i32*, i32** %2
%26 = call i32 @fread(i8* %23, i32 1, i32 %24, i32* %25)
%27 = icmp eq i32 %22, %26
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %21, %7
%31 = load i32*, i32** %2
%32 = call i32 @fclose(i32* %31)
%33 = load i8*, i8** %4
%34 = load i32, i32* %3
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %30, %1
%38 = load i8*, i8** %4
ret i8* %38
}

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