#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 findletter(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int grade[4], i = 0, sum = 0;
  char grades[4];
  printf("\nInput: \n");
  for (i = 0; i < 4; i++) {
    printf("Enter grade %d: ", i + 1);
    scanf("%d", &grade[i]);
    grades[i] = findletter(grade[i]);
    sum += grade[i];
  }
  printf("\nOutput: \n");
  printf("------------------------\n");
  for (i = 0; i < 4; i++) {
    printf("|    grade %d | %3d | %c |\n", i + 1, grade[i], grades[i]);
    printf("------------------------\n");
  }
  double avg = sum / 4;
  printf("************************\n");
  printf("| Average |  %5.2f | %c |\n", avg, findletter(avg));
  printf("************************\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11d0 <main+0xa0>
mov    -0x24(%rbp),%esi
add    $0x1,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x24(%rbp),%rax
lea    -0x20(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe85(%rip),%rdi
call   1050 <scanf@plt>
movslq -0x24(%rbp),%rax
cvtsi2sdl -0x20(%rbp,%rax,4),%xmm0
call   1040 <findletter@plt>
mov    %al,%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x2c(%rbp,%rax,1)
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <main+0x32>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    123e <main+0x10e>
mov    -0x24(%rbp),%esi
add    $0x1,%esi
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edx
movslq -0x24(%rbp),%rax
movsbl -0x2c(%rbp,%rax,1),%ecx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f3 <main+0xc3>
mov    -0x28(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <findletter@plt>
movsd  -0x40(%rbp),%xmm0
mov    %eax,%esi
lea    0xdf7(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9a(%rip),%rbp
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1060 <scanf@plt>
cvtsi2sdl (%rsp),%xmm0
call   1050 <findletter@plt>
mov    %eax,0x18(%rsp)
mov    (%rsp),%r14d
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <scanf@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x4(%rsp),%xmm0
call   1050 <findletter@plt>
mov    %eax,0x24(%rsp)
add    0x4(%rsp),%r14d
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <scanf@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x8(%rsp),%xmm0
call   1050 <findletter@plt>
mov    %eax,%r12d
add    0x8(%rsp),%r14d
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <scanf@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
call   1050 <findletter@plt>
mov    %eax,%r13d
mov    0xc(%rsp),%r15d
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
lea    0xe39(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%rsp),%edx
movsbl 0x18(%rsp),%ecx
lea    0xdbf(%rip),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edx
movsbl 0x24(%rsp),%ecx
mov    %rbp,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edx
movsbl %r12b,%ecx
mov    %rbp,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edx
movsbl %r13b,%ecx
mov    %rbp,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r15d,%eax
add    %r14d,%eax
lea    0x3(%r15,%r14,1),%ecx
cmovns %eax,%ecx
sar    $0x2,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x18(%rsp)
lea    0xd6f(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
movsd  0x18(%rsp),%xmm0
call   1050 <findletter@plt>
lea    0xd27(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"\0AInput: \0A\00"
@.str.1 = [17 x i8] c"Enter grade %d: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"\0AOutput: \0A\00"
@.str.4 = [26 x i8] c"------------------------\0A\00"
@.str.5 = [28 x i8] c"| grade %d | %3d | %c |\0A\00"
@.str.6 = [26 x i8] c"************************\0A\00"
@.str.7 = [27 x i8] c"| Average | %5.2f | %c |\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4 x i8]
%6 = alloca double
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %8
8: ; preds = %35, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %38
11: ; preds = %8
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %17)
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = sitofp i32 %22 to double
%24 = call i32 @findletter(double %23)
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 %27
store i8 %25, i8* %28
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, %32
store i32 %34, i32* %4
br label %35
35: ; preds = %11
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %8
38: ; preds = %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %41
41: ; preds = %58, %38
%42 = load i32, i32* %3
%43 = icmp slt i32 %42, 4
br i1 %43, label %44, label %61
44: ; preds = %41
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %46, i32 %50, i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %58
58: ; preds = %44
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
store i32 %60, i32* %3
br label %41
61: ; preds = %41
%62 = load i32, i32* %4
%63 = sdiv i32 %62, 4
%64 = sitofp i32 %63 to double
store double %64, double* %6
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%66 = load double, double* %6
%67 = load double, double* %6
%68 = call i32 @findletter(double %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), double %66, i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Enter grade %d: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [28 x i8] c"| grade %d | %3d | %c |\0A\00"
@.str.7 = [27 x i8] c"| Average | %5.2f | %c |\0A\00"
@str = [9 x i8] c"\0AInput: \00"
@str.8 = [10 x i8] c"\0AOutput: \00"
@str.11 = [25 x i8] c"************************\00"
@str.12 = [25 x i8] c"------------------------\00"
define i32 @main() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 1)
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%7 = load i32, i32* %5
%8 = sitofp i32 %7 to double
%9 = call i32 @findletter(double %8)
%10 = load i32, i32* %5
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 2)
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%14 = load i32, i32* %12
%15 = sitofp i32 %14 to double
%16 = call i32 @findletter(double %15)
%17 = load i32, i32* %12
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 3)
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %19)
%21 = load i32, i32* %19
%22 = sitofp i32 %21 to double
%23 = call i32 @findletter(double %22)
%24 = load i32, i32* %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 4)
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %26)
%28 = load i32, i32* %26
%29 = sitofp i32 %28 to double
%30 = call i32 @findletter(double %29)
%31 = load i32, i32* %26
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%34 = load i32, i32* %5
%35 = shl i32 %9, 24
%36 = ashr exact i32 %35, 24
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 1, i32 %34, i32 %36)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%39 = load i32, i32* %12
%40 = shl i32 %16, 24
%41 = ashr exact i32 %40, 24
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 2, i32 %39, i32 %41)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%44 = load i32, i32* %19
%45 = shl i32 %23, 24
%46 = ashr exact i32 %45, 24
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 3, i32 %44, i32 %46)
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%49 = load i32, i32* %26
%50 = shl i32 %30, 24
%51 = ashr exact i32 %50, 24
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 4, i32 %49, i32 %51)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%54 = add nsw i32 %17, %10
%55 = add nsw i32 %24, %54
%56 = add nsw i32 %31, %55
%57 = sdiv i32 %56, 4
%58 = sitofp i32 %57 to double
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
%60 = call i32 @findletter(double %58)
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), double %58, i32 %60)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}