void pnormsq2(double *normsq, double *X, int n) {
  double a = 0.0, b = 0.0;
  const int n2 = n * 2;
#pragma omp parallel for reduction(+ : a, b) schedule(static)
  for (int i = 0; i < n2; i += 2) {
    a += X[i] * X[i];
    b += X[i + 1] * X[i + 1];
  }
  normsq[0] = a;
  normsq[1] = b;
}


x86 assembly (clang, -O0):
<pnormsq2>:
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)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11ab <pnormsq2+0xab>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x30(%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    -0x30(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%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    -0x30(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x30(%rbp)
jmp    112f <pnormsq2+0x2f>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<pnormsq2>:
test   %edx,%edx
jle    1137 <pnormsq2+0x37>
add    %edx,%edx
movslq %edx,%rax
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
nop
movapd %xmm2,%xmm1
movupd (%rsi,%rcx,8),%xmm0
mulpd  %xmm0,%xmm0
movapd %xmm0,%xmm2
addpd  %xmm1,%xmm2
add    $0x2,%rcx
cmp    %rax,%rcx
jl     1110 <pnormsq2+0x10>
addpd  %xmm1,%xmm0
movupd %xmm0,(%rdi)
ret
xorps  %xmm0,%xmm0
movups %xmm0,(%rdi)
ret

LLVM IR (-O0):
define void @pnormsq2(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = 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
%11 = load i32, i32* %6
%12 = mul nsw i32 %11, 2
store i32 %12, i32* %9
store i32 0, i32* %10
br label %13
13: ; preds = %44, %3
%14 = load i32, i32* %10
%15 = load i32, i32* %9
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %47
17: ; preds = %13
%18 = load double*, double** %5
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %5
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double, double* %7
%29 = call double @llvm.fmuladd.f64(double %22, double %27, double %28)
store double %29, double* %7
%30 = load double*, double** %5
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %30, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %5
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %36, i64 %39
%41 = load double, double* %40
%42 = load double, double* %8
%43 = call double @llvm.fmuladd.f64(double %35, double %41, double %42)
store double %43, double* %8
br label %44
44: ; preds = %17
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 2
store i32 %46, i32* %10
br label %13
47: ; preds = %13
%48 = load double, double* %7
%49 = load double*, double** %4
%50 = getelementptr inbounds double, double* %49, i64 0
store double %48, double* %50
%51 = load double, double* %8
%52 = load double*, double** %4
%53 = getelementptr inbounds double, double* %52, i64 1
store double %51, double* %53
ret void
}

LLVM IR (-O2):
define void @pnormsq2(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 %13
8: ; preds = %13
%9 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %18, <2 x double> %15)
br label %10
10: ; preds = %8, %3
%11 = phi <2 x double> [ zeroinitializer, %3 ], [ %9, %8 ]
%12 = bitcast double* %0 to <2 x double>*
store <2 x double> %11, <2 x double>* %12
ret void
13: ; preds = %5, %13
%14 = phi i64 [ 0, %5 ], [ %20, %13 ]
%15 = phi <2 x double> [ zeroinitializer, %5 ], [ %19, %13 ]
%16 = getelementptr inbounds double, double* %1, i64 %14
%17 = bitcast double* %16 to <2 x double>*
%18 = load <2 x double>, <2 x double>* %17
%19 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %18, <2 x double> %15)
%20 = add nuw nsw i64 %14, 2
%21 = icmp slt i64 %20, %7
br i1 %21, label %13, label %8
}