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


x86 assembly (clang, -O0):
<glmMultQuaterniond>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x8(%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  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%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  0x18(%rax),%xmm0
mov    -0x18(%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    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x18(%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,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%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    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm1
mov    -0x18(%rbp),%rax
mulsd  (%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,0x18(%rax)
pop    %rbp
ret

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

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