#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 */
typedef int /*<<< orphan*/ c;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ferror(int /*<<< orphan*/);
size_t fread(float *, int, int, int /*<<< orphan*/);
scalar_t__ hypot(float, float);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, float);
int /*<<< orphan*/ stdin;
void average(int samples) {
  float c[2];
  int n = 0;
  float sum = 0;
  size_t s;
  while (1) {
    s = fread(c, sizeof(c), 1, stdin);
    if (!s) {
      if (!ferror(stdin))
        break;
      if (s < 0) {
        perror("read");
        exit(1);
      }
    }
    sum += hypot(c[0], c[1]);
    if (n++ % samples)
      continue;
    printf("%f\n", sum / samples);
    sum = 0;
  }
}


x86 assembly (clang, -O0):
<average>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%ecx
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e7 <average+0x87>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%eax
jne    11c1 <average+0x61>
jmp    1249 <average+0xe9>
cmpq   $0x0,-0x20(%rbp)
jae    11e2 <average+0x82>
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11e7 <average+0x87>
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
call   1060 <hypot@plt>
cvtsi2ss %rax,%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cltd
idivl  -0x4(%rbp)
cmp    $0x0,%edx
je     1222 <average+0xc2>
jmp    117a <average+0x1a>
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0x4(%rbp),%xmm1
divss  %xmm1,%xmm0
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    117a <average+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<average>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
cvtsi2ss %edi,%xmm0
movss  %xmm0,0x4(%rsp)
xor    %ebp,%ebp
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    0x2e7f(%rip),%r12
lea    0x8(%rsp),%r14
lea    0xe8b(%rip),%r15
jmp    1188 <average+0x48>
nopw   0x0(%rax,%rax,1)
movss  %xmm0,(%rsp)
add    $0x1,%ebp
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
test   %rax,%rax
jne    11b0 <average+0x70>
mov    (%r12),%edi
call   1030 <ferror@plt>
test   %eax,%eax
je     11f1 <average+0xb1>
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1060 <hypot@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm0
mov    %ebp,%eax
cltd
idiv   %ebx
test   %edx,%edx
jne    1180 <average+0x40>
divss  0x4(%rsp),%xmm0
mov    %r15,%rdi
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
jmp    1180 <average+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"read\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define void @average(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x float]
%4 = alloca i32
%5 = alloca float
%6 = alloca i64
store i32 %0, i32* %2
store i32 0, i32* %4
store float 0.000000e+00, float* %5
br label %7
7: ; preds = %1, %39, %40
%8 = getelementptr inbounds [2 x float], [2 x float]* %3, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i64 @fread(float* %8, i32 8, i32 1, i32 %9)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %7
%14 = load i32, i32* @stdin
%15 = call i32 @ferror(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
br label %46
18: ; preds = %13
%19 = load i64, i64* %6
%20 = icmp ult i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %18
br label %25
25: ; preds = %24, %7
%26 = getelementptr inbounds [2 x float], [2 x float]* %3, i64 0, i64 0
%27 = load float, float* %26
%28 = getelementptr inbounds [2 x float], [2 x float]* %3, i64 0, i64 1
%29 = load float, float* %28
%30 = call i64 @hypot(float %27, float %29)
%31 = sitofp i64 %30 to float
%32 = load float, float* %5
%33 = fadd float %32, %31
store float %33, float* %5
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
%36 = load i32, i32* %2
%37 = srem i32 %34, %36
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %25
br label %7
40: ; preds = %25
%41 = load float, float* %5
%42 = load i32, i32* %2
%43 = sitofp i32 %42 to float
%44 = fdiv float %41, %43
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float %44)
store float 0.000000e+00, float* %5
br label %7
46: ; preds = %17
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [4 x i8] c"%f\0A\00"
define void @average(i32 %0) {
%2 = alloca [2 x float]
%3 = bitcast [2 x float]* %2 to i8*
%4 = getelementptr inbounds [2 x float], [2 x float]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x float], [2 x float]* %2, i64 0, i64 1
%6 = sitofp i32 %0 to float
br label %7
7: ; preds = %29, %1
%8 = phi float [ 0.000000e+00, %1 ], [ %30, %29 ]
%9 = phi i32 [ 0, %1 ], [ %23, %29 ]
%10 = load i32, i32* @stdin
%11 = call i64 @fread(float* %4, i32 8, i32 1, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = load i32, i32* @stdin
%15 = call i32 @ferror(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %13, %7
%18 = load float, float* %4
%19 = load float, float* %5
%20 = call i64 @hypot(float %18, float %19)
%21 = sitofp i64 %20 to float
%22 = fadd float %8, %21
%23 = add nuw nsw i32 %9, 1
%24 = srem i32 %9, %0
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %17
%27 = fdiv float %22, %6
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float %27)
br label %29
29: ; preds = %26, %17
%30 = phi float [ %22, %17 ], [ 0.000000e+00, %26 ]
br label %7
31: ; preds = %13
ret void
}