#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 */
char EOF;
int EXIT_SUCCESS;
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int scanf(char *, int *);
int main(void) {
  const char GRADES[] = {
      [0] = 'F', [1] = 'F', [2] = 'F', [3] = 'F', [4] = 'F', [5] = 'F',
      [6] = 'D', [7] = 'C', [8] = 'B', [9] = 'A', [10] = 'A'};
  int grade = 0;
  char c = '\0';
  while (1) {
    printf("Enter numerical grade: ");
    if (scanf("%d", &grade) != 1) {
      puts("Input invalid. Please try again.");
      while ((c = getchar()) != '\n' && c != EOF)
        continue;
      continue;
    }
    while ((c = getchar()) != '\n' && c != EOF)
      continue;
    if (grade < 0) {
      puts("Input invalid. Grade cannot be negative. Please try again.");
      continue;
    }
    if (grade > 100) {
      printf("Input invalid. Grade cannot exceed %d. Please try again.\n", 100);
      continue;
    }
    break;
  }
  char letterGrade = GRADES[grade / 10];
  printf("Letter grade: %c\n", letterGrade);
  putchar('\n');
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xe97(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xe8f(%rip),%al
mov    %al,-0x5(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe85(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
je     1207 <main+0xb7>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x17(%rbp)
je     11ed <main+0x9d>
movsbl -0x15(%rbp),%eax
mov    0x2e06(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x17(%rbp)
mov    -0x17(%rbp),%al
test   $0x1,%al
jne    11fd <main+0xad>
jmp    1202 <main+0xb2>
jmp    11bc <main+0x6c>
jmp    1189 <main+0x39>
jmp    120c <main+0xbc>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x18(%rbp)
je     123d <main+0xed>
movsbl -0x15(%rbp),%eax
mov    0x2db6(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x18(%rbp)
mov    -0x18(%rbp),%al
test   $0x1,%al
jne    124d <main+0xfd>
jmp    1252 <main+0x102>
jmp    120c <main+0xbc>
cmpl   $0x0,-0x14(%rbp)
jge    126d <main+0x11d>
lea    0xde4(%rip),%rdi
call   1040 <puts@plt>
jmp    1189 <main+0x39>
cmpl   $0x64,-0x14(%rbp)
jle    128f <main+0x13f>
lea    0xe04(%rip),%rdi
mov    $0x64,%esi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1189 <main+0x39>
jmp    1294 <main+0x144>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cltq
mov    -0xf(%rbp,%rax,1),%al
mov    %al,-0x16(%rbp)
movsbl -0x16(%rbp),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xea1(%rip),%r14
lea    0xeb2(%rip),%r15
lea    0x4(%rsp),%rbx
mov    0x2e6b(%rip),%r12
lea    0xefe(%rip),%r13
lea    0xe9b(%rip),%rbp
jmp    11a0 <main+0x50>
lea    0xeb3(%rip),%rdi
call   1040 <puts@plt>
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    11f0 <main+0xa0>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     11d1 <main+0x81>
cmp    (%r12),%al
jne    11c0 <main+0x70>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     118d <main+0x3d>
cmp    $0x65,%eax
jb     1216 <main+0xc6>
mov    %r13,%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a0 <main+0x50>
nop
mov    %rbp,%rdi
call   1040 <puts@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
movzbl (%r12),%ecx
cmp    $0xa,%al
je     11a0 <main+0x50>
cmp    %cl,%al
jne    1200 <main+0xb0>
jmp    11a0 <main+0x50>
movzbl %al,%eax
imul   $0xcd,%eax,%eax
shr    $0xb,%rax
lea    0xdd6(%rip),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.GRADES = [11 x i8] c"FFFFFFDCBAA"
@.str = [24 x i8] c"Enter numerical grade: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Input invalid. Please try again.\00"
@EOF = global i8 0
@.str.3 = [59 x i8] c"Input invalid. Grade cannot be negative. Please try again.\00"
@.str.4 = [58 x i8] c"Input invalid. Grade cannot exceed %d. Please try again.\0A\00"
@.str.5 = [18 x i8] c"Letter grade: %c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
store i32 0, i32* %1
%6 = bitcast [11 x i8]* %2 to i8*
store i32 0, i32* %3
store i8 0, i8* %4
br label %7
7: ; preds = %0, %26, %44, %49
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %25, %11
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br label %23
23: ; preds = %17, %13
%24 = phi i1 [ false, %13 ], [ %22, %17 ]
br i1 %24, label %25, label %26
25: ; preds = %23
br label %13
26: ; preds = %23
br label %7
27: ; preds = %7
br label %28
28: ; preds = %40, %27
%29 = call signext i8 (...) @getchar()
store i8 %29, i8* %4
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %34, %36
br label %38
38: ; preds = %32, %28
%39 = phi i1 [ false, %28 ], [ %37, %32 ]
br i1 %39, label %40, label %41
40: ; preds = %38
br label %28
41: ; preds = %38
%42 = load i32, i32* %3
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @puts(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
br label %7
46: ; preds = %41
%47 = load i32, i32* %3
%48 = icmp sgt i32 %47, 100
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 100)
br label %7
51: ; preds = %46
br label %52
52: ; preds = %51
%53 = load i32, i32* %3
%54 = sdiv i32 %53, 10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %55
%57 = load i8, i8* %56
store i8 %57, i8* %5
%58 = load i8, i8* %5
%59 = sext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = call i32 @putchar(i8 signext 10)
%62 = call signext i8 (...) @getchar()
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}

LLVM IR (-O2):
@__const.main.GRADES = [11 x i8] c"FFFFFFDCBAA"
@.str = [24 x i8] c"Enter numerical grade: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Input invalid. Please try again.\00"
@EOF = global i8 0
@.str.3 = [59 x i8] c"Input invalid. Grade cannot be negative. Please try again.\00"
@.str.4 = [58 x i8] c"Input invalid. Grade cannot exceed %d. Please try again.\0A\00"
@.str.5 = [18 x i8] c"Letter grade: %c\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %3
3: ; preds = %26, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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), i32* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %9, %7
%10 = call signext i8 (...) @getchar()
%11 = icmp ne i8 %10, 10
%12 = load i8, i8* @EOF
%13 = icmp ne i8 %10, %12
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %9, label %26
15: ; preds = %3, %15
%16 = call signext i8 (...) @getchar()
%17 = icmp ne i8 %16, 10
%18 = load i8, i8* @EOF
%19 = icmp ne i8 %16, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %15, label %21
21: ; preds = %15
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %9, %24, %29
br label %3
27: ; preds = %21
%28 = icmp ugt i32 %22, 100
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32 100)
br label %26
31: ; preds = %27
%32 = trunc i32 %22 to i8
%33 = udiv i8 %32, 10
%34 = zext i8 %33 to i64
%35 = getelementptr inbounds [11 x i8], [11 x i8]* @__const.main.GRADES, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = call i32 @putchar(i8 signext 10)
%40 = call signext i8 (...) @getchar()
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}