void axpy(double *dest, double alpha, double *x, double *y, int n) {
  int i = 0;
  for (i = 0; i < n; i++) {
    dest[i] = alpha * x[i] + y[i];
  }
}


x86 assembly (clang, -O0):
<axpy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1174 <axpy+0x74>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%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    1126 <axpy+0x26>
pop    %rbp
ret

x86 assembly (clang, -O2):
<axpy>:
test   %ecx,%ecx
jle    129f <axpy+0x19f>
mov    %ecx,%r8d
cmp    $0x4,%ecx
jae    1177 <axpy+0x77>
xor    %ecx,%ecx
mov    %rcx,%rax
not    %rax
test   $0x1,%r8b
je     1135 <axpy+0x35>
movsd  (%rsi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rdx,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
or     $0x1,%rcx
add    %r8,%rax
je     129f <axpy+0x19f>
xchg   %ax,%ax
movsd  (%rsi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rdx,%rcx,8),%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
movsd  0x8(%rsi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rdx,%rcx,8),%xmm1
movsd  %xmm1,0x8(%rdi,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%r8
jne    1140 <axpy+0x40>
jmp    129f <axpy+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 <axpy+0x12>
and    %r9b,%al
jne    1112 <axpy+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 <axpy+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,%xmm2
addpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm5,%xmm3
movupd %xmm2,(%rdi,%rax,8)
movupd %xmm3,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,%xmm2
addpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm5,%xmm3
movupd %xmm2,0x20(%rdi,%rax,8)
movupd %xmm3,0x30(%rdi,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%r10
jne    11f0 <axpy+0xf0>
test   $0x1,%r9b
je     1296 <axpy+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,%xmm2
addpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm5,%xmm3
movupd %xmm2,(%rdi,%rax,8)
movupd %xmm3,0x10(%rdi,%rax,8)
cmp    %r8,%rcx
jne    1112 <axpy+0x12>
ret
xor    %eax,%eax
test   $0x1,%r9b
jne    1265 <axpy+0x165>
jmp    1296 <axpy+0x196>

LLVM IR (-O0):
define void @axpy(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
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 double*, double** %8
%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 = 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 %17, double %22, double %27)
%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 @axpy(double* nocapture writeonly %0, double %1, double* nocapture %2, double* nocapture %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* %2, i64 %8
%13 = getelementptr double, double* %3, i64 %8
%14 = icmp ugt double* %12, %0
%15 = icmp ugt double* %11, %2
%16 = and i1 %14, %15
%17 = icmp ugt double* %13, %0
%18 = icmp ugt double* %11, %3
%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 %1, i64 0
%24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
%25 = insertelement <2 x double> poison, double %1, 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* %2, 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* %3, 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> %39, <2 x double> %45)
%50 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %42, <2 x double> %48)
%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* %2, 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* %3, 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> %58, <2 x double> %64)
%69 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %61, <2 x double> %67)
%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* %2, 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* %3, 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> %83, <2 x double> %89)
%94 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %86, <2 x double> %92)
%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* %2, i64 %102
%108 = load double, double* %107
%109 = getelementptr inbounds double, double* %3, i64 %102
%110 = load double, double* %109
%111 = tail call double @llvm.fmuladd.f64(double %1, double %108, double %110)
%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* %2, i64 %119
%121 = load double, double* %120
%122 = getelementptr inbounds double, double* %3, i64 %119
%123 = load double, double* %122
%124 = tail call double @llvm.fmuladd.f64(double %1, double %121, double %123)
%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* %2, i64 %126
%128 = load double, double* %127
%129 = getelementptr inbounds double, double* %3, i64 %126
%130 = load double, double* %129
%131 = tail call double @llvm.fmuladd.f64(double %1, double %128, double %130)
%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
}