#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int numberOfGrades, i, grade;
  int gradeTotal = 0;
  int failureCount = 0;
  float average;
  printf("How many grades will you be entering? ");
  scanf("%i", &numberOfGrades);
  for (i = 1; i <= numberOfGrades; ++i) {
    printf("Enter grade #%i: ", i);
    scanf("%i", &grade);
    gradeTotal += grade;
    if (grade < 65)
      ++failureCount;
  }
  average = (float)gradeTotal / numberOfGrades;
  printf("\n");
  printf("Grade average = %.2f\n", average);
  printf("Number of failures = %i\n", failureCount);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11be <main+0x9e>
mov    -0xc(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x41,-0x10(%rbp)
jge    11ab <main+0x8b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <main+0x90>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <main+0x42>
cvtsi2ssl -0x14(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe52(%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
sub    $0x18,%rsp
lea    0xebb(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11c9 <main+0x99>
lea    0xebb(%rip),%r14
lea    0xeb1(%rip),%r15
lea    0x14(%rsp),%r12
xor    %ebp,%ebp
xor    %r13d,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
add    %eax,%ebx
xor    %ecx,%ecx
cmp    $0x41,%eax
setl   %cl
add    %ecx,%r13d
mov    0xc(%rsp),%eax
cmp    %eax,%ebp
jl     1190 <main+0x60>
cvtsi2ss %ebx,%xmm1
jmp    11cc <main+0x9c>
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm0
divss  %xmm0,%xmm1
movss  %xmm1,0x10(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
movss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe47(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"How many grades will you be entering? \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [18 x i8] c"Enter grade #%i: \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [22 x i8] c"Grade average = %.2f\0A\00"
@.str.5 = [25 x i8] c"Number of failures = %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 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* %2)
store i32 1, i32* %3
br label %10
10: ; preds = %27, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %19, %18
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 65
br i1 %22, label %23, label %26
23: ; preds = %14
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %26
26: ; preds = %23, %14
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %10
30: ; preds = %10
%31 = load i32, i32* %5
%32 = sitofp i32 %31 to float
%33 = load i32, i32* %2
%34 = sitofp i32 %33 to float
%35 = fdiv float %32, %34
store float %35, float* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = load float, float* %7
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %38)
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"How many grades will you be entering? \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [18 x i8] c"Enter grade #%i: \00"
@.str.4 = [22 x i8] c"Grade average = %.2f\0A\00"
@.str.5 = [25 x i8] c"Number of failures = %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %25, label %9
9: ; preds = %0, %9
%10 = phi i32 [ %20, %9 ], [ 1, %0 ]
%11 = phi i32 [ %19, %9 ], [ 0, %0 ]
%12 = phi i32 [ %16, %9 ], [ 0, %0 ]
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = add nsw i32 %15, %12
%17 = icmp slt i32 %15, 65
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %11, %18
%20 = add nuw nsw i32 %10, 1
%21 = load i32, i32* %1
%22 = icmp slt i32 %10, %21
br i1 %22, label %9, label %23
23: ; preds = %9
%24 = sitofp i32 %16 to float
br label %25
25: ; preds = %23, %0
%26 = phi float [ 0.000000e+00, %0 ], [ %24, %23 ]
%27 = phi i32 [ 0, %0 ], [ %19, %23 ]
%28 = phi i32 [ %7, %0 ], [ %21, %23 ]
%29 = sitofp i32 %28 to float
%30 = fdiv float %26, %29
%31 = call i32 @putchar(i32 10)
%32 = fpext float %30 to double
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %27)
ret i32 0
}