void main() {
  float average(float array[], int n);
  float score_1[5] = {98.5, 97, 91.5, 60, 55};
  float score_2[10] = {67.5, 89.5, 99, 69.5, 77, 89.5, 76.5, 54, 60, 99.5};
  int i;
  printf("Get the array a store address in main function:\n");
  for (i = 0; i < 5; i++) {
    printf("%d  ", &score_1[i]);
  }
  printf("\nGet the array b store address in main function:\n");
  for (i = 0; i < 10; i++) {
    printf("%d  ", &score_2[i]);
  }
  printf("\nThe average of class A is %6.2f", average(score_1, 5));
  printf("\nThe average of class B is %6.2f\n", average(score_2, 10));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebc(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xebe(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x5,-0x54(%rbp)
jge    11b6 <main+0x86>
movslq -0x54(%rbp),%rax
lea    -0x20(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1181 <main+0x51>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0xa,-0x54(%rbp)
jge    1200 <main+0xd0>
movslq -0x54(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11cb <main+0x9b>
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1050 <average@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe97(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    $0xa,%esi
call   1050 <average@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe98(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    0xecd(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%r12
mov    0xee2(%rip),%rax
mov    %rax,0x40(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x40(%rsp),%r14
lea    0x30(%rsp),%r13
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%rbx
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x24(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x28(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x2c(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x34(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x38(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x3c(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x44(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x5,%esi
call   1050 <average@plt>
cvtss2sd %xmm0,%xmm0
lea    0xdb2(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r12,%rdi
mov    $0xa,%esi
call   1050 <average@plt>
cvtss2sd %xmm0,%xmm0
lea    0xdb4(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.score_1 = [5 x float] [float 9.850000e+01, float 9.700000e+01, float 9.150000e+01, float 6.000000e+01, float 5.500000e+01]
@__const.main.score_2 = [10 x float] [float 6.750000e+01, float 8.950000e+01, float 9.900000e+01, float 6.950000e+01, float 7.700000e+01, float 8.950000e+01, float 7.650000e+01, float 5.400000e+01, float 6.000000e+01, float 9.950000e+01]
@.str = [49 x i8] c"Get the array a store address in main function:\0A\00"
@.str.1 = [5 x i8] c"%d \00"
@.str.2 = [50 x i8] c"\0AGet the array b store address in main function:\0A\00"
@.str.3 = [33 x i8] c"\0AThe average of class A is %6.2f\00"
@.str.4 = [34 x i8] c"\0AThe average of class B is %6.2f\0A\00"
define void @main() {
%1 = alloca [5 x float]
%2 = alloca [10 x float]
%3 = alloca i32
%4 = bitcast [5 x float]* %1 to i8*
%5 = bitcast [10 x float]* %2 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 5
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [5 x float], [5 x float]* %1, i64 0, i64 %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %13)
br label %15
15: ; preds = %10
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %20
20: ; preds = %28, %18
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %26)
br label %28
28: ; preds = %23
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %20
31: ; preds = %20
%32 = getelementptr inbounds [5 x float], [5 x float]* %1, i64 0, i64 0
%33 = call float @average(float* %32, i32 5)
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), double %34)
%36 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 0
%37 = call float @average(float* %36, i32 10)
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), double %38)
ret void
}

LLVM IR (-O2):
@__const.main.score_1 = [5 x float] [float 9.850000e+01, float 9.700000e+01, float 9.150000e+01, float 6.000000e+01, float 5.500000e+01]
@__const.main.score_2 = [10 x float] [float 6.750000e+01, float 8.950000e+01, float 9.900000e+01, float 6.950000e+01, float 7.700000e+01, float 8.950000e+01, float 7.650000e+01, float 5.400000e+01, float 6.000000e+01, float 9.950000e+01]
@.str.1 = [5 x i8] c"%d \00"
@.str.3 = [33 x i8] c"\0AThe average of class A is %6.2f\00"
@.str.4 = [34 x i8] c"\0AThe average of class B is %6.2f\0A\00"
@str = [48 x i8] c"Get the array a store address in main function:\00"
@str.5 = [49 x i8] c"\0AGet the array b store address in main function:\00"
define void @main() {
%1 = alloca [5 x float]
%2 = alloca [10 x float]
%3 = bitcast [5 x float]* %1 to i8*
%4 = bitcast [10 x float]* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [5 x float], [5 x float]* %1, i64 0, i64 0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %6)
%8 = getelementptr inbounds [5 x float], [5 x float]* %1, i64 0, i64 1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %8)
%10 = getelementptr inbounds [5 x float], [5 x float]* %1, i64 0, i64 2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %10)
%12 = getelementptr inbounds [5 x float], [5 x float]* %1, i64 0, i64 3
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %12)
%14 = getelementptr inbounds [5 x float], [5 x float]* %1, i64 0, i64 4
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.5, i64 0, i64 0))
%17 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %17)
%19 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 1
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %19)
%21 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 2
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %21)
%23 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 3
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %23)
%25 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 4
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %25)
%27 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 5
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %27)
%29 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 6
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %29)
%31 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 7
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %31)
%33 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 8
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %33)
%35 = getelementptr inbounds [10 x float], [10 x float]* %2, i64 0, i64 9
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %35)
%37 = call float @average(float* %6, i32 5)
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), double %38)
%40 = call float @average(float* %17, i32 10)
%41 = fpext float %40 to double
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), double %41)
ret void
}