double *vector_saxpy(int n, double *x, double *y, double beta) {
  int i;
  for (i = 0; i < n; i++)
    y[i] = x[i] + beta * y[i];
  return y;
}


x86 assembly (clang, -O0):
<vector_saxpy>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1169 <vector_saxpy+0x69>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111b <vector_saxpy+0x1b>
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_saxpy>:
mov    %rdx,%rax
test   %edi,%edi
jle    127f <vector_saxpy+0x17f>
mov    %edi,%r9d
cmp    $0x4,%edi
jb     1125 <vector_saxpy+0x25>
lea    (%rsi,%r9,8),%rcx
cmp    %rax,%rcx
jbe    1197 <vector_saxpy+0x97>
lea    (%rax,%r9,8),%rcx
cmp    %rsi,%rcx
jbe    1197 <vector_saxpy+0x97>
xor    %edx,%edx
mov    %rdx,%rcx
not    %rcx
test   $0x1,%r9b
je     114a <vector_saxpy+0x4a>
movsd  (%rax,%rdx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rsi,%rdx,8),%xmm1
movsd  %xmm1,(%rax,%rdx,8)
or     $0x1,%rdx
add    %r9,%rcx
je     127f <vector_saxpy+0x17f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rax,%rdx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rsi,%rdx,8),%xmm1
movsd  %xmm1,(%rax,%rdx,8)
movsd  0x8(%rax,%rdx,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rsi,%rdx,8),%xmm1
movsd  %xmm1,0x8(%rax,%rdx,8)
add    $0x2,%rdx
cmp    %rdx,%r9
jne    1160 <vector_saxpy+0x60>
jmp    127f <vector_saxpy+0x17f>
mov    %r9d,%edx
and    $0xfffffffc,%edx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rdx),%rcx
mov    %rcx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rcx,%rcx
je     1280 <vector_saxpy+0x180>
mov    %r8,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
movupd (%rsi,%rdi,8),%xmm2
movupd 0x10(%rsi,%rdi,8),%xmm3
movupd (%rax,%rdi,8),%xmm4
movupd 0x10(%rax,%rdi,8),%xmm5
movupd 0x20(%rax,%rdi,8),%xmm6
movupd 0x30(%rax,%rdi,8),%xmm7
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,(%rax,%rdi,8)
movupd %xmm5,0x10(%rax,%rdi,8)
movupd 0x20(%rsi,%rdi,8),%xmm2
movupd 0x30(%rsi,%rdi,8),%xmm3
mulpd  %xmm1,%xmm6
addpd  %xmm2,%xmm6
mulpd  %xmm1,%xmm7
addpd  %xmm3,%xmm7
movupd %xmm6,0x20(%rax,%rdi,8)
movupd %xmm7,0x30(%rax,%rdi,8)
add    $0x8,%rdi
add    $0xfffffffffffffffe,%rcx
jne    11d0 <vector_saxpy+0xd0>
test   $0x1,%r8b
je     1276 <vector_saxpy+0x176>
movupd (%rsi,%rdi,8),%xmm2
movupd 0x10(%rsi,%rdi,8),%xmm3
movupd (%rax,%rdi,8),%xmm4
movupd 0x10(%rax,%rdi,8),%xmm5
mulpd  %xmm1,%xmm4
addpd  %xmm2,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm3,%xmm5
movupd %xmm4,(%rax,%rdi,8)
movupd %xmm5,0x10(%rax,%rdi,8)
cmp    %r9,%rdx
jne    1127 <vector_saxpy+0x27>
ret
xor    %edi,%edi
test   $0x1,%r8b
jne    1245 <vector_saxpy+0x145>
jmp    1276 <vector_saxpy+0x176>

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

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