#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 */
scalar_t__ EOF;
double avrg(float, float);
int /*<<< orphan*/ free(float *);
float *malloc(int);
int /*<<< orphan*/ printf(char *, double);
float *realloc(float *, int);
scalar_t__ scanf(char *, float *);
int main() {
  float *array;
  int size = 10;
  int i = 0;
  float sum = 0;
  float count = 0;
  array = malloc(sizeof(float) * 10);
  while (scanf("%f", (array + i)) != EOF) {
    sum += *(array + i);
    count++;
    if (i == size - 1) {
      size *= 2;
      array = realloc(array, size);
    }
    i++;
  }
  free(array);
  printf("%f\n\n", sum);
  printf("%f\n\n", avrg(count, sum));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe53(%rip),%rdi
call   1080 <scanf@plt>
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
je     1227 <main+0xc7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xe1b(%rip),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1219 <main+0xb9>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119b <main+0x3b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc7(%rip),%rdi
call   1040 <printf@plt>
movss  -0x20(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
call   1050 <avrg@plt>
lea    0xdac(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rdi
mov    %rax,%rsi
call   1080 <scanf@plt>
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%rax
jne    11f0 <main+0x90>
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    %rbx,%r15
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe48(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
call   1050 <avrg@plt>
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%r12d
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
mov    $0x4,%ebp
xor    %r13d,%r13d
lea    0xdf6(%rip),%r14
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    %rbx,%r15
jmp    1247 <main+0xe7>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
lea    (%r15,%rbp,1),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x4,%rbp
mov    0x2daa(%rip),%rcx
cmp    (%rcx),%rax
je     11a7 <main+0x47>
movss  (%rsp),%xmm1
addss  (%rbx),%xmm1
movss  0x4(%rsp),%xmm0
addss  0xda2(%rip),%xmm0
lea    -0x1(%r12),%eax
cmp    %rax,%r13
movss  %xmm0,0x4(%rsp)
movss  %xmm1,(%rsp)
jne    1220 <main+0xc0>
add    %r12d,%r12d
mov    %r15,%rdi
mov    %r12d,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
jmp    1220 <main+0xc0>

LLVM IR (-O0):
@.str = [3 x i8] c"%f\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c"%f\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float*
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
store i32 10, i32* %3
store i32 0, i32* %4
store float 0.000000e+00, float* %5
store float 0.000000e+00, float* %6
%7 = call float* @malloc(i32 40)
store float* %7, float** %2
br label %8
8: ; preds = %36, %0
%9 = load float*, float** %2
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds float, float* %9, i64 %11
%13 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %12)
%14 = load i64, i64* @EOF
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %39
16: ; preds = %8
%17 = load float*, float** %2
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds float, float* %17, i64 %19
%21 = load float, float* %20
%22 = load float, float* %5
%23 = fadd float %22, %21
store float %23, float* %5
%24 = load float, float* %6
%25 = fadd float %24, 1.000000e+00
store float %25, float* %6
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 1
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %36
30: ; preds = %16
%31 = load i32, i32* %3
%32 = mul nsw i32 %31, 2
store i32 %32, i32* %3
%33 = load float*, float** %2
%34 = load i32, i32* %3
%35 = call float* @realloc(float* %33, i32 %34)
store float* %35, float** %2
br label %36
36: ; preds = %30, %16
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %8
39: ; preds = %8
%40 = load float*, float** %2
%41 = call i32 @free(float* %40)
%42 = load float, float* %5
%43 = fpext float %42 to double
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %43)
%45 = load float, float* %6
%46 = load float, float* %5
%47 = call double @avrg(float %45, float %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %47)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c"%f\0A\0A\00"
define i32 @main() {
%1 = tail call float* @malloc(i32 40)
%2 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %1)
%3 = load i64, i64* @EOF
%4 = icmp eq i64 %2, %3
br i1 %4, label %29, label %5
5: ; preds = %0, %21
%6 = phi i64 [ %24, %21 ], [ 0, %0 ]
%7 = phi float* [ %25, %21 ], [ %1, %0 ]
%8 = phi float [ %14, %21 ], [ 0.000000e+00, %0 ]
%9 = phi float [ %13, %21 ], [ 0.000000e+00, %0 ]
%10 = phi i32 [ %23, %21 ], [ 10, %0 ]
%11 = phi float* [ %22, %21 ], [ %1, %0 ]
%12 = load float, float* %7
%13 = fadd float %9, %12
%14 = fadd float %8, 1.000000e+00
%15 = add nsw i32 %10, -1
%16 = zext i32 %15 to i64
%17 = icmp eq i64 %6, %16
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = shl nsw i32 %10, 1
%20 = tail call float* @realloc(float* %11, i32 %19)
br label %21
21: ; preds = %18, %5
%22 = phi float* [ %20, %18 ], [ %11, %5 ]
%23 = phi i32 [ %19, %18 ], [ %10, %5 ]
%24 = add nuw i64 %6, 1
%25 = getelementptr inbounds float, float* %22, i64 %24
%26 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float* %25)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %5
29: ; preds = %21, %0
%30 = phi float* [ %1, %0 ], [ %22, %21 ]
%31 = phi float [ 0.000000e+00, %0 ], [ %13, %21 ]
%32 = phi float [ 0.000000e+00, %0 ], [ %14, %21 ]
%33 = tail call i32 @free(float* %30)
%34 = fpext float %31 to double
%35 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %34)
%36 = tail call double @avrg(float %32, float %31)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %36)
ret i32 0
}