#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ system(char *);
void loadText() {
  char file_name[256];
  int fd;
  char buf[1024];
  system("clear");
  printf("Input Load Path : ");
  scanf("%s", file_name);
  fd = open(file_name, O_RDONLY);
  if (fd <= 0) {
    puts("error occurred while opening file");
    return;
  }
  while (read(fd, buf, 1024) > 0) {
    printf("%s", buf);
  }
  printf("\n");
  close(fd);
}


x86 assembly (clang, -O0):
<loadText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x510,%rsp
lea    0xe7e(%rip),%rdi
call   1040 <system@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x100(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x100(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
jg     11e1 <loadText+0x71>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
jmp    123a <loadText+0xca>
jmp    11e6 <loadText+0x76>
mov    -0x104(%rbp),%edi
lea    -0x510(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jle    1221 <loadText+0xb1>
lea    -0x510(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e6 <loadText+0x76>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x104(%rbp),%edi
call   1060 <close@plt>
add    $0x510,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadText>:
push   %rbp
push   %r14
push   %rbx
sub    $0x500,%rsp
lea    0xe6e(%rip),%rdi
call   1050 <system@plt>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
test   %eax,%eax
jle    1234 <loadText+0xb4>
mov    %eax,%ebp
lea    0x100(%rsp),%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1080 <read@plt>
test   %rax,%rax
jle    1221 <loadText+0xa1>
lea    0xe2b(%rip),%r14
lea    0x100(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
test   %rax,%rax
jg     1200 <loadText+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    1240 <loadText+0xc0>
lea    0xde1(%rip),%rdi
call   1040 <puts@plt>
add    $0x500,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [19 x i8] c"Input Load Path : \00"
@.str.2 = [3 x i8] c"%s\00"
@O_RDONLY = global i32 0
@.str.3 = [34 x i8] c"error occurred while opening file\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @loadText() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %28
15: ; preds = %0
br label %16
16: ; preds = %21, %15
%17 = load i32, i32* %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i64 @read(i32 %17, i8* %18, i32 1024)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %16
24: ; preds = %16
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* %2
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %24, %13
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.1 = [19 x i8] c"Input Load Path : \00"
@.str.2 = [3 x i8] c"%s\00"
@O_RDONLY = global i32 0
@.str.3 = [34 x i8] c"error occurred while opening file\00"
define void @loadText() {
%1 = alloca [256 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %3, i32 %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = call i64 @read(i32 %9, i8* %4, i32 1024)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %16, label %20
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %23
16: ; preds = %11, %16
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%18 = call i64 @read(i32 %9, i8* %4, i32 1024)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %16, label %20
20: ; preds = %16, %11
%21 = call i32 @putchar(i32 10)
%22 = call i32 @close(i32 %9)
br label %23
23: ; preds = %20, %14
ret void
}