void __attribute__((no, noclone))
reduc_plus_double(double (*restrict a)[(1024 / sizeof(double))],
                  double *restrict r, int n) {
  for (int i = 0; i < n; i++) {
    r[i] = 0;
    for (int j = 0; j < (1024 / sizeof(double)); j++)
      r[i] += a[i][j];
  }
}


x86 assembly (clang, -O0):
<reduc_plus_double>:
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    1194 <reduc_plus_double+0x94>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x80,%rax
jae    1181 <reduc_plus_double+0x81>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
shl    $0xa,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1139 <reduc_plus_double+0x39>
jmp    1186 <reduc_plus_double+0x86>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1116 <reduc_plus_double+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<reduc_plus_double>:
test   %edx,%edx
jle    1159 <reduc_plus_double+0x59>
mov    %edx,%eax
add    $0x18,%rdi
xor    %ecx,%ecx
nopl   0x0(%rax)
xorpd  %xmm0,%xmm0
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
addsd  -0x18(%rdi,%rdx,8),%xmm0
addsd  -0x10(%rdi,%rdx,8),%xmm0
addsd  -0x8(%rdi,%rdx,8),%xmm0
addsd  (%rdi,%rdx,8),%xmm0
add    $0x4,%rdx
cmp    $0x80,%rdx
jne    1120 <reduc_plus_double+0x20>
movsd  %xmm0,(%rsi,%rcx,8)
add    $0x1,%rcx
add    $0x400,%rdi
cmp    %rax,%rcx
jne    1110 <reduc_plus_double+0x10>
ret

LLVM IR (-O0):
define void @reduc_plus_double([128 x double]* noalias %0, double* noalias %1, i32 %2) {
%4 = alloca [128 x double]*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store [128 x double]* %0, [128 x double]** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %41, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %44
13: ; preds = %9
%14 = load double*, double** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
store double 0.000000e+00, double* %17
store i32 0, i32* %8
br label %18
18: ; preds = %37, %13
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = icmp ult i64 %20, 128
br i1 %21, label %22, label %40
22: ; preds = %18
%23 = load [128 x double]*, [128 x double]** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [128 x double], [128 x double]* %23, i64 %25
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [128 x double], [128 x double]* %26, i64 0, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = fadd double %35, %30
store double %36, double* %34
br label %37
37: ; preds = %22
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %18
40: ; preds = %18
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %9
44: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @reduc_plus_double([128 x double]* noalias nocapture %0, double* noalias nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %8
7: ; preds = %11, %3
ret void
8: ; preds = %5, %11
%9 = phi i64 [ 0, %5 ], [ %12, %11 ]
%10 = getelementptr inbounds double, double* %1, i64 %9
br label %14
11: ; preds = %14
store double %31, double* %10
%12 = add nuw nsw i64 %9, 1
%13 = icmp eq i64 %12, %6
br i1 %13, label %7, label %8
14: ; preds = %14, %8
%15 = phi i64 [ 0, %8 ], [ %32, %14 ]
%16 = phi double [ 0.000000e+00, %8 ], [ %31, %14 ]
%17 = getelementptr inbounds [128 x double], [128 x double]* %0, i64 %9, i64 %15
%18 = load double, double* %17
%19 = fadd double %18, %16
%20 = or i64 %15, 1
%21 = getelementptr inbounds [128 x double], [128 x double]* %0, i64 %9, i64 %20
%22 = load double, double* %21
%23 = fadd double %22, %19
%24 = or i64 %15, 2
%25 = getelementptr inbounds [128 x double], [128 x double]* %0, i64 %9, i64 %24
%26 = load double, double* %25
%27 = fadd double %26, %23
%28 = or i64 %15, 3
%29 = getelementptr inbounds [128 x double], [128 x double]* %0, i64 %9, i64 %28
%30 = load double, double* %29
%31 = fadd double %30, %27
%32 = add nuw nsw i64 %15, 4
%33 = icmp eq i64 %32, 128
br i1 %33, label %11, label %14
}