#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
main() {
  FILE *fp;
  int i;
  fp = fopen("tfile.txt", "r");
  char ch = 'y';
  char str[64];
  char *pc = &ch;
  while (ch != 'n') {
    if (feof(fp)) {
      ch = 'n';
      printf("\nEnd of File\n");
    } else {
      printf("\nRead next MAX chars from file? (y/n): ");
      gets(pc);
      switch (ch) {
      case 'y': {
        if (fp) {
          fgets(str, 64, fp);
          for (i = 0; i < strlen(str); i++) {
            if (str[i] == '\r') {
              str[i] = '\0';
            }
          }
          printf("line: %s\n", str);
        } else {
          printf("-File Read Error-\n");
        }
        break;
      }
      case 'n': {
        printf("\nUser Quit\n");
        break;
      }
      default: {
        printf("\nInvalid input.\n");
      }
      }
    }
  }
  printf("\nProgram End\n");
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
movb   $0x79,-0x15(%rbp)
lea    -0x15(%rbp),%rax
mov    %rax,-0x68(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x6e,%eax
je     12d9 <main+0x169>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     11d9 <main+0x69>
movb   $0x6e,-0x15(%rbp)
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d4 <main+0x164>
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x68(%rbp),%rdi
call   1080 <gets@plt>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x6c(%rbp)
sub    $0x6e,%eax
je     12ae <main+0x13e>
jmp    1205 <main+0x95>
mov    -0x6c(%rbp),%eax
sub    $0x79,%eax
jne    12c1 <main+0x151>
jmp    1216 <main+0xa6>
cmpq   $0x0,-0x10(%rbp)
je     129b <main+0x12b>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40,%esi
call   1060 <fgets@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x70(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cmp    %ecx,%eax
jge    1284 <main+0x114>
movslq -0x14(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0xd,%eax
jne    1271 <main+0x101>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
jmp    1276 <main+0x106>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <main+0xca>
lea    -0x60(%rbp),%rsi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a9 <main+0x139>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cf <main+0x15f>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cf <main+0x15f>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d4 <main+0x164>
jmp    11a2 <main+0x32>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
movb   $0x79,0xf(%rsp)
lea    0xe5c(%rip),%r14
lea    0xf(%rsp),%r15
lea    0x10(%rsp),%rbp
lea    0xeb7(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     1200 <main+0x80>
movb   $0x6e,0xf(%rsp)
mov    %r12,%rdi
call   1030 <puts@plt>
cmpb   $0x6e,0xf(%rsp)
jne    11d0 <main+0x50>
jmp    12b5 <main+0x135>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1090 <gets@plt>
movsbl 0xf(%rsp),%eax
cmp    $0x6e,%eax
je     1273 <main+0xf3>
cmp    $0x79,%eax
jne    127f <main+0xff>
test   %rbx,%rbx
je     12a9 <main+0x129>
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    128b <main+0x10b>
xor    %r13d,%r13d
jmp    1263 <main+0xe3>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%r13
jge    128b <main+0x10b>
cmpb   $0xd,0x10(%rsp,%r13,1)
jne    1250 <main+0xd0>
movb   $0x0,0x10(%rsp,%r13,1)
jmp    1250 <main+0xd0>
lea    0xdd1(%rip),%rdi
jmp    11e5 <main+0x65>
lea    0xde2(%rip),%rdi
jmp    11e5 <main+0x65>
lea    0xda2(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmpb   $0x6e,0xf(%rsp)
jne    11d0 <main+0x50>
jmp    12b5 <main+0x135>
lea    0xda6(%rip),%rdi
jmp    11e5 <main+0x65>
lea    0xd82(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"tfile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"\0AEnd of File\0A\00"
@.str.3 = [40 x i8] c"\0ARead next MAX chars from file? (y/n): \00"
@.str.4 = [10 x i8] c"line: %s\0A\00"
@.str.5 = [19 x i8] c"-File Read Error-\0A\00"
@.str.6 = [12 x i8] c"\0AUser Quit\0A\00"
@.str.7 = [17 x i8] c"\0AInvalid input.\0A\00"
@.str.8 = [14 x i8] c"\0AProgram End\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8
%5 = alloca [64 x i8]
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
store i8 121, i8* %4
store i8* %4, i8** %6
br label %8
8: ; preds = %62, %0
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 110
br i1 %11, label %12, label %63
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = call i64 @feof(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
store i8 110, i8* %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %62
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%20 = load i8*, i8** %6
%21 = call i32 @gets(i8* %20)
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
switch i32 %23, label %59 [
i32 121, label %24
i32 110, label %57
]
24: ; preds = %18
%25 = load i32*, i32** %2
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %54
27: ; preds = %24
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%29 = load i32*, i32** %2
%30 = call i32 @fgets(i8* %28, i32 64, i32* %29)
store i32 0, i32* %3
br label %31
31: ; preds = %48, %27
%32 = load i32, i32* %3
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %51
36: ; preds = %31
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 13
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %45
store i8 0, i8* %46
br label %47
47: ; preds = %43, %36
br label %48
48: ; preds = %47
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %31
51: ; preds = %31
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %52)
br label %56
54: ; preds = %24
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
br label %61
57: ; preds = %18
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %61
59: ; preds = %18
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %61
61: ; preds = %59, %57, %56
br label %62
62: ; preds = %61, %16
br label %8
63: ; preds = %8
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%65 = load i32*, i32** %2
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@.str = [10 x i8] c"tfile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [40 x i8] c"\0ARead next MAX chars from file? (y/n): \00"
@.str.4 = [10 x i8] c"line: %s\0A\00"
@str = [13 x i8] c"\0AProgram End\00"
@str.9 = [11 x i8] c"\0AUser Quit\00"
@str.10 = [18 x i8] c"-File Read Error-\00"
@str.11 = [16 x i8] c"\0AInvalid input.\00"
@str.12 = [13 x i8] c"\0AEnd of File\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca [64 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8 121, i8* %1
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br label %6
6: ; preds = %0, %40
%7 = call i64 @feof(i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
store i8 110, i8* %1
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
br label %40
11: ; preds = %6
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @gets(i8* %1)
%14 = load i8, i8* %1
%15 = sext i8 %14 to i32
switch i32 %15, label %38 [
i32 121, label %16
i32 110, label %36
]
16: ; preds = %11
br i1 %5, label %34, label %17
17: ; preds = %16
%18 = call i32 @fgets(i8* %4, i32 64, i32* %3)
%19 = call i32 @strlen(i8* %4)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %17, %27
%22 = phi i64 [ %28, %27 ], [ 0, %17 ]
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 13
br i1 %25, label %26, label %27
26: ; preds = %21
store i8 0, i8* %23
br label %27
27: ; preds = %21, %26
%28 = add nuw nsw i64 %22, 1
%29 = call i32 @strlen(i8* %4)
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %21, label %32
32: ; preds = %27, %17
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %40
34: ; preds = %16
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.10, i64 0, i64 0))
br label %40
36: ; preds = %11
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0))
br label %40
38: ; preds = %11
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
br label %40
40: ; preds = %36, %38, %34, %32, %9
%41 = load i8, i8* %1
%42 = icmp eq i8 %41, 110
br i1 %42, label %43, label %6
43: ; preds = %40
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%45 = call i32 @fclose(i32* %3)
ret i32 0
}