double weighted_average(double(*obs_ptr), double(*weights_ptr)) {
  double mean = 0.0;
  double weight_sum = 0.0;
  for (int dim1 = 0; dim1 < 10; dim1++) {
    mean += obs_ptr[dim1];
    weight_sum += weights_ptr[dim1];
  }
  mean /= weight_sum;
  return mean;
}


x86 assembly (clang, -O0):
<weighted_average>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    1169 <weighted_average+0x69>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1123 <weighted_average+0x23>
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<weighted_average>:
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
movsd  0x10(%rdi),%xmm2
movsd  0x18(%rdi),%xmm3
movhpd (%rsi),%xmm0
xorpd  %xmm4,%xmm4
addpd  %xmm0,%xmm4
movhpd 0x8(%rsi),%xmm1
addpd  %xmm4,%xmm1
movhpd 0x10(%rsi),%xmm2
movhpd 0x18(%rsi),%xmm3
addpd  %xmm1,%xmm2
movsd  0x20(%rdi),%xmm0
movhpd 0x20(%rsi),%xmm0
addpd  %xmm2,%xmm3
movsd  0x28(%rdi),%xmm1
movhpd 0x28(%rsi),%xmm1
addpd  %xmm3,%xmm0
movsd  0x30(%rdi),%xmm2
movhpd 0x30(%rsi),%xmm2
addpd  %xmm0,%xmm1
movsd  0x38(%rdi),%xmm3
movhpd 0x38(%rsi),%xmm3
addpd  %xmm1,%xmm2
movsd  0x40(%rdi),%xmm1
movhpd 0x40(%rsi),%xmm1
addpd  %xmm2,%xmm3
movsd  0x48(%rdi),%xmm0
movhpd 0x48(%rsi),%xmm0
addpd  %xmm3,%xmm1
addpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
divsd  %xmm1,%xmm0
ret

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

LLVM IR (-O2):
define double @weighted_average(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = load double, double* %1
%5 = insertelement <2 x double> poison, double %3, i64 0
%6 = insertelement <2 x double> %5, double %4, i64 1
%7 = fadd <2 x double> %6, zeroinitializer
%8 = getelementptr inbounds double, double* %0, i64 1
%9 = load double, double* %8
%10 = getelementptr inbounds double, double* %1, i64 1
%11 = load double, double* %10
%12 = insertelement <2 x double> poison, double %9, i64 0
%13 = insertelement <2 x double> %12, double %11, i64 1
%14 = fadd <2 x double> %7, %13
%15 = getelementptr inbounds double, double* %0, i64 2
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %1, i64 2
%18 = load double, double* %17
%19 = insertelement <2 x double> poison, double %16, i64 0
%20 = insertelement <2 x double> %19, double %18, i64 1
%21 = fadd <2 x double> %14, %20
%22 = getelementptr inbounds double, double* %0, i64 3
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %1, i64 3
%25 = load double, double* %24
%26 = insertelement <2 x double> poison, double %23, i64 0
%27 = insertelement <2 x double> %26, double %25, i64 1
%28 = fadd <2 x double> %21, %27
%29 = getelementptr inbounds double, double* %0, i64 4
%30 = load double, double* %29
%31 = getelementptr inbounds double, double* %1, i64 4
%32 = load double, double* %31
%33 = insertelement <2 x double> poison, double %30, i64 0
%34 = insertelement <2 x double> %33, double %32, i64 1
%35 = fadd <2 x double> %28, %34
%36 = getelementptr inbounds double, double* %0, i64 5
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %1, i64 5
%39 = load double, double* %38
%40 = insertelement <2 x double> poison, double %37, i64 0
%41 = insertelement <2 x double> %40, double %39, i64 1
%42 = fadd <2 x double> %35, %41
%43 = getelementptr inbounds double, double* %0, i64 6
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %1, i64 6
%46 = load double, double* %45
%47 = insertelement <2 x double> poison, double %44, i64 0
%48 = insertelement <2 x double> %47, double %46, i64 1
%49 = fadd <2 x double> %42, %48
%50 = getelementptr inbounds double, double* %0, i64 7
%51 = load double, double* %50
%52 = getelementptr inbounds double, double* %1, i64 7
%53 = load double, double* %52
%54 = insertelement <2 x double> poison, double %51, i64 0
%55 = insertelement <2 x double> %54, double %53, i64 1
%56 = fadd <2 x double> %49, %55
%57 = getelementptr inbounds double, double* %0, i64 8
%58 = load double, double* %57
%59 = getelementptr inbounds double, double* %1, i64 8
%60 = load double, double* %59
%61 = insertelement <2 x double> poison, double %58, i64 0
%62 = insertelement <2 x double> %61, double %60, i64 1
%63 = fadd <2 x double> %56, %62
%64 = getelementptr inbounds double, double* %0, i64 9
%65 = load double, double* %64
%66 = getelementptr inbounds double, double* %1, i64 9
%67 = load double, double* %66
%68 = insertelement <2 x double> poison, double %65, i64 0
%69 = insertelement <2 x double> %68, double %67, i64 1
%70 = fadd <2 x double> %63, %69
%71 = extractelement <2 x double> %70, i64 0
%72 = extractelement <2 x double> %70, i64 1
%73 = fdiv double %71, %72
ret double %73
}