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


x86 assembly (clang, -O0):
<vector_saxpy2>:
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_saxpy2+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    -0x10(%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_saxpy2+0x1b>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

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

LLVM IR (-O0):
define double* @vector_saxpy2(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** %6
%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** %6
ret double* %35
}

LLVM IR (-O2):
define double* @vector_saxpy2(i32 %0, double* returned %1, double* nocapture %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* %1, i64 %7
%11 = getelementptr double, double* %2, i64 %7
%12 = icmp ugt double* %11, %1
%13 = icmp ugt double* %10, %2
%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* %31 to <2 x double>*
store <2 x double> %43, <2 x double>* %45
%46 = bitcast double* %34 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* %48 to <2 x double>*
store <2 x double> %60, <2 x double>* %62
%63 = bitcast double* %51 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* %71 to <2 x double>*
store <2 x double> %83, <2 x double>* %85
%86 = bitcast double* %74 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* %95
%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* %107
%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* %113
%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* %1
}