#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 */
char getchar();
int /*<<< orphan*/ scanf(char *, float *);
float ave(void) {
  float sum = 0, ave, a;
  int n = 0;
  do {
    scanf("%f", &a);
    sum += a;
    n++;
  } while (getchar() != '\n');
  ave = sum / n;
  return ave;
}


x86 assembly (clang, -O0):
<ave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0xc(%rbp),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
jne    1137 <ave+0x17>
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ave>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
lea    0xec8(%rip),%r14
lea    0xc(%rsp),%rbx
xor    %ebp,%ebp
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
movss  0x8(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
add    $0x1,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
jne    1140 <ave+0x20>
cvtsi2ss %ebp,%xmm1
movss  0x8(%rsp),%xmm0
divss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%f\00"
define float @ave() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca i32
store float 0.000000e+00, float* %1
store i32 0, i32* %4
br label %5
5: ; preds = %12, %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %3)
%7 = load float, float* %3
%8 = load float, float* %1
%9 = fadd float %8, %7
store float %9, float* %1
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
store i32 %11, i32* %4
br label %12
12: ; preds = %5
%13 = call signext i8 (...) @getchar()
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %5, label %16
16: ; preds = %12
%17 = load float, float* %1
%18 = load i32, i32* %4
%19 = sitofp i32 %18 to float
%20 = fdiv float %17, %19
store float %20, float* %2
%21 = load float, float* %2
ret float %21
}

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
define float @ave() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi float [ 0.000000e+00, %0 ], [ %8, %3 ]
%5 = phi i32 [ 0, %0 ], [ %9, %3 ]
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %1)
%7 = load float, float* %1
%8 = fadd float %4, %7
%9 = add nuw nsw i32 %5, 1
%10 = call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %3
12: ; preds = %3
%13 = sitofp i32 %9 to float
%14 = fdiv float %8, %13
ret float %14
}