#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *);
int main() {
  int grade;
  int total = 0;
  int count = 0;
  printf("Enter the letter grades.\n");
  printf("Enter the EOF character to end input.\n");
  while ((grade = getchar()) != EOF) {
    switch (grade) {
    case 'A':
    case 'a':
      total += 5;
      count++;
      break;
    case 'B':
    case 'b':
      total += 4;
      count++;
      break;
    case 'C':
    case 'c':
      total += 3;
      count++;
      break;
    case 'D':
    case 'd':
      total += 2;
      count++;
      break;
    case 'F':
    case 'f':
      total += 0;
      count++;
      break;
    case '\n':
    case ' ':
      break;
    default:
      printf("Incorrect letter grade entered.\n");
      printf("Enter a new grade.\n");
      break;
    }
  }
  grade = total / count;
  printf("The average grade for the class was ");
  switch (grade) {
  case 5:
    printf("A.\n");
    break;
  case 4:
    printf("B.\n");
    break;
  case 3:
    printf("C.\n");
    break;
  case 2:
    printf("D.\n");
    break;
  default:
    printf("F.\n");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0x1040(%rip),%rdi
call   1030 <printf@plt>
lea    0x104e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%eax
je     122c <main+0x10c>
mov    -0x8(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5c,%eax
ja     120f <main+0xef>
mov    -0x18(%rbp),%rax
lea    0xe82(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1227 <main+0x107>
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1227 <main+0x107>
mov    -0xc(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1227 <main+0x107>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1227 <main+0x107>
mov    -0xc(%rbp),%eax
add    $0x0,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1227 <main+0x107>
jmp    1227 <main+0x107>
lea    0xfaf(%rip),%rdi
call   1030 <printf@plt>
lea    0xfc4(%rip),%rdi
call   1030 <printf@plt>
jmp    1155 <main+0x35>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
lea    0xfbb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     12b1 <main+0x191>
mov    -0x20(%rbp),%rax
lea    0xd9c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xfab(%rip),%rdi
call   1030 <printf@plt>
jmp    12bd <main+0x19d>
lea    0xf9e(%rip),%rdi
call   1030 <printf@plt>
jmp    12bd <main+0x19d>
lea    0xf91(%rip),%rdi
call   1030 <printf@plt>
jmp    12bd <main+0x19d>
lea    0xf84(%rip),%rdi
call   1030 <printf@plt>
jmp    12bd <main+0x19d>
lea    0xf77(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%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
lea    0x1067(%rip),%rdi
call   1030 <puts@plt>
lea    0x1074(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e87(%rip),%r12
cmp    (%r12),%eax
jne    1178 <main+0x48>
lea    0x1016(%rip),%rdi
call   1040 <printf@plt>
jmp    1211 <main+0xe1>
lea    0x1078(%rip),%r14
lea    0x1091(%rip),%r15
lea    0xe73(%rip),%r13
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11b0 <main+0x80>
add    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r12),%eax
je     11e3 <main+0xb3>
add    $0xfffffff6,%eax
cmp    $0x5c,%eax
ja     11d1 <main+0xa1>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
add    $0x5,%ebp
jmp    11a0 <main+0x70>
add    $0x4,%ebp
jmp    11a0 <main+0x70>
add    $0x3,%ebp
jmp    11a0 <main+0x70>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    11a3 <main+0x73>
mov    %ebp,%eax
cltd
idiv   %ebx
mov    %eax,%ebx
lea    0xf93(%rip),%rdi
call   1040 <printf@plt>
add    $0xfffffffe,%ebx
cmp    $0x3,%ebx
ja     1211 <main+0xe1>
movslq %ebx,%rax
lea    0xf6c(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1218 <main+0xe8>
lea    0xfdc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter the letter grades.\0A\00"
@.str.1 = [39 x i8] c"Enter the EOF character to end input.\0A\00"
@EOF = global i32 0
@.str.2 = [33 x i8] c"Incorrect letter grade entered.\0A\00"
@.str.3 = [20 x i8] c"Enter a new grade.\0A\00"
@.str.4 = [37 x i8] c"The average grade for the class was \00"
@.str.5 = [4 x i8] c"A.\0A\00"
@.str.6 = [4 x i8] c"B.\0A\00"
@.str.7 = [4 x i8] c"C.\0A\00"
@.str.8 = [4 x i8] c"D.\0A\00"
@.str.9 = [4 x i8] c"F.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %42, %0
%8 = call i32 (...) @getchar()
store i32 %8, i32* %2
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %43
11: ; preds = %7
%12 = load i32, i32* %2
switch i32 %12, label %39 [
i32 65, label %13
i32 97, label %13
i32 66, label %18
i32 98, label %18
i32 67, label %23
i32 99, label %23
i32 68, label %28
i32 100, label %28
i32 70, label %33
i32 102, label %33
i32 10, label %38
i32 32, label %38
]
13: ; preds = %11, %11
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 5
store i32 %15, i32* %3
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %42
18: ; preds = %11, %11
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 4
store i32 %20, i32* %3
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %42
23: ; preds = %11, %11
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 3
store i32 %25, i32* %3
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %42
28: ; preds = %11, %11
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 2
store i32 %30, i32* %3
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %42
33: ; preds = %11, %11
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 0
store i32 %35, i32* %3
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %42
38: ; preds = %11, %11
br label %42
39: ; preds = %11
%40 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %39, %38, %33, %28, %23, %18, %13
br label %7
43: ; preds = %7
%44 = load i32, i32* %3
%45 = load i32, i32* %4
%46 = sdiv i32 %44, %45
store i32 %46, i32* %2
%47 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%48 = load i32, i32* %2
switch i32 %48, label %57 [
i32 5, label %49
i32 4, label %51
i32 3, label %53
i32 2, label %55
]
49: ; preds = %43
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %59
51: ; preds = %43
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %59
53: ; preds = %43
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %59
55: ; preds = %43
%56 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %59
57: ; preds = %43
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
br label %59
59: ; preds = %57, %55, %53, %51, %49
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.4 = [37 x i8] c"The average grade for the class was \00"
@str = [25 x i8] c"Enter the letter grades.\00"
@str.10 = [38 x i8] c"Enter the EOF character to end input.\00"
@str.11 = [3 x i8] c"D.\00"
@str.12 = [3 x i8] c"C.\00"
@str.13 = [3 x i8] c"B.\00"
@str.14 = [3 x i8] c"A.\00"
@str.15 = [3 x i8] c"F.\00"
@str.16 = [32 x i8] c"Incorrect letter grade entered.\00"
@str.17 = [19 x i8] c"Enter a new grade.\00"
@reltable.main = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @str.11 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @str.12 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @str.13 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @str.14 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.10, i64 0, i64 0))
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %44
8: ; preds = %0, %29
%9 = phi i32 [ %32, %29 ], [ %3, %0 ]
%10 = phi i32 [ %31, %29 ], [ 0, %0 ]
%11 = phi i32 [ %30, %29 ], [ 0, %0 ]
switch i32 %9, label %26 [
i32 65, label %12
i32 97, label %12
i32 66, label %15
i32 98, label %15
i32 67, label %18
i32 99, label %18
i32 68, label %21
i32 100, label %21
i32 70, label %24
i32 102, label %24
i32 10, label %29
i32 32, label %29
]
12: ; preds = %8, %8
%13 = add nsw i32 %11, 5
%14 = add nsw i32 %10, 1
br label %29
15: ; preds = %8, %8
%16 = add nsw i32 %11, 4
%17 = add nsw i32 %10, 1
br label %29
18: ; preds = %8, %8
%19 = add nsw i32 %11, 3
%20 = add nsw i32 %10, 1
br label %29
21: ; preds = %8, %8
%22 = add nsw i32 %11, 2
%23 = add nsw i32 %10, 1
br label %29
24: ; preds = %8, %8
%25 = add nsw i32 %10, 1
br label %29
26: ; preds = %8
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.16, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.17, i64 0, i64 0))
br label %29
29: ; preds = %8, %8, %26, %24, %21, %18, %15, %12
%30 = phi i32 [ %11, %26 ], [ %11, %8 ], [ %11, %8 ], [ %11, %24 ], [ %22, %21 ], [ %19, %18 ], [ %16, %15 ], [ %13, %12 ]
%31 = phi i32 [ %10, %26 ], [ %10, %8 ], [ %10, %8 ], [ %25, %24 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ], [ %14, %12 ]
%32 = tail call i32 (...) @getchar()
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %8
35: ; preds = %29
%36 = sdiv i32 %30, %31
%37 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%38 = add i32 %36, -2
%39 = icmp ult i32 %38, 4
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = sext i32 %38 to i64
%42 = shl i64 %41, 2
%43 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.main to i8*), i64 %42)
br label %44
44: ; preds = %6, %35, %40
%45 = phi i8* [ %43, %40 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.15, i64 0, i64 0), %35 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.15, i64 0, i64 0), %6 ]
%46 = tail call i32 @puts(i8* dereferenceable(1) %45)
ret i32 0
}