#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*/ cleartoendofline();
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
char toupper(char);
void run() {
  char ch;
  char buffer[80];
  int char_count;
  int exit_flag = 0;
  int valid_choice;
  while (exit_flag == 0) {
    printf("Enter a line of text (<80 chars)\n");
    ch = getchar();
    char_count = 0;
    while ((ch != '\n') && (char_count < 80)) {
      buffer[char_count++] = ch;
      ch = getchar();
    }
    buffer[char_count] = 0x00;
    printf("\nThe line you entered was:\n");
    printf("%s\n", buffer);
    valid_choice = 0;
    while (valid_choice == 0) {
      printf("Continue (Y/N)?\n");
      scanf(" %c", &ch);
      ch = toupper(ch);
      if ((ch == 'Y') || (ch == 'N'))
        valid_choice = 1;
      else
        printf("\007Error: Invalid choice\n");
      cleartoendofline();
    }
    if (ch == 'N')
      exit_flag = 1;
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jne    1294 <run+0x144>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x1(%rbp)
movl   $0x0,-0x64(%rbp)
movsbl -0x1(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x6d(%rbp)
je     11a4 <run+0x54>
cmpl   $0x50,-0x64(%rbp)
setl   %al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
test   $0x1,%al
jne    11b4 <run+0x64>
jmp    11d7 <run+0x87>
mov    -0x1(%rbp),%cl
mov    -0x64(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x64(%rbp)
cltq
mov    %cl,-0x60(%rbp,%rax,1)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x1(%rbp)
jmp    1188 <run+0x38>
movslq -0x64(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jne    127b <run+0x12b>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2d(%rip),%rdi
lea    -0x1(%rbp),%rsi
call   1070 <scanf@plt>
movsbl -0x1(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x59,%eax
je     1255 <run+0x105>
movsbl -0x1(%rbp),%eax
cmp    $0x4e,%eax
jne    1261 <run+0x111>
movl   $0x1,-0x6c(%rbp)
jmp    126f <run+0x11f>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <cleartoendofline@plt>
jmp    1207 <run+0xb7>
movsbl -0x1(%rbp),%eax
cmp    $0x4e,%eax
jne    128f <run+0x13f>
movl   $0x1,-0x68(%rbp)
jmp    115f <run+0xf>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xedb(%rip),%r13
lea    0xe94(%rip),%rbx
lea    0xf(%rsp),%rbp
lea    0xed8(%rip),%r14
jmp    1192 <run+0x42>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <cleartoendofline@plt>
cmpb   $0x4e,0xf(%rsp)
je     1252 <run+0x102>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0xf(%rsp)
cmp    $0xa,%al
jne    11c0 <run+0x70>
xor    %r12d,%r12d
jmp    11f1 <run+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%r15),%r12
mov    %al,0x10(%rsp,%r15,1)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0xf(%rsp)
cmp    $0xa,%al
je     11f1 <run+0xa1>
cmp    $0x4f,%r15
mov    %r12,%r15
jb     11d0 <run+0x80>
movb   $0x0,0x10(%rsp,%r12,1)
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
call   1040 <puts@plt>
nopl   (%rax)
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
movsbl 0xf(%rsp),%edi
call   1030 <toupper@plt>
mov    %al,0xf(%rsp)
cmp    $0x4e,%al
je     1180 <run+0x30>
cmp    $0x59,%al
je     1180 <run+0x30>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <cleartoendofline@plt>
jmp    1210 <run+0xc0>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter a line of text (<80 chars)\0A\00"
@.str.1 = [28 x i8] c"\0AThe line you entered was:\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [17 x i8] c"Continue (Y/N)?\0A\00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [24 x i8] c"\07Error: Invalid choice\0A\00"
define void @run() {
%1 = alloca i8
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %4
br label %6
6: ; preds = %60, %0
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %61
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%11 = call signext i8 (...) @getchar()
store i8 %11, i8* %1
store i32 0, i32* %3
br label %12
12: ; preds = %21, %9
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 80
br label %19
19: ; preds = %16, %12
%20 = phi i1 [ false, %12 ], [ %18, %16 ]
br i1 %20, label %21, label %28
21: ; preds = %19
%22 = load i8, i8* %1
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %25
store i8 %22, i8* %26
%27 = call signext i8 (...) @getchar()
store i8 %27, i8* %1
br label %12
28: ; preds = %19
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i32 0, i32* %5
br label %35
35: ; preds = %53, %28
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %55
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%41 = load i8, i8* %1
%42 = call signext i8 @toupper(i8 signext %41)
store i8 %42, i8* %1
%43 = load i8, i8* %1
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 89
br i1 %45, label %50, label %46
46: ; preds = %38
%47 = load i8, i8* %1
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 78
br i1 %49, label %50, label %51
50: ; preds = %46, %38
store i32 1, i32* %5
br label %53
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %50
%54 = call i32 (...) @cleartoendofline()
br label %35
55: ; preds = %35
%56 = load i8, i8* %1
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 78
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 1, i32* %4
br label %60
60: ; preds = %59, %55
br label %6
61: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str.4 = [4 x i8] c" %c\00"
@str = [33 x i8] c"Enter a line of text (<80 chars)\00"
@str.6 = [27 x i8] c"\0AThe line you entered was:\00"
@str.7 = [16 x i8] c"Continue (Y/N)?\00"
@str.8 = [23 x i8] c"\07Error: Invalid choice\00"
define void @run() {
%1 = alloca i8
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %0, %30
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%6 = call signext i8 (...) @getchar()
store i8 %6, i8* %1
%7 = icmp eq i8 %6, 10
br i1 %7, label %17, label %8
8: ; preds = %4, %8
%9 = phi i64 [ %11, %8 ], [ 0, %4 ]
%10 = phi i8 [ %13, %8 ], [ %6, %4 ]
%11 = add nuw nsw i64 %9, 1
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %9
store i8 %10, i8* %12
%13 = call signext i8 (...) @getchar()
store i8 %13, i8* %1
%14 = icmp ne i8 %13, 10
%15 = icmp ult i64 %9, 79
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %8, label %17
17: ; preds = %8, %4
%18 = phi i64 [ 0, %4 ], [ %11, %8 ]
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%21 = call i32 @puts(i8* %3)
br label %22
22: ; preds = %27, %17
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%25 = load i8, i8* %1
%26 = call signext i8 @toupper(i8 signext %25)
store i8 %26, i8* %1
switch i8 %26, label %27 [
i8 89, label %30
i8 78, label %30
]
27: ; preds = %22
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%29 = call i32 (...) @cleartoendofline()
br label %22
30: ; preds = %22, %22
%31 = call i32 (...) @cleartoendofline()
%32 = load i8, i8* %1
%33 = icmp eq i8 %32, 78
br i1 %33, label %34, label %4
34: ; preds = %30
ret void
}