#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 */
float getAvg(float, float, int);
int /*<<< orphan*/ printf(char *, int, float);
void streamAvg(float arr[], int n) {
  float avg = 0;
  for (int i = 0; i < n; i++) {
    avg = getAvg(avg, arr[i], i);
    printf("Average of %d numbers is %f \n", i + 1, avg);
  }
}


x86 assembly (clang, -O0):
<streamAvg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118e <streamAvg+0x6e>
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mov    -0x14(%rbp),%edi
call   1040 <getAvg@plt>
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%esi
add    $0x1,%esi
movss  -0x10(%rbp),%xmm0
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <streamAvg+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<streamAvg>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    116c <streamAvg+0x4c>
mov    %rdi,%r14
mov    %esi,%r12d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
lea    0xec2(%rip),%r15
xchg   %ax,%ax
movss  (%r14,%rbx,4),%xmm1
mov    %ebx,%edi
call   1040 <getAvg@plt>
movss  %xmm0,0x4(%rsp)
add    $0x1,%rbx
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
movss  0x4(%rsp),%xmm0
cmp    %rbx,%r12
jne    1140 <streamAvg+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Average of %d numbers is %f \0A\00"
define void @streamAvg(float* %0, i32 %1) {
%3 = alloca float*
%4 = alloca i32
%5 = alloca float
%6 = alloca i32
store float* %0, float** %3
store i32 %1, i32* %4
store float 0.000000e+00, float* %5
store i32 0, i32* %6
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load float, float* %5
%13 = load float*, float** %3
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds float, float* %13, i64 %15
%17 = load float, float* %16
%18 = load i32, i32* %6
%19 = call float @getAvg(float %12, float %17, i32 %18)
store float %19, float* %5
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
%22 = load float, float* %5
%23 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %21, float %22)
br label %24
24: ; preds = %11
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %7
27: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Average of %d numbers is %f \0A\00"
define void @streamAvg(float* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %7
6: ; preds = %7, %2
ret void
7: ; preds = %4, %7
%8 = phi i64 [ 0, %4 ], [ %14, %7 ]
%9 = phi float [ 0.000000e+00, %4 ], [ %13, %7 ]
%10 = getelementptr inbounds float, float* %0, i64 %8
%11 = load float, float* %10
%12 = trunc i64 %8 to i32
%13 = tail call float @getAvg(float %9, float %11, i32 %12)
%14 = add nuw nsw i64 %8, 1
%15 = trunc i64 %14 to i32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %15, float %13)
%17 = icmp eq i64 %14, %5
br i1 %17, label %6, label %7
}