void doubles_scalar_add(double *farr1, double *farr2, int size, double alpha,
                        double *res_farr) {
  int i;
  for (i = 0; i < size; i++)
    res_farr[i] = farr1[i] + alpha * farr2[i];
}


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

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

LLVM IR (-O0):
define void @doubles_scalar_add(double* %0, double* %1, i32 %2, double %3, double* %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double*
%11 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store i32 %2, i32* %8
store double %3, double* %9
store double* %4, double** %10
store i32 0, i32* %11
br label %12
12: ; preds = %33, %5
%13 = load i32, i32* %11
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = load double*, double** %6
%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* %9
%23 = load double*, double** %7
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = call double @llvm.fmuladd.f64(double %22, double %27, double %21)
%29 = load double*, double** %10
%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 @doubles_scalar_add(double* nocapture %0, double* nocapture %1, i32 %2, double %3, double* nocapture writeonly %4) {
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %135
7: ; preds = %5
%8 = zext i32 %2 to i64
%9 = icmp ult i32 %2, 4
br i1 %9, label %101, label %10
10: ; preds = %7
%11 = getelementptr double, double* %4, i64 %8
%12 = getelementptr double, double* %0, i64 %8
%13 = getelementptr double, double* %1, i64 %8
%14 = icmp ugt double* %12, %4
%15 = icmp ugt double* %11, %0
%16 = and i1 %14, %15
%17 = icmp ugt double* %13, %4
%18 = icmp ugt double* %11, %1
%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* %0, 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* %1, 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> %24, <2 x double> %45, <2 x double> %39)
%50 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %48, <2 x double> %42)
%51 = getelementptr inbounds double, double* %4, 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* %0, 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* %1, 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> %24, <2 x double> %64, <2 x double> %58)
%69 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %67, <2 x double> %61)
%70 = getelementptr inbounds double, double* %4, 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* %0, 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* %1, 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> %24, <2 x double> %89, <2 x double> %83)
%94 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %92, <2 x double> %86)
%95 = getelementptr inbounds double, double* %4, 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* %0, i64 %102
%108 = load double, double* %107
%109 = getelementptr inbounds double, double* %1, i64 %102
%110 = load double, double* %109
%111 = tail call double @llvm.fmuladd.f64(double %3, double %110, double %108)
%112 = getelementptr inbounds double, double* %4, 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* %0, i64 %119
%121 = load double, double* %120
%122 = getelementptr inbounds double, double* %1, i64 %119
%123 = load double, double* %122
%124 = tail call double @llvm.fmuladd.f64(double %3, double %123, double %121)
%125 = getelementptr inbounds double, double* %4, i64 %119
store double %124, double* %125
%126 = add nuw nsw i64 %119, 1
%127 = getelementptr inbounds double, double* %0, i64 %126
%128 = load double, double* %127
%129 = getelementptr inbounds double, double* %1, i64 %126
%130 = load double, double* %129
%131 = tail call double @llvm.fmuladd.f64(double %3, double %130, double %128)
%132 = getelementptr inbounds double, double* %4, 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
}