#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 FILENAME_MAX;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, 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*/ perror(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *ReadFile(char *pPath) {
  int fileLen = 0;
  FILE *fp;
  char buffer[FILENAME_MAX];
  char *file = malloc(10000 * sizeof(char));
  fp = fopen(pPath, "r");
  if (fp == NULL) {
    perror("Error opening file");
    return NULL;
  } else {
    fseek(fp, 0, SEEK_END);
    fileLen = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    fread(buffer, fileLen, 1, fp);
    fclose(fp);
  }
  strcat(buffer, "\nEND\n");
  strcpy(file, buffer);
  return file;
}


x86 assembly (clang, -O0):
<ReadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    $0x2710,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121c <ReadFile+0x8c>
lea    0xdff(%rip),%rdi
call   10a0 <perror@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    129a <ReadFile+0x10a>
mov    -0x20(%rbp),%rdi
mov    0x2dc1(%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
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
lea    0xd9c(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x48(%rbp),%rsi
mov    -0x38(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadFile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    $0x2710,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1252 <ReadFile+0xc2>
mov    %rax,%rbx
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%r12d
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xde6(%rip),%rsi
mov    %r15,%rdi
call   10b0 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda9(%rip),%rdi
call   10a0 <perror@plt>
xor    %r14d,%r14d
jmp    1242 <ReadFile+0xb2>

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

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [19 x i8] c"Error opening file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"\0AEND\0A\00"
define i8* @ReadFile(i8* nocapture %0) {
%2 = load i32, i32* @FILENAME_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call dereferenceable_or_null(10000) i8* @malloc(i32 10000)
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %20
10: ; preds = %1
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %6, i32 0, i32 %11)
%13 = tail call i32 @ftell(i32* %6)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %6, i32 0, i32 %14)
%16 = call i32 @fread(i8* %4, i32 %13, i32 1, i32* %6)
%17 = tail call i32 @fclose(i32* %6)
%18 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @strcpy(i8* %5, i8* %4)
br label %20
20: ; preds = %10, %8
%21 = phi i8* [ null, %8 ], [ %5, %10 ]
ret i8* %21
}