#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 /*<<< orphan*/ puts(char *);
void fig04_07() {
  int grade;
  unsigned int aCount = 0;
  unsigned int bCount = 0;
  unsigned int cCount = 0;
  unsigned int dCount = 0;
  unsigned int eCount = 0;
  unsigned int fCount = 0;
  puts("Enter the letter grades.");
  puts("Enter the EOF character to end input.");
  while ((grade = getchar()) != EOF) {
    switch (grade) {
    case 'A':
    case 'a':
      ++aCount;
      break;
    case 'B':
    case 'b':
      ++bCount;
      break;
    case 'C':
    case 'c':
      ++cCount;
      break;
    case 'D':
    case 'd':
      ++dCount;
      break;
    case 'E':
    case 'e':
      ++eCount;
      break;
    case 'F':
    case 'f':
      ++fCount;
      break;
    case '\n':
    case '\t':
    case ' ':
      break;
    default:
      printf("%s", "Incorrect letter grade entered.");
      puts("Enter a new grade.");
      break;
    }
  }
  puts("\nTotals for each letter grade are:");
  printf("A: %u\n", aCount);
  printf("B: %u\n", bCount);
  printf("C: %u\n", cCount);
  printf("D: %u\n", dCount);
  printf("E: %u\n", eCount);
  printf("F: %u\n", fCount);
}


