#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*/ text;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char **);
int strlen(char *);
int main() {
  FILE *file;
  char file_name[30];
  scanf("%s", &file_name);
  file = fopen(file_name, "r");
  if (file == NULL) {
    while (file == NULL) {
      printf("%s", "FILE NOT FOUND. Please, try again\n");
      scanf("%s", &file_name);
      file = fopen(file_name, "r");
    }
  }
  char text[1000];
  int i = 0;
  char *real_tail;
  while (fgets(text, sizeof(text), file)) {
    real_tail = "";
    if (text[strlen(text) - 1] == '\n') {
      real_tail = "\\n";
      text[strlen(text) - 1] = '\0';
    };
    printf("%s\n", text);
  }
  int size = ftell(file);
  printf("File size = %d bytes\n", size);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1204 <main+0x94>
jmp    11b6 <main+0x46>
cmpq   $0x0,-0x10(%rbp)
jne    11ff <main+0x8f>
lea    0xe38(%rip),%rdi
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe1f(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
jmp    11b6 <main+0x46>
jmp    1204 <main+0x94>
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     129e <main+0x12e>
lea    0xdf3(%rip),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1284 <main+0x114>
lea    0xdc4(%rip),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120e <main+0x9e>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%esi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0xe69(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1206 <main+0x86>
lea    0xe5b(%rip),%r15
lea    0xe39(%rip),%r12
mov    %rsp,%rbx
lea    0xe32(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11e0 <main+0x60>
mov    %rax,%r14
lea    0x20(%rsp),%rbx
jmp    1218 <main+0x98>
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124f <main+0xcf>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1210 <main+0x90>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    1210 <main+0x90>
mov    %r14,%rdi
call   1080 <ftell@plt>
lea    0xda7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"FILE NOT FOUND. Please, try again\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"\\n\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [22 x i8] c"File size = %d bytes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [30 x i8]
%4 = alloca [1000 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [30 x i8]* %3 to i8**
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %8)
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %25
14: ; preds = %0
br label %15
15: ; preds = %18, %14
%16 = load i32*, i32** %2
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%20 = bitcast [30 x i8]* %3 to i8**
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %20)
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %2
br label %15
24: ; preds = %15
br label %25
25: ; preds = %24, %0
store i32 0, i32* %5
br label %26
26: ; preds = %46, %25
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%28 = load i32*, i32** %2
%29 = call i64 @fgets(i8* %27, i32 1000, i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %49
31: ; preds = %26
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8** %6
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 10
br i1 %39, label %40, label %46
40: ; preds = %31
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %6
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %44
store i8 0, i8* %45
br label %46
46: ; preds = %40, %31
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %47)
br label %26
49: ; preds = %26
%50 = load i32*, i32** %2
%51 = call i32 @ftell(i32* %50)
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = load i32*, i32** %2
%55 = call i32 @fclose(i32* %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.6 = [22 x i8] c"File size = %d bytes\0A\00"
@str = [34 x i8] c"FILE NOT FOUND. Please, try again\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = bitcast [30 x i8]* %1 to i8**
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %0, %8
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4)
%11 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %8, label %13
13: ; preds = %8, %0
%14 = phi i32* [ %6, %0 ], [ %11, %8 ]
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%16 = call i64 @fgets(i8* %15, i32 1000, i32* %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %34, label %18
18: ; preds = %13, %30
%19 = call i32 @strlen(i8* %15)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = call i32 @strlen(i8* %15)
%27 = add nsw i32 %26, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %25, %18
%31 = call i32 @puts(i8* %15)
%32 = call i64 @fgets(i8* %15, i32 1000, i32* %14)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %18
34: ; preds = %30, %13
%35 = call i32 @ftell(i32* %14)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = call i32 @fclose(i32* %14)
ret i32 0
}