#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("\nGrade 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)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe61(%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    0xece(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%eax
test   %eax,%eax
jle    11a8 <main+0x88>
lea    0xed1(%rip),%r14
lea    0xec7(%rip),%r15
lea    0x4(%rsp),%r12
xor    %ebp,%ebp
xor    %r13d,%r13d
xor    %ebx,%ebx
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
add    %eax,%ebx
xor    %ecx,%ecx
cmp    $0x41,%eax
setl   %cl
add    %ecx,%r13d
mov    (%rsp),%eax
cmp    %eax,%ebp
jl     1170 <main+0x50>
cvtsi2ss %ebx,%xmm0
jmp    11ab <main+0x8b>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <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 = [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 = [23 x i8] c"\0AGrade average = %.2f\0A\00"
@.str.4 = [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 = load float, float* %7
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %37)
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %39)
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.3 = [23 x i8] c"\0AGrade average = %.2f\0A\00"
@.str.4 = [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 = fpext float %30 to double
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %27)
ret i32 0
}