int main(void) {
  char grade;
  int excellent = 0, normal = 0, bad = 0;
  printf("Enter your grade,if wanna quit,enter EOF\n");
  scanf("%c", &grade);
  while (grade != "EOF") {
    switch (grade) {
    case 'A':
    case 'a':
      excellent++;
      break;
    case 'B':
    case 'b':
      normal++;
      break;
    case 'C':
    case 'c':
      bad++;
      break;
    case '\n':
    case ' ':
      break;
    default:
      printf("you suck\n");
      break;
    }
  }
  printf("%d\n%d\n%d\n", excellent, normal, bad);
  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)
movl   $0x0,-0x14(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbq -0x5(%rbp),%rax
lea    0xebd(%rip),%rcx
cmp    %rcx,%rax
je     1247 <main+0x127>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xa,%eax
je     122f <main+0x10f>
jmp    118e <main+0x6e>
mov    -0x18(%rbp),%eax
sub    $0x20,%eax
je     122f <main+0x10f>
jmp    119f <main+0x7f>
mov    -0x18(%rbp),%eax
sub    $0x41,%eax
je     1205 <main+0xe5>
jmp    11b0 <main+0x90>
mov    -0x18(%rbp),%eax
sub    $0x42,%eax
je     1213 <main+0xf3>
jmp    11c1 <main+0xa1>
mov    -0x18(%rbp),%eax
sub    $0x43,%eax
je     1221 <main+0x101>
jmp    11d2 <main+0xb2>
mov    -0x18(%rbp),%eax
sub    $0x61,%eax
je     1205 <main+0xe5>
jmp    11e3 <main+0xc3>
mov    -0x18(%rbp),%eax
sub    $0x62,%eax
je     1213 <main+0xf3>
jmp    11f4 <main+0xd4>
mov    -0x18(%rbp),%eax
sub    $0x63,%eax
je     1221 <main+0x101>
jmp    1234 <main+0x114>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1242 <main+0x122>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1242 <main+0x122>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1242 <main+0x122>
jmp    1242 <main+0x122>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1164 <main+0x44>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xde4(%rip),%rdi
mov    $0x0,%al
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    0xfdb(%rip),%rdi
call   1030 <puts@plt>
lea    0xfc2(%rip),%rdi
xor    %r14d,%r14d
lea    0x7(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsbq 0x7(%rsp),%rax
lea    0xfd8(%rip),%r12
mov    $0x0,%ebx
mov    $0x0,%r13d
cmp    %r12,%rax
je     11e9 <main+0xb9>
xor    %r13d,%r13d
lea    0xfc2(%rip),%r15
lea    0xe75(%rip),%rbp
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    11ad <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r13d
movsbq %al,%rcx
cmp    %r12,%rcx
je     11e9 <main+0xb9>
movsbl %al,%ecx
lea    -0x20(%rcx),%edx
cmp    $0x43,%edx
ja     11d5 <main+0xa5>
movslq 0x0(%rbp,%rdx,4),%rcx
add    %rbp,%rcx
jmp    *%rcx
add    $0x1,%r14d
jmp    11a4 <main+0x74>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
jmp    11a4 <main+0x74>
cmp    $0xa,%ecx
je     11a4 <main+0x74>
mov    %r15,%rdi
call   1030 <puts@plt>
movzbl 0x7(%rsp),%eax
jmp    11a4 <main+0x74>
lea    0xf23(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Enter your grade,if wanna quit,enter EOF\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [4 x i8] c"EOF\00"
@.str.3 = [10 x i8] c"you suck\0A\00"
@.str.4 = [10 x i8] c"%d\0A%d\0A%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %8
8: ; preds = %28, %0
%9 = load i8, i8* %2
%10 = sext i8 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = icmp ne i8* %11, getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
switch i32 %15, label %26 [
i32 65, label %16
i32 97, label %16
i32 66, label %19
i32 98, label %19
i32 67, label %22
i32 99, label %22
i32 10, label %25
i32 32, label %25
]
16: ; preds = %13, %13
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %28
19: ; preds = %13, %13
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %28
22: ; preds = %13, %13
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %28
25: ; preds = %13, %13
br label %28
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %25, %22, %19, %16
br label %8
29: ; preds = %8
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [4 x i8] c"EOF\00"
@.str.4 = [10 x i8] c"%d\0A%d\0A%d\0A\00"
@str = [41 x i8] c"Enter your grade,if wanna quit,enter EOF\00"
@str.5 = [9 x i8] c"you suck\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%3 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%4 = load i8, i8* %1
%5 = sext i8 %4 to i64
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i8* %6, getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
br i1 %7, label %31, label %8
8: ; preds = %0, %23
%9 = phi i8 [ %24, %23 ], [ %4, %0 ]
%10 = phi i32 [ %27, %23 ], [ 0, %0 ]
%11 = phi i32 [ %26, %23 ], [ 0, %0 ]
%12 = phi i32 [ %25, %23 ], [ 0, %0 ]
%13 = sext i8 %9 to i32
switch i32 %13, label %20 [
i32 65, label %14
i32 97, label %14
i32 66, label %16
i32 98, label %16
i32 67, label %18
i32 99, label %18
i32 10, label %23
i32 32, label %23
]
14: ; preds = %8, %8
%15 = add nsw i32 %12, 1
br label %23
16: ; preds = %8, %8
%17 = add nsw i32 %11, 1
br label %23
18: ; preds = %8, %8
%19 = add nsw i32 %10, 1
br label %23
20: ; preds = %8
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.5, i64 0, i64 0))
%22 = load i8, i8* %1
br label %23
23: ; preds = %8, %8, %20, %18, %16, %14
%24 = phi i8 [ %22, %20 ], [ %9, %8 ], [ %9, %8 ], [ %9, %18 ], [ %9, %16 ], [ %9, %14 ]
%25 = phi i32 [ %12, %20 ], [ %12, %8 ], [ %12, %8 ], [ %12, %18 ], [ %12, %16 ], [ %15, %14 ]
%26 = phi i32 [ %11, %20 ], [ %11, %8 ], [ %11, %8 ], [ %11, %18 ], [ %17, %16 ], [ %11, %14 ]
%27 = phi i32 [ %10, %20 ], [ %10, %8 ], [ %10, %8 ], [ %19, %18 ], [ %10, %16 ], [ %10, %14 ]
%28 = sext i8 %24 to i64
%29 = inttoptr i64 %28 to i8*
%30 = icmp eq i8* %29, getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
br i1 %30, label %31, label %8
31: ; preds = %23, %0
%32 = phi i32 [ 0, %0 ], [ %25, %23 ]
%33 = phi i32 [ 0, %0 ], [ %26, %23 ]
%34 = phi i32 [ 0, %0 ], [ %27, %23 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %33, i32 %34)
ret i32 0
}