void elem_daxmy(double a, double *x, double *y, int n) {
  for (n--; n >= 0; n--)
    y[n] -= a * x[n];
}


x86 assembly (clang, -O0):
<elem_daxmy>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1178 <elem_daxmy+0x78>
movsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movq   %xmm0,%rdx
movabs $0x8000000000000000,%rsi
xor    %rsi,%rdx
movq   %rdx,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    111d <elem_daxmy+0x1d>
pop    %rbp
ret

x86 assembly (clang, -O2):
<elem_daxmy>:
test   %edx,%edx
jle    1180 <elem_daxmy+0x80>
xorpd  0xef4(%rip),%xmm0
mov    %edx,%r8d
cmp    $0x4,%edx
jb     1159 <elem_daxmy+0x59>
lea    -0x1(%r8),%r11
add    $0xffffffff,%edx
cmp    %r11d,%edx
jb     1159 <elem_daxmy+0x59>
mov    %r11,%rcx
shr    $0x20,%rcx
jne    1159 <elem_daxmy+0x59>
mov    %r8,%rcx
neg    %rcx
lea    (%rdx,%rcx,1),%r10
add    $0x1,%r10
lea    (%rsi,%r10,8),%r9
lea    (%rdi,%rdx,8),%rcx
add    $0x8,%rcx
cmp    %rcx,%r9
jae    1181 <elem_daxmy+0x81>
lea    (%rsi,%rdx,8),%rcx
add    $0x8,%rcx
lea    (%rdi,%r10,8),%rdx
cmp    %rcx,%rdx
jae    1181 <elem_daxmy+0x81>
mov    %r8,%rcx
add    $0x1,%rcx
lea    -0x2(%rcx),%eax
movsd  (%rdi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rsi,%rax,8),%xmm1
movsd  %xmm1,(%rsi,%rax,8)
add    $0xffffffffffffffff,%rcx
cmp    $0x1,%rcx
ja     1160 <elem_daxmy+0x60>
ret
mov    %r8d,%r9d
and    $0xfffffffc,%r9d
mov    %r8d,%ecx
and    $0x3,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
shufpd $0x1,%xmm1,%xmm1
mov    %r9,%rdx
xchg   %ax,%ax
mov    %r11d,%eax
shl    $0x3,%rax
movupd -0x18(%rdi,%rax,1),%xmm2
movupd -0x8(%rdi,%rax,1),%xmm3
movupd -0x18(%rsi,%rax,1),%xmm4
movupd -0x8(%rsi,%rax,1),%xmm5
mulpd  %xmm1,%xmm3
addpd  %xmm5,%xmm3
movupd %xmm3,-0x8(%rsi,%rax,1)
mulpd  %xmm1,%xmm2
addpd  %xmm4,%xmm2
movupd %xmm2,-0x18(%rsi,%rax,1)
add    $0xfffffffffffffffc,%r11
add    $0xfffffffffffffffc,%rdx
jne    11a0 <elem_daxmy+0xa0>
cmp    %r8,%r9
je     1180 <elem_daxmy+0x80>
jmp    115c <elem_daxmy+0x5c>

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

LLVM IR (-O2):
define void @elem_daxmy(double %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %84
6: ; preds = %4
%7 = fneg double %0
%8 = zext i32 %3 to i64
%9 = icmp ult i32 %3, 4
br i1 %9, label %72, label %10
10: ; preds = %6
%11 = add nsw i64 %8, -1
%12 = add i32 %3, -1
%13 = trunc i64 %11 to i32
%14 = icmp ult i32 %12, %13
%15 = icmp ugt i64 %11, 4294967295
%16 = or i1 %14, %15
br i1 %16, label %72, label %17
17: ; preds = %10
%18 = add i32 %3, -1
%19 = zext i32 %18 to i64
%20 = add nuw nsw i64 %19, 1
%21 = sub nsw i64 %20, %8
%22 = getelementptr double, double* %2, i64 %21
%23 = add nuw nsw i64 %19, 1
%24 = getelementptr double, double* %2, i64 %23
%25 = getelementptr double, double* %1, i64 %21
%26 = getelementptr double, double* %1, i64 %23
%27 = icmp ult double* %22, %26
%28 = icmp ult double* %25, %24
%29 = and i1 %27, %28
br i1 %29, label %72, label %30
30: ; preds = %17
%31 = and i64 %8, 4294967292
%32 = and i64 %8, 3
%33 = insertelement <2 x double> poison, double %7, i64 0
%34 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> zeroinitializer
%35 = insertelement <2 x double> poison, double %7, i64 0
%36 = shufflevector <2 x double> %35, <2 x double> poison, <2 x i32> zeroinitializer
br label %37
37: ; preds = %37, %30
%38 = phi i64 [ 0, %30 ], [ %68, %37 ]
%39 = xor i64 %38, -1
%40 = add i64 %39, %8
%41 = and i64 %40, 4294967295
%42 = getelementptr inbounds double, double* %1, i64 %41
%43 = getelementptr inbounds double, double* %42, i64 -1
%44 = bitcast double* %43 to <2 x double>*
%45 = load <2 x double>, <2 x double>* %44
%46 = shufflevector <2 x double> %45, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%47 = getelementptr inbounds double, double* %42, i64 -2
%48 = getelementptr inbounds double, double* %47, i64 -1
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = shufflevector <2 x double> %50, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%52 = getelementptr inbounds double, double* %2, i64 %41
%53 = getelementptr inbounds double, double* %52, i64 -1
%54 = bitcast double* %53 to <2 x double>*
%55 = load <2 x double>, <2 x double>* %54
%56 = shufflevector <2 x double> %55, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%57 = getelementptr inbounds double, double* %52, i64 -2
%58 = getelementptr inbounds double, double* %57, i64 -1
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = shufflevector <2 x double> %60, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%62 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %34, <2 x double> %46, <2 x double> %56)
%63 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %36, <2 x double> %51, <2 x double> %61)
%64 = shufflevector <2 x double> %62, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%65 = bitcast double* %53 to <2 x double>*
store <2 x double> %64, <2 x double>* %65
%66 = shufflevector <2 x double> %63, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%67 = bitcast double* %58 to <2 x double>*
store <2 x double> %66, <2 x double>* %67
%68 = add nuw i64 %38, 4
%69 = icmp eq i64 %68, %31
br i1 %69, label %70, label %37
70: ; preds = %37
%71 = icmp eq i64 %31, %8
br i1 %71, label %84, label %72
72: ; preds = %17, %10, %6, %70
%73 = phi i64 [ %8, %17 ], [ %8, %10 ], [ %8, %6 ], [ %32, %70 ]
br label %74
74: ; preds = %72, %74
%75 = phi i64 [ %76, %74 ], [ %73, %72 ]
%76 = add nsw i64 %75, -1
%77 = and i64 %76, 4294967295
%78 = getelementptr inbounds double, double* %1, i64 %77
%79 = load double, double* %78
%80 = getelementptr inbounds double, double* %2, i64 %77
%81 = load double, double* %80
%82 = tail call double @llvm.fmuladd.f64(double %7, double %79, double %81)
store double %82, double* %80
%83 = icmp ugt i64 %75, 1
br i1 %83, label %74, label %84
84: ; preds = %74, %70, %4
ret void
}