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


x86 assembly (clang, -O0):
<sum_d>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1178 <sum_d+0x78>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
sub    $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    1127 <sum_d+0x27>
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_d>:
movsd  0x8(%rdi),%xmm0
movsd  %xmm0,(%rsi)
cmp    $0x2,%edx
jl     11cb <sum_d+0xcb>
mov    %edx,%r9d
lea    -0x1(%r9),%rax
mov    $0x1,%ecx
cmp    $0x4,%rax
jbe    1195 <sum_d+0x95>
mov    %eax,%ecx
and    $0x3,%ecx
test   %rcx,%rcx
mov    $0x4,%edx
cmovne %rcx,%rdx
mov    %rax,%r8
sub    %rdx,%r8
neg    %rdx
lea    (%rax,%rdx,1),%rcx
add    $0x1,%rcx
lea    0x38(%rdi),%rdx
xor    %eax,%eax
nopl   0x0(%rax)
movupd -0x30(%rdx),%xmm0
movupd -0x20(%rdx),%xmm1
movupd -0x10(%rdx),%xmm2
movupd (%rdx),%xmm3
unpcklpd %xmm1,%xmm0
unpcklpd %xmm2,%xmm1
addpd  %xmm0,%xmm1
unpcklpd %xmm3,%xmm2
movhpd 0x10(%rdx),%xmm3
addpd  %xmm2,%xmm3
movupd %xmm1,0x8(%rsi,%rax,8)
movupd %xmm3,0x18(%rsi,%rax,8)
add    $0x4,%rax
add    $0x40,%rdx
cmp    %rax,%r8
jne    1150 <sum_d+0x50>
mov    %rcx,%rax
shl    $0x4,%rax
add    %rdi,%rax
add    $0x8,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  -0x10(%rax),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,(%rsi,%rcx,8)
add    $0x1,%rcx
add    $0x10,%rax
cmp    %rcx,%r9
jne    11b0 <sum_d+0xb0>
ret

LLVM IR (-O0):
define void @sum_d(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
%8 = load double*, double** %4
%9 = getelementptr inbounds double, double* %8, i64 1
%10 = load double, double* %9
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 0
store double %10, double* %12
store i32 1, i32* %7
br label %13
13: ; preds = %37, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %40
17: ; preds = %13
%18 = load double*, double** %4
%19 = load i32, i32* %7
%20 = mul nsw i32 2, %19
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %18, i64 %22
%24 = load double, double* %23
%25 = load double*, double** %4
%26 = load i32, i32* %7
%27 = mul nsw i32 2, %26
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %25, i64 %29
%31 = load double, double* %30
%32 = fadd double %24, %31
%33 = load double*, double** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
store double %32, double* %36
br label %37
37: ; preds = %17
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %13
40: ; preds = %13
ret void
}

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