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


x86 assembly (clang, -O0):
<sum_c>:
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    114f <sum_c+0x4f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%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_c+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_c>:
test   %edx,%edx
jle    1176 <sum_c+0x76>
mov    %edx,%r8d
cmp    $0x4,%edx
ja     1110 <sum_c+0x10>
xor    %ecx,%ecx
jmp    1155 <sum_c+0x55>
mov    %r8d,%eax
and    $0x3,%eax
test   %rax,%rax
mov    $0x4,%edx
cmovne %rax,%rdx
mov    %r8,%rcx
sub    %rdx,%rcx
lea    0x20(%rdi),%rdx
xor    %eax,%eax
xchg   %ax,%ax
movups -0x20(%rdx),%xmm0
movhps -0x10(%rdx),%xmm0
movups (%rdx),%xmm1
movhps 0x10(%rdx),%xmm1
movups %xmm0,(%rsi,%rax,8)
movups %xmm1,0x10(%rsi,%rax,8)
add    $0x4,%rax
add    $0x40,%rdx
cmp    %rax,%rcx
jne    1130 <sum_c+0x30>
mov    %rcx,%rax
shl    $0x4,%rax
add    %rax,%rdi
nop
movsd  (%rdi),%xmm0
movsd  %xmm0,(%rsi,%rcx,8)
add    $0x1,%rcx
add    $0x10,%rdi
cmp    %rcx,%r8
jne    1160 <sum_c+0x60>
ret

LLVM IR (-O0):
define void @sum_c(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 = %23, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %26
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** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
store double %18, double* %22
br label %23
23: ; preds = %12
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %8
26: ; preds = %8
ret void
}

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