void sum_a(const double *restrict input, double *restrict output, int len) {
  for (int i = 0; i < len; i++)
    output[i] = input[2 * i] + input[2 * i + 1];
}


x86 assembly (clang, -O0):
<sum_a>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1164 <sum_a+0x64>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1116 <sum_a+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_a>:
test   %edx,%edx
jle    11ab <sum_a+0xab>
mov    %edx,%r8d
cmp    $0x4,%edx
jae    1114 <sum_a+0x14>
xor    %ecx,%ecx
jmp    1180 <sum_a+0x80>
mov    %r8d,%ecx
and    $0xfffffffc,%ecx
lea    0x0(,%r8,8),%rdx
and    $0xffffffffffffffe0,%rdx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movupd (%rdi,%rax,2),%xmm0
movupd 0x10(%rdi,%rax,2),%xmm1
movupd 0x20(%rdi,%rax,2),%xmm2
movupd 0x30(%rdi,%rax,2),%xmm3
movapd %xmm0,%xmm4
unpcklpd %xmm1,%xmm4
movapd %xmm2,%xmm5
unpcklpd %xmm3,%xmm5
unpckhpd %xmm1,%xmm0
addpd  %xmm4,%xmm0
unpckhpd %xmm3,%xmm2
addpd  %xmm5,%xmm2
movupd %xmm0,(%rsi,%rax,1)
movupd %xmm2,0x10(%rsi,%rax,1)
add    $0x20,%rax
cmp    %rax,%rdx
jne    1130 <sum_a+0x30>
cmp    %r8,%rcx
je     11ab <sum_a+0xab>
mov    %rcx,%rax
shl    $0x4,%rax
add    %rdi,%rax
add    $0x8,%rax
xchg   %ax,%ax
movsd  -0x8(%rax),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,(%rsi,%rcx,8)
add    $0x1,%rcx
add    $0x10,%rax
cmp    %rcx,%r8
jne    1190 <sum_a+0x90>
ret

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

LLVM IR (-O2):
define void @sum_a(double* noalias nocapture %0, double* noalias nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %37
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = icmp ult i32 %2, 4
br i1 %7, label %35, label %8
8: ; preds = %5
%9 = and i64 %6, 4294967292
br label %10
10: ; preds = %10, %8
%11 = phi i64 [ 0, %8 ], [ %31, %10 ]
%12 = shl nuw nsw i64 %11, 1
%13 = shl i64 %11, 1
%14 = or i64 %13, 4
%15 = getelementptr inbounds double, double* %0, i64 %12
%16 = getelementptr inbounds double, double* %0, i64 %14
%17 = bitcast double* %15 to <4 x double>*
%18 = bitcast double* %16 to <4 x double>*
%19 = load <4 x double>, <4 x double>* %17
%20 = load <4 x double>, <4 x double>* %18
%21 = shufflevector <4 x double> %19, <4 x double> poison, <2 x i32> <i32 0, i32 2>
%22 = shufflevector <4 x double> %20, <4 x double> poison, <2 x i32> <i32 0, i32 2>
%23 = shufflevector <4 x double> %19, <4 x double> poison, <2 x i32> <i32 1, i32 3>
%24 = shufflevector <4 x double> %20, <4 x double> poison, <2 x i32> <i32 1, i32 3>
%25 = fadd <2 x double> %21, %23
%26 = fadd <2 x double> %22, %24
%27 = getelementptr inbounds double, double* %1, i64 %11
%28 = bitcast double* %27 to <2 x double>*
store <2 x double> %25, <2 x double>* %28
%29 = getelementptr inbounds double, double* %27, i64 2
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> %26, <2 x double>* %30
%31 = add nuw i64 %11, 4
%32 = icmp eq i64 %31, %9
br i1 %32, label %33, label %10
33: ; preds = %10
%34 = icmp eq i64 %9, %6
br i1 %34, label %37, label %35
35: ; preds = %5, %33
%36 = phi i64 [ 0, %5 ], [ %9, %33 ]
br label %38
37: ; preds = %38, %33, %3
ret void
38: ; preds = %35, %38
%39 = phi i64 [ %48, %38 ], [ %36, %35 ]
%40 = shl nuw nsw i64 %39, 1
%41 = getelementptr inbounds double, double* %0, i64 %40
%42 = load double, double* %41
%43 = or i64 %40, 1
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = load double, double* %44
%46 = fadd double %42, %45
%47 = getelementptr inbounds double, double* %1, i64 %39
store double %46, double* %47
%48 = add nuw nsw i64 %39, 1
%49 = icmp eq i64 %48, %6
br i1 %49, label %37, label %38
}