int triad(int len, double xx, double *restrict a, double *restrict b,
          double *restrict c) {
  int i, bytes = 24;
  a = __builtin_assume_aligned(a, 64);
  b = __builtin_assume_aligned(b, 64);
  c = __builtin_assume_aligned(c, 64);
  for (i = 0; i < len; i++)
    a[i] = b[i] + xx * c[i];
  return bytes;
}


x86 assembly (clang, -O0):
<triad>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x18,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118c <triad+0x8c>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x10(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113e <triad+0x3e>
mov    -0x30(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<triad>:
test   %edi,%edi
jle    120c <triad+0x10c>
mov    %edi,%r8d
cmp    $0x4,%edi
jae    1117 <triad+0x17>
xor    %edi,%edi
jmp    11f0 <triad+0xf0>
mov    %r8d,%edi
and    $0xfffffffc,%edi
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rdi),%rax
mov    %rax,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %rax,%rax
je     1212 <triad+0x112>
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
movapd (%rcx,%rax,8),%xmm2
mulpd  %xmm1,%xmm2
addpd  (%rdx,%rax,8),%xmm2
movapd 0x10(%rcx,%rax,8),%xmm3
mulpd  %xmm1,%xmm3
addpd  0x10(%rdx,%rax,8),%xmm3
movapd %xmm2,(%rsi,%rax,8)
movapd %xmm3,0x10(%rsi,%rax,8)
movupd 0x30(%rdx,%rax,8),%xmm2
movupd 0x30(%rcx,%rax,8),%xmm3
movapd 0x20(%rcx,%rax,8),%xmm4
mulpd  %xmm1,%xmm4
addpd  0x20(%rdx,%rax,8),%xmm4
mulpd  %xmm1,%xmm3
addpd  %xmm2,%xmm3
movapd %xmm4,0x20(%rsi,%rax,8)
movupd %xmm3,0x30(%rsi,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%r10
jne    1150 <triad+0x50>
test   $0x1,%r9b
je     11ea <triad+0xea>
movupd (%rdx,%rax,8),%xmm2
movupd 0x10(%rdx,%rax,8),%xmm3
movupd (%rcx,%rax,8),%xmm4
movupd 0x10(%rcx,%rax,8),%xmm5
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,(%rsi,%rax,8)
movupd %xmm5,0x10(%rsi,%rax,8)
cmp    %r8,%rdi
je     120c <triad+0x10c>
nop
movsd  (%rcx,%rdi,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rdx,%rdi,8),%xmm1
movsd  %xmm1,(%rsi,%rdi,8)
add    $0x1,%rdi
cmp    %rdi,%r8
jne    11f0 <triad+0xf0>
mov    $0x18,%eax
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    11b9 <triad+0xb9>
jmp    11ea <triad+0xea>

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

LLVM IR (-O2):
define i32 @triad(i32 %0, double %1, double* noalias %2, double* noalias %3, double* noalias %4) {
%6 = bitcast double* %2 to i8*
%7 = bitcast double* %3 to i8*
%8 = bitcast double* %4 to i8*
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %105
10: ; preds = %5
%11 = zext i32 %0 to i64
%12 = icmp ult i32 %0, 4
br i1 %12, label %93, label %13
13: ; preds = %10
%14 = and i64 %11, 4294967292
%15 = insertelement <2 x double> poison, double %1, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = insertelement <2 x double> poison, double %1, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = add nsw i64 %14, -4
%20 = lshr exact i64 %19, 2
%21 = add nuw nsw i64 %20, 1
%22 = and i64 %21, 1
%23 = icmp eq i64 %19, 0
br i1 %23, label %69, label %24
24: ; preds = %13
%25 = and i64 %21, 9223372036854775806
br label %26
26: ; preds = %26, %24
%27 = phi i64 [ 0, %24 ], [ %66, %26 ]
%28 = phi i64 [ 0, %24 ], [ %67, %26 ]
%29 = getelementptr inbounds double, double* %3, i64 %27
%30 = bitcast double* %29 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = getelementptr inbounds double, double* %29, i64 2
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %4, i64 %27
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %35, i64 2
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %16, <2 x double> %37, <2 x double> %31)
%42 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %40, <2 x double> %34)
%43 = getelementptr inbounds double, double* %2, i64 %27
%44 = bitcast double* %43 to <2 x double>*
store <2 x double> %41, <2 x double>* %44
%45 = getelementptr inbounds double, double* %43, i64 2
%46 = bitcast double* %45 to <2 x double>*
store <2 x double> %42, <2 x double>* %46
%47 = or i64 %27, 4
%48 = getelementptr inbounds double, double* %3, i64 %47
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = getelementptr inbounds double, double* %48, i64 2
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = getelementptr inbounds double, double* %4, i64 %47
%55 = bitcast double* %54 to <2 x double>*
%56 = load <2 x double>, <2 x double>* %55
%57 = getelementptr inbounds double, double* %54, i64 2
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %16, <2 x double> %56, <2 x double> %50)
%61 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %59, <2 x double> %53)
%62 = getelementptr inbounds double, double* %2, i64 %47
%63 = bitcast double* %62 to <2 x double>*
store <2 x double> %60, <2 x double>* %63
%64 = getelementptr inbounds double, double* %62, i64 2
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %61, <2 x double>* %65
%66 = add nuw i64 %27, 8
%67 = add i64 %28, 2
%68 = icmp eq i64 %67, %25
br i1 %68, label %69, label %26
69: ; preds = %26, %13
%70 = phi i64 [ 0, %13 ], [ %66, %26 ]
%71 = icmp eq i64 %22, 0
br i1 %71, label %91, label %72
72: ; preds = %69
%73 = getelementptr inbounds double, double* %3, i64 %70
%74 = bitcast double* %73 to <2 x double>*
%75 = load <2 x double>, <2 x double>* %74
%76 = getelementptr inbounds double, double* %73, i64 2
%77 = bitcast double* %76 to <2 x double>*
%78 = load <2 x double>, <2 x double>* %77
%79 = getelementptr inbounds double, double* %4, i64 %70
%80 = bitcast double* %79 to <2 x double>*
%81 = load <2 x double>, <2 x double>* %80
%82 = getelementptr inbounds double, double* %79, i64 2
%83 = bitcast double* %82 to <2 x double>*
%84 = load <2 x double>, <2 x double>* %83
%85 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %16, <2 x double> %81, <2 x double> %75)
%86 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %84, <2 x double> %78)
%87 = getelementptr inbounds double, double* %2, i64 %70
%88 = bitcast double* %87 to <2 x double>*
store <2 x double> %85, <2 x double>* %88
%89 = getelementptr inbounds double, double* %87, i64 2
%90 = bitcast double* %89 to <2 x double>*
store <2 x double> %86, <2 x double>* %90
br label %91
91: ; preds = %69, %72
%92 = icmp eq i64 %14, %11
br i1 %92, label %105, label %93
93: ; preds = %10, %91
%94 = phi i64 [ 0, %10 ], [ %14, %91 ]
br label %95
95: ; preds = %93, %95
%96 = phi i64 [ %103, %95 ], [ %94, %93 ]
%97 = getelementptr inbounds double, double* %3, i64 %96
%98 = load double, double* %97
%99 = getelementptr inbounds double, double* %4, i64 %96
%100 = load double, double* %99
%101 = tail call double @llvm.fmuladd.f64(double %1, double %100, double %98)
%102 = getelementptr inbounds double, double* %2, i64 %96
store double %101, double* %102
%103 = add nuw nsw i64 %96, 1
%104 = icmp eq i64 %103, %11
br i1 %104, label %105, label %95
105: ; preds = %95, %91, %5
ret i32 24
}