#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() {
  float average;
  int counter, grade, total;
  total = 0;
  counter = 0;
  printf("Enter grade, -1 to end: ");
  scanf("%d", &grade);
  while (grade != -1) {
    total = total + grade;
    counter = counter + 1;
    printf("Enter grade, -1 to end: ");
    scanf("%d", &grade);
  }
  if (counter != 0) {
    average = (float)total / counter;
    printf("Class average is %.2f\n", average);
  } else
    printf("No grades were entered\n");
  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,-0xc(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0xffffffff,-0x10(%rbp)
je     119a <main+0x7a>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
jmp    115b <main+0x3b>
cmpl   $0x0,-0xc(%rbp)
je     11d3 <main+0xb3>
cvtsi2ssl -0x14(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe55(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11e1 <main+0xc1>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
je     11df <main+0xaf>
pxor   %xmm2,%xmm2
lea    0xea4(%rip),%r14
lea    0xeb6(%rip),%r15
lea    0xc(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
movd   %eax,%xmm0
movaps 0xe75(%rip),%xmm1
movss  %xmm0,%xmm1
paddd  %xmm1,%xmm2
movdqa %xmm2,0x10(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movdqa 0x10(%rsp),%xmm2
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
jne    1180 <main+0x50>
cvtdq2ps %xmm2,%xmm0
movaps %xmm0,%xmm1
shufps $0x55,%xmm0,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe56(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11eb <main+0xbb>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Enter grade, -1 to end: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Class average is %.2f\0A\00"
@.str.3 = [24 x i8] c"No grades were entered\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 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* %4)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = add nsw i32 %12, %13
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
br label %8
19: ; preds = %8
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to float
%25 = load i32, i32* %3
%26 = sitofp i32 %25 to float
%27 = fdiv float %24, %26
store float %27, float* %2
%28 = load float, float* %2
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %29)
br label %33
31: ; preds = %19
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Enter grade, -1 to end: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Class average is %.2f\0A\00"
@str = [23 x i8] c"No grades were entered\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 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 = icmp eq i32 %5, -1
br i1 %6, label %23, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %14, %7 ], [ %5, %0 ]
%9 = phi <2 x i32> [ %11, %7 ], [ zeroinitializer, %0 ]
%10 = insertelement <2 x i32> <i32 poison, i32 1>, i32 %8, i64 0
%11 = add nsw <2 x i32> %9, %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = sitofp <2 x i32> %11 to <2 x float>
%18 = extractelement <2 x float> %17, i64 0
%19 = extractelement <2 x float> %17, i64 1
%20 = fdiv float %18, %19
%21 = fpext float %20 to double
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %25
23: ; preds = %0
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
ret i32 0
}