int triad(int len, double xx, double *restrict a, double *restrict b,
          double *restrict c) {
  int i, bytes = 24;
  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)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1174 <triad+0x74>
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    1126 <triad+0x26>
mov    -0x30(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<triad>:
test   %edi,%edi
jle    121c <triad+0x11c>
mov    %edi,%r8d
cmp    $0x4,%edi
jae    1117 <triad+0x17>
xor    %edi,%edi
jmp    1200 <triad+0x100>
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     1222 <triad+0x122>
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
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)
movupd 0x20(%rdx,%rax,8),%xmm2
movupd 0x30(%rdx,%rax,8),%xmm3
movupd 0x20(%rcx,%rax,8),%xmm4
movupd 0x30(%rcx,%rax,8),%xmm5
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,0x20(%rsi,%rax,8)
movupd %xmm5,0x30(%rsi,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%r10
jne    1150 <triad+0x50>
test   $0x1,%r9b
je     11f6 <triad+0xf6>
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     121c <triad+0x11c>
nopl   0x0(%rax,%rax,1)
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    1200 <triad+0x100>
mov    $0x18,%eax
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    11c5 <triad+0xc5>
jmp    11f6 <triad+0xf6>

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
store i32 0, i32* %11
br label %13
13: ; preds = %34, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %37
17: ; preds = %13
%18 = load double*, double** %9
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double, double* %7
%24 = load double*, double** %10
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = call double @llvm.fmuladd.f64(double %23, double %28, double %22)
%30 = load double*, double** %8
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %17
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %13
37: ; preds = %13
%38 = load i32, i32* %12
ret i32 %38
}

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