void qmult(double *p, double *q, double *r) {
  int i;
  for (i = 0; i < 3; i++)
    r[i] = 0.0;
  r[0] = p[0] * q[0] - (p[1] * q[1] + p[2] * q[2] + p[3] * q[3]);
  r[1] = p[0] * q[1] + q[0] * p[1] + p[2] * q[3] - p[3] * q[2];
  r[2] = p[0] * q[2] + q[0] * p[2] + p[3] * q[1] - p[1] * q[3];
  r[3] = p[0] * q[3] + q[0] * p[3] + p[1] * q[2] - p[2] * q[1];
}


x86 assembly (clang, -O0):
<qmult>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    113f <qmult+0x3f>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <qmult+0x17>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm3
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm4
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x10(%rax),%xmm1
mulsd  %xmm4,%xmm3
addsd  %xmm1,%xmm3
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm4
mulsd  %xmm4,%xmm1
addsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x10(%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    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x10(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x18(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%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    -0x18(%rbp),%rax
movsd  %xmm0,0x18(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<qmult>:
xorps  %xmm0,%xmm0
movups %xmm0,(%rdx)
movq   $0x0,0x10(%rdx)
movsd  (%rdi),%xmm0
movsd  0x10(%rdi),%xmm1
mulsd  0x10(%rsi),%xmm1
movsd  0x8(%rdi),%xmm2
mulsd  0x8(%rsi),%xmm2
addsd  %xmm1,%xmm2
movsd  0x18(%rdi),%xmm1
mulsd  0x18(%rsi),%xmm1
addsd  %xmm2,%xmm1
mulsd  (%rsi),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rdx)
movsd  (%rsi),%xmm0
mulsd  0x8(%rdi),%xmm0
movsd  (%rdi),%xmm1
movsd  0x10(%rdi),%xmm2
mulsd  0x8(%rsi),%xmm1
addsd  %xmm0,%xmm1
mulsd  0x18(%rsi),%xmm2
addsd  %xmm1,%xmm2
movsd  0x18(%rdi),%xmm0
mulsd  0x10(%rsi),%xmm0
subsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rdx)
movsd  (%rsi),%xmm0
mulsd  0x10(%rdi),%xmm0
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
mulsd  0x10(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  0x18(%rdi),%xmm0
mulsd  0x8(%rsi),%xmm0
addsd  %xmm1,%xmm0
mulsd  0x18(%rsi),%xmm2
subsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rdx)
movsd  (%rsi),%xmm0
mulsd  0x18(%rdi),%xmm0
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
mulsd  0x18(%rsi),%xmm1
addsd  %xmm0,%xmm1
mulsd  0x10(%rsi),%xmm2
addsd  %xmm1,%xmm2
movsd  0x10(%rdi),%xmm0
mulsd  0x8(%rsi),%xmm0
subsd  %xmm0,%xmm2
movsd  %xmm2,0x18(%rdx)
ret

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

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