x86 assembly (clang, -O0):
<fig04_07>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0x100f(%rip),%rdi
call   1030 <puts@plt>
lea    0x101c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%eax
je     123b <fig04_07+0x10b>
mov    -0x4(%rbp),%eax
add    $0xfffffff7,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5d,%eax
ja     1215 <fig04_07+0xe5>
mov    -0x28(%rbp),%rax
lea    0xe4d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1236 <fig04_07+0x106>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1236 <fig04_07+0x106>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1236 <fig04_07+0x106>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1236 <fig04_07+0x106>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1236 <fig04_07+0x106>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1236 <fig04_07+0x106>
jmp    1236 <fig04_07+0x106>
lea    0xf9b(%rip),%rdi
lea    0xf97(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xfa9(%rip),%rdi
call   1030 <puts@plt>
jmp    117a <fig04_07+0x4a>
lea    0xfab(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%esi
lea    0xfbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xfb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xfab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xfa1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xf97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xf8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig04_07>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x1036(%rip),%rdi
call   1030 <puts@plt>
lea    0x1043(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e85(%rip),%r14
mov    $0x0,%ebp
mov    $0x0,%r13d
mov    $0x0,%r12d
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
cmp    (%r14),%eax
jne    1207 <fig04_07+0xd7>
lea    0x105e(%rip),%rdi
call   1030 <puts@plt>
lea    0x1075(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x106c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1063(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1059(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x104f(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1044(%rip),%rdi
mov    (%rsp),%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xdf2(%rip),%r15
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1240 <fig04_07+0x110>
addl   $0x1,0x4(%rsp)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r14),%eax
je     1188 <fig04_07+0x58>
add    $0xfffffff7,%eax
cmp    $0x5d,%eax
ja     126d <fig04_07+0x13d>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
add    $0x1,%ebx
jmp    1230 <fig04_07+0x100>
add    $0x1,%r13d
jmp    1230 <fig04_07+0x100>
add    $0x1,%ebp
jmp    1230 <fig04_07+0x100>
add    $0x1,%r12d
jmp    1230 <fig04_07+0x100>
addl   $0x1,(%rsp)
jmp    1230 <fig04_07+0x100>
lea    0xf43(%rip),%rdi
lea    0xf3f(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf51(%rip),%rdi
call   1030 <puts@plt>
jmp    1230 <fig04_07+0x100>

LLVM IR (-O0):
@.str = [25 x i8] c"Enter the letter grades.\00"
@.str.1 = [38 x i8] c"Enter the EOF character to end input.\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [32 x i8] c"Incorrect letter grade entered.\00"
@.str.4 = [19 x i8] c"Enter a new grade.\00"
@.str.5 = [35 x i8] c"\0ATotals for each letter grade are:\00"
@.str.6 = [7 x i8] c"A: %u\0A\00"
@.str.7 = [7 x i8] c"B: %u\0A\00"
@.str.8 = [7 x i8] c"C: %u\0A\00"
@.str.9 = [7 x i8] c"D: %u\0A\00"
@.str.10 = [7 x i8] c"E: %u\0A\00"
@.str.11 = [7 x i8] c"F: %u\0A\00"
define void @fig04_07() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %38, %0
%11 = call i32 (...) @getchar()
store i32 %11, i32* %1
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load i32, i32* %1
switch i32 %15, label %35 [
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 68, label %25
i32 100, label %25
i32 69, label %28
i32 101, label %28
i32 70, label %31
i32 102, label %31
i32 10, label %34
i32 9, label %34
i32 32, label %34
]
16: ; preds = %14, %14
%17 = load i32, i32* %2
%18 = add i32 %17, 1
store i32 %18, i32* %2
br label %38
19: ; preds = %14, %14
%20 = load i32, i32* %3
%21 = add i32 %20, 1
store i32 %21, i32* %3
br label %38
22: ; preds = %14, %14
%23 = load i32, i32* %4
%24 = add i32 %23, 1
store i32 %24, i32* %4
br label %38
25: ; preds = %14, %14
%26 = load i32, i32* %5
%27 = add i32 %26, 1
store i32 %27, i32* %5
br label %38
28: ; preds = %14, %14
%29 = load i32, i32* %6
%30 = add i32 %29, 1
store i32 %30, i32* %6
br label %38
31: ; preds = %14, %14
%32 = load i32, i32* %7
%33 = add i32 %32, 1
store i32 %33, i32* %7
br label %38
34: ; preds = %14, %14, %14
br label %38
35: ; preds = %14
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %35, %34, %31, %28, %25, %22, %19, %16
br label %10
39: ; preds = %10
%40 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* %2
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %4
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %51)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Enter the letter grades.\00"
@.str.1 = [38 x i8] c"Enter the EOF character to end input.\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [32 x i8] c"Incorrect letter grade entered.\00"
@.str.4 = [19 x i8] c"Enter a new grade.\00"
@.str.5 = [35 x i8] c"\0ATotals for each letter grade are:\00"
@.str.6 = [7 x i8] c"A: %u\0A\00"
@.str.7 = [7 x i8] c"B: %u\0A\00"
@.str.8 = [7 x i8] c"C: %u\0A\00"
@.str.9 = [7 x i8] c"D: %u\0A\00"
@.str.10 = [7 x i8] c"E: %u\0A\00"
@.str.11 = [7 x i8] c"F: %u\0A\00"
define void @fig04_07() {
%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.1, i64 0, i64 0))
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %39, label %6
6: ; preds = %0, %29
%7 = phi i32 [ %36, %29 ], [ %3, %0 ]
%8 = phi i32 [ %35, %29 ], [ 0, %0 ]
%9 = phi i32 [ %34, %29 ], [ 0, %0 ]
%10 = phi i32 [ %33, %29 ], [ 0, %0 ]
%11 = phi i32 [ %32, %29 ], [ 0, %0 ]
%12 = phi i32 [ %31, %29 ], [ 0, %0 ]
%13 = phi i32 [ %30, %29 ], [ 0, %0 ]
switch i32 %7, label %26 [
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 68, label %20
i32 100, label %20
i32 69, label %22
i32 101, label %22
i32 70, label %24
i32 102, label %24
i32 10, label %29
i32 9, label %29
i32 32, label %29
]
14: ; preds = %6, %6
%15 = add i32 %13, 1
br label %29
16: ; preds = %6, %6
%17 = add i32 %12, 1
br label %29
18: ; preds = %6, %6
%19 = add i32 %11, 1
br label %29
20: ; preds = %6, %6
%21 = add i32 %10, 1
br label %29
22: ; preds = %6, %6
%23 = add i32 %9, 1
br label %29
24: ; preds = %6, %6
%25 = add i32 %8, 1
br label %29
26: ; preds = %6
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %6, %6, %6, %26, %24, %22, %20, %18, %16, %14
%30 = phi i32 [ %13, %26 ], [ %13, %6 ], [ %13, %6 ], [ %13, %6 ], [ %13, %24 ], [ %13, %22 ], [ %13, %20 ], [ %13, %18 ], [ %13, %16 ], [ %15, %14 ]
%31 = phi i32 [ %12, %26 ], [ %12, %6 ], [ %12, %6 ], [ %12, %6 ], [ %12, %24 ], [ %12, %22 ], [ %12, %20 ], [ %12, %18 ], [ %17, %16 ], [ %12, %14 ]
%32 = phi i32 [ %11, %26 ], [ %11, %6 ], [ %11, %6 ], [ %11, %6 ], [ %11, %24 ], [ %11, %22 ], [ %11, %20 ], [ %19, %18 ], [ %11, %16 ], [ %11, %14 ]
%33 = phi i32 [ %10, %26 ], [ %10, %6 ], [ %10, %6 ], [ %10, %6 ], [ %10, %24 ], [ %10, %22 ], [ %21, %20 ], [ %10, %18 ], [ %10, %16 ], [ %10, %14 ]
%34 = phi i32 [ %9, %26 ], [ %9, %6 ], [ %9, %6 ], [ %9, %6 ], [ %9, %24 ], [ %23, %22 ], [ %9, %20 ], [ %9, %18 ], [ %9, %16 ], [ %9, %14 ]
%35 = phi i32 [ %8, %26 ], [ %8, %6 ], [ %8, %6 ], [ %8, %6 ], [ %25, %24 ], [ %8, %22 ], [ %8, %20 ], [ %8, %18 ], [ %8, %16 ], [ %8, %14 ]
%36 = tail call i32 (...) @getchar()
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %6
39: ; preds = %29, %0
%40 = phi i32 [ 0, %0 ], [ %30, %29 ]
%41 = phi i32 [ 0, %0 ], [ %31, %29 ]
%42 = phi i32 [ 0, %0 ], [ %32, %29 ]
%43 = phi i32 [ 0, %0 ], [ %33, %29 ]
%44 = phi i32 [ 0, %0 ], [ %34, %29 ]
%45 = phi i32 [ 0, %0 ], [ %35, %29 ]
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %40)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %41)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %42)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %43)
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %44)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %45)
ret void
}