void wavg(double z[], double x[], double y[], double w, int n) {
  int i;
  for (i = 0; i < n; i++)
    z[i] = w * x[i] + (1 - w) * y[i];
}


x86 assembly (clang, -O0):
<wavg>:
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    117a <wavg+0x7a>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  0xebb(%rip),%xmm1
subsd  -0x20(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
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 <wavg+0x1f>
pop    %rbp
ret

x86 assembly (clang, -O2):
<wavg>:
test   %ecx,%ecx
jle    12e7 <wavg+0x1e7>
movsd  0xef0(%rip),%xmm1
subsd  %xmm0,%xmm1
mov    %ecx,%r8d
cmp    $0x4,%ecx
jae    11a7 <wavg+0xa7>
xor    %ecx,%ecx
mov    %rcx,%rax
not    %rax
test   $0x1,%r8b
je     114d <wavg+0x4d>
movsd  (%rdx,%rcx,8),%xmm2
mulsd  %xmm1,%xmm2
movsd  (%rsi,%rcx,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,(%rdi,%rcx,8)
or     $0x1,%rcx
add    %r8,%rax
je     12e7 <wavg+0x1e7>
cs nopw 0x0(%rax,%rax,1)
movsd  (%rdx,%rcx,8),%xmm2
mulsd  %xmm1,%xmm2
movsd  (%rsi,%rcx,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,(%rdi,%rcx,8)
movsd  0x8(%rdx,%rcx,8),%xmm2
mulsd  %xmm1,%xmm2
movsd  0x8(%rsi,%rcx,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rdi,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%r8
jne    1160 <wavg+0x60>
jmp    12e7 <wavg+0x1e7>
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    1122 <wavg+0x22>
and    %r9b,%al
jne    1122 <wavg+0x22>
mov    %r8d,%ecx
and    $0xfffffffc,%ecx
movapd %xmm1,%xmm3
unpcklpd %xmm1,%xmm3
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
lea    -0x4(%rcx),%rax
mov    %rax,%r9
shr    $0x2,%r9
add    $0x1,%r9
test   %rax,%rax
je     12e8 <wavg+0x1e8>
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %eax,%eax
nopl   0x0(%rax)
movupd (%rsi,%rax,8),%xmm4
movupd 0x10(%rsi,%rax,8),%xmm5
movupd (%rdx,%rax,8),%xmm6
movupd 0x10(%rdx,%rax,8),%xmm7
mulpd  %xmm3,%xmm6
mulpd  %xmm3,%xmm7
mulpd  %xmm2,%xmm4
addpd  %xmm6,%xmm4
mulpd  %xmm2,%xmm5
addpd  %xmm7,%xmm5
movupd %xmm4,(%rdi,%rax,8)
movupd %xmm5,0x10(%rdi,%rax,8)
movupd 0x20(%rsi,%rax,8),%xmm4
movupd 0x30(%rsi,%rax,8),%xmm5
movupd 0x20(%rdx,%rax,8),%xmm6
movupd 0x30(%rdx,%rax,8),%xmm7
mulpd  %xmm3,%xmm6
mulpd  %xmm3,%xmm7
mulpd  %xmm2,%xmm4
addpd  %xmm6,%xmm4
mulpd  %xmm2,%xmm5
addpd  %xmm7,%xmm5
movupd %xmm4,0x20(%rdi,%rax,8)
movupd %xmm5,0x30(%rdi,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%r10
jne    1220 <wavg+0x120>
test   $0x1,%r9b
je     12de <wavg+0x1de>
movupd (%rsi,%rax,8),%xmm4
movupd 0x10(%rsi,%rax,8),%xmm5
movupd (%rdx,%rax,8),%xmm6
movupd 0x10(%rdx,%rax,8),%xmm7
mulpd  %xmm3,%xmm6
mulpd  %xmm3,%xmm7
mulpd  %xmm2,%xmm4
addpd  %xmm6,%xmm4
mulpd  %xmm2,%xmm5
addpd  %xmm7,%xmm5
movupd %xmm4,(%rdi,%rax,8)
movupd %xmm5,0x10(%rdi,%rax,8)
cmp    %r8,%rcx
jne    1122 <wavg+0x22>
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    12a5 <wavg+0x1a5>
jmp    12de <wavg+0x1de>

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

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