float average(float arr[], int n) {
  int i;
  float sum = 0;
  printf("\nGet the array store address in callee function:\n");
  for (i = 0; i < n; i++) {
    sum += arr[i];
    printf("%d  ", &arr[i]);
  }
  return sum / n;
}


x86 assembly (clang, -O0):
<average>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118a <average+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <average+0x2c>
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<average>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
test   %r14d,%r14d
jle    1179 <average+0x59>
mov    %r14d,%ebp
xorps  %xmm0,%xmm0
lea    0xeb5(%rip),%r15
nopl   0x0(%rax,%rax,1)
addss  (%rbx),%xmm0
movss  %xmm0,0x4(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movss  0x4(%rsp),%xmm0
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1150 <average+0x30>
jmp    117c <average+0x5c>
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm1
divss  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"\0AGet the array store address in callee function:\0A\00"
@.str.1 = [5 x i8] c"%d \00"
define float @average(float* %0, i32 %1) {
%3 = alloca float*
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
store float* %0, float** %3
store i32 %1, i32* %4
store float 0.000000e+00, float* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load float*, float** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds float, float* %13, i64 %15
%17 = load float, float* %16
%18 = load float, float* %6
%19 = fadd float %18, %17
store float %19, float* %6
%20 = load float*, float** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds float, float* %20, i64 %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %23)
br label %25
25: ; preds = %12
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %8
28: ; preds = %8
%29 = load float, float* %6
%30 = load i32, i32* %4
%31 = sitofp i32 %30 to float
%32 = fdiv float %29, %31
ret float %32
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%d \00"
@str = [49 x i8] c"\0AGet the array store address in callee function:\00"
define float @average(float* %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %14, %7 ]
%9 = phi float [ 0.000000e+00, %5 ], [ %12, %7 ]
%10 = getelementptr inbounds float, float* %0, i64 %8
%11 = load float, float* %10
%12 = fadd float %9, %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %10)
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %16, label %7
16: ; preds = %7, %2
%17 = phi float [ 0.000000e+00, %2 ], [ %12, %7 ]
%18 = sitofp i32 %1 to float
%19 = fdiv float %17, %18
ret float %19
}