void vec_scaledy_add(double z[], const double x[], const double y[],
                     double y_scale, int n) {
  int i;
  for (i = 0; i < n; i++)
    z[i] = x[i] + y[i] * y_scale;
}


x86 assembly (clang, -O0):
<vec_scaledy_add>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    116d <vec_scaledy_add+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    111f <vec_scaledy_add+0x1f>
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_scaledy_add>:
test   %ecx,%ecx
jle    129f <vec_scaledy_add+0x19f>
mov    %ecx,%r8d
cmp    $0x4,%ecx
jae    1177 <vec_scaledy_add+0x77>
xor    %ecx,%ecx
mov    %rcx,%rax
not    %rax
test   $0x1,%r8b
je     1135 <vec_scaledy_add+0x35>
movsd  (%rdx,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rsi,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
or     $0x1,%rcx
add    %r8,%rax
je     129f <vec_scaledy_add+0x19f>
xchg   %ax,%ax
movsd  (%rdx,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rsi,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
movsd  0x8(%rdx,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rsi,%rcx,8),%xmm1
movsd  %xmm1,0x8(%rdi,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%r8
jne    1140 <vec_scaledy_add+0x40>
jmp    129f <vec_scaledy_add+0x19f>
lea    (%rdi,%r8,8),%rcx
lea    (%rsi,%r8,8),%rax
cmp    %rdi,%rax
seta   %r10b
lea    (%rdx,%r8,8),%rax
cmp    %rsi,%rcx
seta   %r11b
cmp    %rdi,%rax
seta   %al
cmp    %rdx,%rcx
seta   %r9b
xor    %ecx,%ecx
test   %r11b,%r10b
jne    1112 <vec_scaledy_add+0x12>
and    %r9b,%al
jne    1112 <vec_scaledy_add+0x12>
mov    %r8d,%ecx
and    $0xfffffffc,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rcx),%rax
mov    %rax,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %rax,%rax
je     12a0 <vec_scaledy_add+0x1a0>
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movupd (%rsi,%rax,8),%xmm2
movupd 0x10(%rsi,%rax,8),%xmm3
movupd (%rdx,%rax,8),%xmm4
movupd 0x10(%rdx,%rax,8),%xmm5
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,(%rdi,%rax,8)
movupd %xmm5,0x10(%rdi,%rax,8)
movupd 0x20(%rsi,%rax,8),%xmm2
movupd 0x30(%rsi,%rax,8),%xmm3
movupd 0x20(%rdx,%rax,8),%xmm4
movupd 0x30(%rdx,%rax,8),%xmm5
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,0x20(%rdi,%rax,8)
movupd %xmm5,0x30(%rdi,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%r10
jne    11f0 <vec_scaledy_add+0xf0>
test   $0x1,%r9b
je     1296 <vec_scaledy_add+0x196>
movupd (%rsi,%rax,8),%xmm2
movupd 0x10(%rsi,%rax,8),%xmm3
movupd (%rdx,%rax,8),%xmm4
movupd 0x10(%rdx,%rax,8),%xmm5
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,(%rdi,%rax,8)
movupd %xmm5,0x10(%rdi,%rax,8)
cmp    %r8,%rcx
jne    1112 <vec_scaledy_add+0x12>
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    1265 <vec_scaledy_add+0x165>
jmp    1296 <vec_scaledy_add+0x196>

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

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