#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char path[4096];
  printf("Please enter path to file: ");
  scanf("%s", path);
  FILE *file = fopen(path, "r");
  char buffer[4096 + 1];
  if (file) {
    while (!feof(file)) {
      int readBytes = fread(buffer, 1, 4096, file);
      buffer[readBytes] = '\0';
      printf("%s", buffer);
    }
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x1010(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
je     1232 <main+0xd2>
jmp    11c0 <main+0x60>
mov    -0x1018(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e1 <main+0x81>
jmp    122d <main+0xcd>
lea    -0x2020(%rbp),%rdi
mov    -0x1018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x2024(%rbp)
movslq -0x2024(%rbp),%rax
movb   $0x0,-0x2020(%rbp,%rax,1)
lea    -0x2020(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11c0 <main+0x60>
jmp    1232 <main+0xd2>
mov    -0x1018(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x2010,%rsp
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9b(%rip),%rdi
lea    0x1010(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11f4 <main+0x94>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11f4 <main+0x94>
mov    %rsp,%r14
lea    0xe5e(%rip),%r15
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11c0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Please enter path to file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i32*
%4 = alloca [4097 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, 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 %29
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = load i32*, i32** %3
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = call i32 @fread(i8* %20, i32 1, i32 4096, i32* %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %14
28: ; preds = %14
br label %29
29: ; preds = %28, %0
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Please enter path to file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = alloca [4097 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 0
%8 = icmp eq i32* %6, null
br i1 %8, label %19, label %9
9: ; preds = %0
%10 = call i32 @feof(i32* %6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9, %12
%13 = call i32 @fread(i8* %7, i32 1, i32 4096, i32* %6)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%17 = call i32 @feof(i32* %6)
%18 = icmp eq i32 %17, 0
br i1 %18, label %12, label %19
19: ; preds = %12, %9, %0
%20 = call i32 @fclose(i32* %6)
ret i32 0
}