#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 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*/ rewind(int /*<<< orphan*/ *);
char *textFileRead(const char *fn) {
  FILE *fp;
  char *content = NULL;
  int count = 0;
  if (fn != NULL) {
    fp = fopen(fn, "rt");
    if (fp != NULL) {
      fseek(fp, 0, SEEK_END);
      count = ftell(fp);
      rewind(fp);
      if (count > 0) {
        content = (char *)malloc(sizeof(char) * (count + 1));
        count = fread(content, sizeof(char), count, fp);
        content[count] = '\0';
      }
      fclose(fp);
    }
  }
  return content;
}


x86 assembly (clang, -O0):
<textFileRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1231 <textFileRead+0xc1>
mov    -0x8(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     122c <textFileRead+0xbc>
mov    -0x10(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    1223 <textFileRead+0xb3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1231 <textFileRead+0xc1>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<textFileRead>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     11e9 <textFileRead+0x79>
lea    0xe80(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11e9 <textFileRead+0x79>
mov    %rax,%rbx
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <rewind@plt>
test   %ebp,%ebp
jle    11df <textFileRead+0x6f>
mov    %ebp,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cltq
movb   $0x0,(%r14,%rax,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11ec <textFileRead+0x7c>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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