double average(double(*obs_ptr), unsigned long numberofframes) {
  double mean = 0.0;
  for (int dim1 = 0; dim1 < 10; dim1++) {
    mean += obs_ptr[dim1];
  }
  mean /= ((double)numberofframes);
  return mean;
}


x86 assembly (clang, -O0):
<average>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    114a <average+0x4a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    111b <average+0x1b>
movaps 0xeaf(%rip),%xmm0
movq   -0x10(%rbp),%xmm1
punpckldq %xmm0,%xmm1
movapd 0xeae(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<average>:
xorpd  %xmm0,%xmm0
addsd  (%rdi),%xmm0
addsd  0x8(%rdi),%xmm0
addsd  0x10(%rdi),%xmm0
addsd  0x18(%rdi),%xmm0
addsd  0x20(%rdi),%xmm0
addsd  0x28(%rdi),%xmm0
addsd  0x30(%rdi),%xmm0
addsd  0x38(%rdi),%xmm0
addsd  0x40(%rdi),%xmm0
addsd  0x48(%rdi),%xmm0
movq   %rsi,%xmm1
punpckldq 0xebe(%rip),%xmm1
subpd  0xec6(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @average(double* %0, i64 %1) {
%3 = alloca double*
%4 = alloca i64
%5 = alloca double
%6 = alloca i32
store double* %0, double** %3
store i64 %1, i64* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %7
7: ; preds = %18, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = load double*, double** %3
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %11, i64 %13
%15 = load double, double* %14
%16 = load double, double* %5
%17 = fadd double %16, %15
store double %17, double* %5
br label %18
18: ; preds = %10
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %7
21: ; preds = %7
%22 = load i64, i64* %4
%23 = uitofp i64 %22 to double
%24 = load double, double* %5
%25 = fdiv double %24, %23
store double %25, double* %5
%26 = load double, double* %5
ret double %26
}

LLVM IR (-O2):
define double @average(double* nocapture %0, i64 %1) {
%3 = load double, double* %0
%4 = fadd double %3, 0.000000e+00
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = fadd double %4, %6
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = fadd double %7, %9
%11 = getelementptr inbounds double, double* %0, i64 3
%12 = load double, double* %11
%13 = fadd double %10, %12
%14 = getelementptr inbounds double, double* %0, i64 4
%15 = load double, double* %14
%16 = fadd double %13, %15
%17 = getelementptr inbounds double, double* %0, i64 5
%18 = load double, double* %17
%19 = fadd double %16, %18
%20 = getelementptr inbounds double, double* %0, i64 6
%21 = load double, double* %20
%22 = fadd double %19, %21
%23 = getelementptr inbounds double, double* %0, i64 7
%24 = load double, double* %23
%25 = fadd double %22, %24
%26 = getelementptr inbounds double, double* %0, i64 8
%27 = load double, double* %26
%28 = fadd double %25, %27
%29 = getelementptr inbounds double, double* %0, i64 9
%30 = load double, double* %29
%31 = fadd double %28, %30
%32 = uitofp i64 %1 to double
%33 = fdiv double %31, %32
ret double %33
}