#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 *);
void main() {
  int grade, i, total = 0, average;
  for (i = 0; i < 5; i += 1) {
    printf("Please enter a grade: ");
    scanf("%d", &grade);
    total += grade;
  }
  average = total / i;
  printf("The average of the %d grades is:  %d", i, average);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1175 <main+0x55>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xefa(%rip),%rbx
lea    0x4(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    0x4(%rsp),%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    0x4(%rsp),%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    0x4(%rsp),%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    0x4(%rsp),%ebp
movslq %ebp,%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x21,%rdx
add    %eax,%edx
lea    0xe42(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Please enter a grade: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [37 x i8] c"The average of the %d grades is: %d\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %2
br label %5
5: ; preds = %14, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = load i32, i32* %3
%13 = add nsw i32 %12, %11
store i32 %13, i32* %3
br label %14
14: ; preds = %8
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %5
17: ; preds = %5
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = sdiv i32 %18, %19
store i32 %20, i32* %4
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Please enter a grade: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [37 x i8] c"The average of the %d grades is: %d\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, %5
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = add nsw i32 %12, %9
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
%17 = add nsw i32 %16, %13
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = add nsw i32 %20, %17
%22 = sdiv i32 %21, 5
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %22)
ret void
}