#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 printf(char *, ...);
int scanf(char *, float *);
main() {
  float num, sum = 0.0;
  int n = 0;
  printf("Let's average numbers\n");
  printf("Enter 'quit' to terminate\n");
  while (printf("Enter value #%d: ", n + 1), scanf("%f", &num) == 1) {
    sum += num;
    n++;
  }
  printf("Averate is %f\n", sum / (float)n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11a4 <main+0x84>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <main+0x3a>
movss  -0xc(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe8a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
xor    %ebx,%ebx
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
xorps  %xmm1,%xmm1
cmp    $0x1,%eax
jne    11d1 <main+0xa1>
xorps  %xmm1,%xmm1
lea    0xe7a(%rip),%r14
lea    0xe85(%rip),%r15
mov    %rsp,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addss  (%rsp),%xmm1
movss  %xmm1,0x4(%rsp)
lea    0x2(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movss  0x4(%rsp),%xmm1
add    $0x1,%ebx
cmp    $0x1,%eax
je     11a0 <main+0x70>
cvtsi2ss %ebx,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe2e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Let's average numbers\0A\00"
@.str.1 = [27 x i8] c"Enter 'quit' to terminate\0A\00"
@.str.2 = [18 x i8] c"Enter value #%d: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [15 x i8] c"Averate is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %13, %0
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = load float, float* %2
%15 = load float, float* %3
%16 = fadd float %15, %14
store float %16, float* %3
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %7
19: ; preds = %7
%20 = load float, float* %3
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to float
%23 = fdiv float %20, %22
%24 = fpext float %23 to double
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %24)
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str.2 = [18 x i8] c"Enter value #%d: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [15 x i8] c"Averate is %f\0A\00"
@str = [22 x i8] c"Let's average numbers\00"
@str.5 = [26 x i8] c"Enter 'quit' to terminate\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 1)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %17
8: ; preds = %0, %8
%9 = phi i32 [ %13, %8 ], [ 1, %0 ]
%10 = phi float [ %12, %8 ], [ 0.000000e+00, %0 ]
%11 = load float, float* %1
%12 = fadd float %10, %11
%13 = add nuw nsw i32 %9, 1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %8, label %17
17: ; preds = %8, %0
%18 = phi float [ 0.000000e+00, %0 ], [ %12, %8 ]
%19 = phi i32 [ 0, %0 ], [ %9, %8 ]
%20 = sitofp i32 %19 to float
%21 = fdiv float %18, %20
%22 = fpext float %21 to double
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %22)
ret i32 0
}