void pouter2(double *outer, double *X, int n) {
  double aa = 0.0, bb = 0.0, ab = 0.0;
  const int n2 = n * 2;
#pragma omp parallel for reduction(+ : aa, bb, ab) schedule(static)
  for (int i = 0; i < n2; i += 2) {
    aa += X[i] * X[i];
    bb += X[i + 1] * X[i + 1];
    ab += X[i] * X[i + 1];
  }
  outer[0] = aa;
  outer[1] = bb;
  outer[2] = ab;
}


x86 assembly (clang, -O0):
<pouter2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11e4 <pouter2+0xe4>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x38(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x38(%rbp)
jmp    1137 <pouter2+0x37>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<pouter2>:
test   %edx,%edx
jle    1154 <pouter2+0x54>
add    %edx,%edx
movslq %edx,%rax
xorpd  %xmm3,%xmm3
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm3,%xmm1
movupd (%rsi,%rcx,8),%xmm2
movapd %xmm2,%xmm4
unpckhpd %xmm2,%xmm4
mulsd  %xmm2,%xmm4
mulpd  %xmm2,%xmm2
movapd %xmm2,%xmm3
addpd  %xmm1,%xmm3
addsd  %xmm4,%xmm0
add    $0x2,%rcx
cmp    %rax,%rcx
jl     1120 <pouter2+0x20>
addpd  %xmm1,%xmm2
jmp    115c <pouter2+0x5c>
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
movupd %xmm2,(%rdi)
movsd  %xmm0,0x10(%rdi)
ret

LLVM IR (-O0):
define void @pouter2(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
%12 = load i32, i32* %6
%13 = mul nsw i32 %12, 2
store i32 %13, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %58, %3
%15 = load i32, i32* %11
%16 = load i32, i32* %10
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %61
18: ; preds = %14
%19 = load double*, double** %5
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load double*, double** %5
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = load double, double* %7
%30 = call double @llvm.fmuladd.f64(double %23, double %28, double %29)
store double %30, double* %7
%31 = load double*, double** %5
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %31, i64 %34
%36 = load double, double* %35
%37 = load double*, double** %5
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %37, i64 %40
%42 = load double, double* %41
%43 = load double, double* %8
%44 = call double @llvm.fmuladd.f64(double %36, double %42, double %43)
store double %44, double* %8
%45 = load double*, double** %5
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double*, double** %5
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %50, i64 %53
%55 = load double, double* %54
%56 = load double, double* %9
%57 = call double @llvm.fmuladd.f64(double %49, double %55, double %56)
store double %57, double* %9
br label %58
58: ; preds = %18
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 2
store i32 %60, i32* %11
br label %14
61: ; preds = %14
%62 = load double, double* %7
%63 = load double*, double** %4
%64 = getelementptr inbounds double, double* %63, i64 0
store double %62, double* %64
%65 = load double, double* %8
%66 = load double*, double** %4
%67 = getelementptr inbounds double, double* %66, i64 1
store double %65, double* %67
%68 = load double, double* %9
%69 = load double*, double** %4
%70 = getelementptr inbounds double, double* %69, i64 2
store double %68, double* %70
ret void
}

LLVM IR (-O2):
define void @pouter2(double* nocapture writeonly %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = shl nuw nsw i32 %2, 1
%7 = sext i32 %6 to i64
br label %15
8: ; preds = %15
%9 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %21, <2 x double> %18)
br label %10
10: ; preds = %8, %3
%11 = phi double [ 0.000000e+00, %3 ], [ %25, %8 ]
%12 = phi <2 x double> [ zeroinitializer, %3 ], [ %9, %8 ]
%13 = bitcast double* %0 to <2 x double>*
store <2 x double> %12, <2 x double>* %13
%14 = getelementptr inbounds double, double* %0, i64 2
store double %11, double* %14
ret void
15: ; preds = %5, %15
%16 = phi i64 [ 0, %5 ], [ %26, %15 ]
%17 = phi double [ 0.000000e+00, %5 ], [ %25, %15 ]
%18 = phi <2 x double> [ zeroinitializer, %5 ], [ %22, %15 ]
%19 = getelementptr inbounds double, double* %1, i64 %16
%20 = bitcast double* %19 to <2 x double>*
%21 = load <2 x double>, <2 x double>* %20
%22 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %21, <2 x double> %18)
%23 = extractelement <2 x double> %21, i64 0
%24 = extractelement <2 x double> %21, i64 1
%25 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %17)
%26 = add nuw nsw i64 %16, 2
%27 = icmp slt i64 %26, %7
br i1 %27, label %15, label %8
}