#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *readFile(const char *path) {
  int size;
  FILE *input;
  char *fileString;
  char c;
  int i;
  input = fopen(path, "rt");
  if (!input)
    return NULL;
  fseek(input, 0, SEEK_END);
  size = ftell(input);
  rewind(input);
  fileString = (char *)malloc(size + 1);
  i = 0;
  while (fscanf(input, "%c", &c) != EOF) {
    fileString[i] = c;
    i++;
  }
  fileString[size] = '\0';
  fclose(input);
  return fileString;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <readFile+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1244 <readFile+0xd4>
mov    -0x20(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe11(%rip),%rsi
lea    -0x29(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
je     1227 <readFile+0xb7>
mov    -0x29(%rbp),%dl
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e7 <readFile+0x77>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1234 <readFile+0xc4>
mov    %rax,%rbx
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <rewind@plt>
mov    %rbp,0x10(%rsp)
lea    0x1(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe31(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    0x2dfa(%rip),%rbp
cmp    0x0(%rbp),%rax
je     1220 <readFile+0xb0>
lea    0xe10(%rip),%r12
lea    0xf(%rsp),%r13
mov    %r15,%r14
nopl   0x0(%rax,%rax,1)
movzbl 0xf(%rsp),%eax
mov    %al,(%r14)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
add    $0x1,%r14
cmp    0x0(%rbp),%rax
jne    1200 <readFile+0x90>
movslq 0x10(%rsp),%rax
movb   $0x0,(%r15,%rax,1)
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1237 <readFile+0xc7>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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