void mulqq(double *res, const double *q1, const double *q2) {
  res[0] = q1[3] * q2[0] + q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1];
  res[1] = q1[3] * q2[1] - q1[0] * q2[2] + q1[1] * q2[3] + q1[2] * q2[0];
  res[2] = q1[3] * q2[2] + q1[0] * q2[1] - q1[1] * q2[0] + q1[2] * q2[3];
  res[3] = q1[3] * q2[3] - q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2];
}


x86 assembly (clang, -O0):
<mulqq>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x18(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x10(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<mulqq>:
movsd  0x18(%rsi),%xmm0
movsd  (%rsi),%xmm1
mulsd  0x18(%rdx),%xmm1
movsd  0x8(%rsi),%xmm2
mulsd  (%rdx),%xmm0
addsd  %xmm1,%xmm0
mulsd  0x10(%rdx),%xmm2
addsd  %xmm0,%xmm2
movsd  0x10(%rsi),%xmm0
mulsd  0x8(%rdx),%xmm0
subsd  %xmm0,%xmm2
movsd  %xmm2,(%rdi)
movsd  0x18(%rsi),%xmm0
movsd  0x10(%rdx),%xmm1
mulsd  (%rsi),%xmm1
mulsd  0x8(%rdx),%xmm0
subsd  %xmm1,%xmm0
movsd  0x8(%rsi),%xmm1
movsd  0x10(%rsi),%xmm2
mulsd  0x18(%rdx),%xmm1
addsd  %xmm0,%xmm1
mulsd  (%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rdi)
movsd  0x18(%rsi),%xmm0
movsd  (%rsi),%xmm1
mulsd  0x8(%rdx),%xmm1
movsd  0x8(%rsi),%xmm2
mulsd  0x10(%rdx),%xmm0
addsd  %xmm1,%xmm0
mulsd  (%rdx),%xmm2
subsd  %xmm2,%xmm0
movsd  0x10(%rsi),%xmm1
mulsd  0x18(%rdx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rdi)
movsd  0x18(%rsi),%xmm0
movsd  (%rdx),%xmm1
mulsd  (%rsi),%xmm1
mulsd  0x18(%rdx),%xmm0
subsd  %xmm1,%xmm0
movsd  0x8(%rsi),%xmm1
movsd  0x10(%rsi),%xmm2
mulsd  0x8(%rdx),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x10(%rdx),%xmm2
subsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rdi)
ret

LLVM IR (-O0):
define void @mulqq(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%7 = load double*, double** %5
%8 = getelementptr inbounds double, double* %7, i64 3
%9 = load double, double* %8
%10 = load double*, double** %6
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = load double*, double** %5
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = load double*, double** %6
%17 = getelementptr inbounds double, double* %16, i64 3
%18 = load double, double* %17
%19 = fmul double %15, %18
%20 = call double @llvm.fmuladd.f64(double %9, double %12, double %19)
%21 = load double*, double** %5
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load double, double* %22
%24 = load double*, double** %6
%25 = getelementptr inbounds double, double* %24, i64 2
%26 = load double, double* %25
%27 = call double @llvm.fmuladd.f64(double %23, double %26, double %20)
%28 = load double*, double** %5
%29 = getelementptr inbounds double, double* %28, i64 2
%30 = load double, double* %29
%31 = load double*, double** %6
%32 = getelementptr inbounds double, double* %31, i64 1
%33 = load double, double* %32
%34 = fneg double %30
%35 = call double @llvm.fmuladd.f64(double %34, double %33, double %27)
%36 = load double*, double** %4
%37 = getelementptr inbounds double, double* %36, i64 0
store double %35, double* %37
%38 = load double*, double** %5
%39 = getelementptr inbounds double, double* %38, i64 3
%40 = load double, double* %39
%41 = load double*, double** %6
%42 = getelementptr inbounds double, double* %41, i64 1
%43 = load double, double* %42
%44 = load double*, double** %5
%45 = getelementptr inbounds double, double* %44, i64 0
%46 = load double, double* %45
%47 = load double*, double** %6
%48 = getelementptr inbounds double, double* %47, i64 2
%49 = load double, double* %48
%50 = fmul double %46, %49
%51 = fneg double %50
%52 = call double @llvm.fmuladd.f64(double %40, double %43, double %51)
%53 = load double*, double** %5
%54 = getelementptr inbounds double, double* %53, i64 1
%55 = load double, double* %54
%56 = load double*, double** %6
%57 = getelementptr inbounds double, double* %56, i64 3
%58 = load double, double* %57
%59 = call double @llvm.fmuladd.f64(double %55, double %58, double %52)
%60 = load double*, double** %5
%61 = getelementptr inbounds double, double* %60, i64 2
%62 = load double, double* %61
%63 = load double*, double** %6
%64 = getelementptr inbounds double, double* %63, i64 0
%65 = load double, double* %64
%66 = call double @llvm.fmuladd.f64(double %62, double %65, double %59)
%67 = load double*, double** %4
%68 = getelementptr inbounds double, double* %67, i64 1
store double %66, double* %68
%69 = load double*, double** %5
%70 = getelementptr inbounds double, double* %69, i64 3
%71 = load double, double* %70
%72 = load double*, double** %6
%73 = getelementptr inbounds double, double* %72, i64 2
%74 = load double, double* %73
%75 = load double*, double** %5
%76 = getelementptr inbounds double, double* %75, i64 0
%77 = load double, double* %76
%78 = load double*, double** %6
%79 = getelementptr inbounds double, double* %78, i64 1
%80 = load double, double* %79
%81 = fmul double %77, %80
%82 = call double @llvm.fmuladd.f64(double %71, double %74, double %81)
%83 = load double*, double** %5
%84 = getelementptr inbounds double, double* %83, i64 1
%85 = load double, double* %84
%86 = load double*, double** %6
%87 = getelementptr inbounds double, double* %86, i64 0
%88 = load double, double* %87
%89 = fneg double %85
%90 = call double @llvm.fmuladd.f64(double %89, double %88, double %82)
%91 = load double*, double** %5
%92 = getelementptr inbounds double, double* %91, i64 2
%93 = load double, double* %92
%94 = load double*, double** %6
%95 = getelementptr inbounds double, double* %94, i64 3
%96 = load double, double* %95
%97 = call double @llvm.fmuladd.f64(double %93, double %96, double %90)
%98 = load double*, double** %4
%99 = getelementptr inbounds double, double* %98, i64 2
store double %97, double* %99
%100 = load double*, double** %5
%101 = getelementptr inbounds double, double* %100, i64 3
%102 = load double, double* %101
%103 = load double*, double** %6
%104 = getelementptr inbounds double, double* %103, i64 3
%105 = load double, double* %104
%106 = load double*, double** %5
%107 = getelementptr inbounds double, double* %106, i64 0
%108 = load double, double* %107
%109 = load double*, double** %6
%110 = getelementptr inbounds double, double* %109, i64 0
%111 = load double, double* %110
%112 = fmul double %108, %111
%113 = fneg double %112
%114 = call double @llvm.fmuladd.f64(double %102, double %105, double %113)
%115 = load double*, double** %5
%116 = getelementptr inbounds double, double* %115, i64 1
%117 = load double, double* %116
%118 = load double*, double** %6
%119 = getelementptr inbounds double, double* %118, i64 1
%120 = load double, double* %119
%121 = fneg double %117
%122 = call double @llvm.fmuladd.f64(double %121, double %120, double %114)
%123 = load double*, double** %5
%124 = getelementptr inbounds double, double* %123, i64 2
%125 = load double, double* %124
%126 = load double*, double** %6
%127 = getelementptr inbounds double, double* %126, i64 2
%128 = load double, double* %127
%129 = fneg double %125
%130 = call double @llvm.fmuladd.f64(double %129, double %128, double %122)
%131 = load double*, double** %4
%132 = getelementptr inbounds double, double* %131, i64 3
store double %130, double* %132
ret void
}

LLVM IR (-O2):
define void @mulqq(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2) {
%4 = getelementptr inbounds double, double* %1, i64 3
%5 = load double, double* %4
%6 = load double, double* %2
%7 = load double, double* %1
%8 = getelementptr inbounds double, double* %2, i64 3
%9 = load double, double* %8
%10 = fmul double %7, %9
%11 = tail call double @llvm.fmuladd.f64(double %5, double %6, double %10)
%12 = getelementptr inbounds double, double* %1, i64 1
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %2, i64 2
%15 = load double, double* %14
%16 = tail call double @llvm.fmuladd.f64(double %13, double %15, double %11)
%17 = getelementptr inbounds double, double* %1, i64 2
%18 = load double, double* %17
%19 = getelementptr inbounds double, double* %2, i64 1
%20 = load double, double* %19
%21 = fneg double %18
%22 = tail call double @llvm.fmuladd.f64(double %21, double %20, double %16)
store double %22, double* %0
%23 = load double, double* %4
%24 = load double, double* %19
%25 = load double, double* %1
%26 = load double, double* %14
%27 = fneg double %25
%28 = fmul double %26, %27
%29 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %28)
%30 = load double, double* %12
%31 = load double, double* %8
%32 = tail call double @llvm.fmuladd.f64(double %30, double %31, double %29)
%33 = load double, double* %17
%34 = load double, double* %2
%35 = tail call double @llvm.fmuladd.f64(double %33, double %34, double %32)
%36 = getelementptr inbounds double, double* %0, i64 1
store double %35, double* %36
%37 = load double, double* %4
%38 = load double, double* %14
%39 = load double, double* %1
%40 = load double, double* %19
%41 = fmul double %39, %40
%42 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %41)
%43 = load double, double* %12
%44 = load double, double* %2
%45 = fneg double %43
%46 = tail call double @llvm.fmuladd.f64(double %45, double %44, double %42)
%47 = load double, double* %17
%48 = load double, double* %8
%49 = tail call double @llvm.fmuladd.f64(double %47, double %48, double %46)
%50 = getelementptr inbounds double, double* %0, i64 2
store double %49, double* %50
%51 = load double, double* %4
%52 = load double, double* %8
%53 = load double, double* %1
%54 = load double, double* %2
%55 = fneg double %53
%56 = fmul double %54, %55
%57 = tail call double @llvm.fmuladd.f64(double %51, double %52, double %56)
%58 = load double, double* %12
%59 = load double, double* %19
%60 = fneg double %58
%61 = tail call double @llvm.fmuladd.f64(double %60, double %59, double %57)
%62 = load double, double* %17
%63 = load double, double* %14
%64 = fneg double %62
%65 = tail call double @llvm.fmuladd.f64(double %64, double %63, double %61)
%66 = getelementptr inbounds double, double* %0, i64 3
store double %65, double* %66
ret void
}