void glmRotateVectorByNormalizedQuaterniond(double result[3], const double v[3],
                                            const double q[4]) {
  double temp1 = v[2] * q[0] + v[1] * q[1] - v[0] * q[2];
  double temp2 = v[1] * q[0] - v[2] * q[1] + v[0] * q[3];
  double temp3 = v[0] * q[0] + v[2] * q[2] - v[1] * q[3];
  double temp4 = -v[0] * q[1] - v[1] * q[2] - v[2] * q[3];
  result[0] = q[2] * temp1 - q[3] * temp2 + q[0] * temp3 - q[1] * temp4;
  result[1] = -q[1] * temp1 + q[0] * temp2 + q[3] * temp3 - q[2] * temp4;
  result[2] = q[0] * temp1 + q[1] * temp2 - q[2] * temp3 - q[3] * temp4;
}


x86 assembly (clang, -O0):
<glmRotateVectorByNormalizedQuaterniond>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  (%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
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x10(%rax),%xmm0
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
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x10(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%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
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  -0x20(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm1
mulsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  -0x38(%rbp),%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    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x20(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm1
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  -0x38(%rbp),%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    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x20(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm1
movsd  -0x30(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  -0x38(%rbp),%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)
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmRotateVectorByNormalizedQuaterniond>:
movsd  0x10(%rsi),%xmm9
movsd  (%rsi),%xmm0
movsd  0x8(%rsi),%xmm10
movsd  (%rdx),%xmm4
movsd  0x8(%rdx),%xmm8
movapd %xmm10,%xmm2
mulsd  %xmm8,%xmm2
movapd %xmm9,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm2,%xmm1
movsd  0x10(%rdx),%xmm7
movapd 0xec2(%rip),%xmm2
xorpd  %xmm0,%xmm2
movapd %xmm0,%xmm3
mulsd  %xmm7,%xmm3
subsd  %xmm3,%xmm1
movapd %xmm8,%xmm3
mulsd  %xmm9,%xmm3
movapd %xmm10,%xmm5
mulsd  %xmm4,%xmm5
subsd  %xmm3,%xmm5
movsd  0x18(%rdx),%xmm6
movapd %xmm0,%xmm3
mulsd  %xmm6,%xmm3
addsd  %xmm5,%xmm3
movapd %xmm9,%xmm5
mulsd  %xmm7,%xmm5
mulsd  %xmm4,%xmm0
addsd  %xmm5,%xmm0
movapd %xmm7,%xmm5
mulsd  %xmm10,%xmm5
mulsd  %xmm6,%xmm10
subsd  %xmm10,%xmm0
mulsd  %xmm8,%xmm2
subsd  %xmm5,%xmm2
mulsd  %xmm6,%xmm9
subsd  %xmm9,%xmm2
mulsd  %xmm3,%xmm6
mulsd  %xmm1,%xmm7
subsd  %xmm6,%xmm7
mulsd  %xmm0,%xmm4
addsd  %xmm7,%xmm4
mulsd  %xmm2,%xmm8
subsd  %xmm8,%xmm4
movsd  %xmm4,(%rdi)
movsd  (%rdx),%xmm4
mulsd  %xmm3,%xmm4
movsd  0x8(%rdx),%xmm5
mulsd  %xmm1,%xmm5
subsd  %xmm5,%xmm4
movsd  0x18(%rdx),%xmm5
mulsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
movsd  0x10(%rdx),%xmm4
mulsd  %xmm2,%xmm4
subsd  %xmm4,%xmm5
movsd  %xmm5,0x8(%rdi)
mulsd  0x8(%rdx),%xmm3
mulsd  (%rdx),%xmm1
addsd  %xmm3,%xmm1
mulsd  0x10(%rdx),%xmm0
subsd  %xmm0,%xmm1
mulsd  0x18(%rdx),%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rdi)
ret

LLVM IR (-O0):
define void @glmRotateVectorByNormalizedQuaterniond(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 2
%13 = load double, double* %12
%14 = load double*, double** %6
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double*, double** %5
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = load double*, double** %6
%21 = getelementptr inbounds double, double* %20, i64 1
%22 = load double, double* %21
%23 = fmul double %19, %22
%24 = call double @llvm.fmuladd.f64(double %13, double %16, double %23)
%25 = load double*, double** %5
%26 = getelementptr inbounds double, double* %25, i64 0
%27 = load double, double* %26
%28 = load double*, double** %6
%29 = getelementptr inbounds double, double* %28, i64 2
%30 = load double, double* %29
%31 = fneg double %27
%32 = call double @llvm.fmuladd.f64(double %31, double %30, double %24)
store double %32, double* %7
%33 = load double*, double** %5
%34 = getelementptr inbounds double, double* %33, i64 1
%35 = load double, double* %34
%36 = load double*, double** %6
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
%39 = load double*, double** %5
%40 = getelementptr inbounds double, double* %39, i64 2
%41 = load double, double* %40
%42 = load double*, double** %6
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = fmul double %41, %44
%46 = fneg double %45
%47 = call double @llvm.fmuladd.f64(double %35, double %38, double %46)
%48 = load double*, double** %5
%49 = getelementptr inbounds double, double* %48, i64 0
%50 = load double, double* %49
%51 = load double*, double** %6
%52 = getelementptr inbounds double, double* %51, i64 3
%53 = load double, double* %52
%54 = call double @llvm.fmuladd.f64(double %50, double %53, double %47)
store double %54, double* %8
%55 = load double*, double** %5
%56 = getelementptr inbounds double, double* %55, i64 0
%57 = load double, double* %56
%58 = load double*, double** %6
%59 = getelementptr inbounds double, double* %58, i64 0
%60 = load double, double* %59
%61 = load double*, double** %5
%62 = getelementptr inbounds double, double* %61, i64 2
%63 = load double, double* %62
%64 = load double*, double** %6
%65 = getelementptr inbounds double, double* %64, i64 2
%66 = load double, double* %65
%67 = fmul double %63, %66
%68 = call double @llvm.fmuladd.f64(double %57, double %60, double %67)
%69 = load double*, double** %5
%70 = getelementptr inbounds double, double* %69, i64 1
%71 = load double, double* %70
%72 = load double*, double** %6
%73 = getelementptr inbounds double, double* %72, i64 3
%74 = load double, double* %73
%75 = fneg double %71
%76 = call double @llvm.fmuladd.f64(double %75, double %74, double %68)
store double %76, double* %9
%77 = load double*, double** %5
%78 = getelementptr inbounds double, double* %77, i64 0
%79 = load double, double* %78
%80 = fneg double %79
%81 = load double*, double** %6
%82 = getelementptr inbounds double, double* %81, i64 1
%83 = load double, double* %82
%84 = load double*, double** %5
%85 = getelementptr inbounds double, double* %84, i64 1
%86 = load double, double* %85
%87 = load double*, double** %6
%88 = getelementptr inbounds double, double* %87, i64 2
%89 = load double, double* %88
%90 = fmul double %86, %89
%91 = fneg double %90
%92 = call double @llvm.fmuladd.f64(double %80, double %83, double %91)
%93 = load double*, double** %5
%94 = getelementptr inbounds double, double* %93, i64 2
%95 = load double, double* %94
%96 = load double*, double** %6
%97 = getelementptr inbounds double, double* %96, i64 3
%98 = load double, double* %97
%99 = fneg double %95
%100 = call double @llvm.fmuladd.f64(double %99, double %98, double %92)
store double %100, double* %10
%101 = load double*, double** %6
%102 = getelementptr inbounds double, double* %101, i64 2
%103 = load double, double* %102
%104 = load double, double* %7
%105 = load double*, double** %6
%106 = getelementptr inbounds double, double* %105, i64 3
%107 = load double, double* %106
%108 = load double, double* %8
%109 = fmul double %107, %108
%110 = fneg double %109
%111 = call double @llvm.fmuladd.f64(double %103, double %104, double %110)
%112 = load double*, double** %6
%113 = getelementptr inbounds double, double* %112, i64 0
%114 = load double, double* %113
%115 = load double, double* %9
%116 = call double @llvm.fmuladd.f64(double %114, double %115, double %111)
%117 = load double*, double** %6
%118 = getelementptr inbounds double, double* %117, i64 1
%119 = load double, double* %118
%120 = load double, double* %10
%121 = fneg double %119
%122 = call double @llvm.fmuladd.f64(double %121, double %120, double %116)
%123 = load double*, double** %4
%124 = getelementptr inbounds double, double* %123, i64 0
store double %122, double* %124
%125 = load double*, double** %6
%126 = getelementptr inbounds double, double* %125, i64 1
%127 = load double, double* %126
%128 = fneg double %127
%129 = load double, double* %7
%130 = load double*, double** %6
%131 = getelementptr inbounds double, double* %130, i64 0
%132 = load double, double* %131
%133 = load double, double* %8
%134 = fmul double %132, %133
%135 = call double @llvm.fmuladd.f64(double %128, double %129, double %134)
%136 = load double*, double** %6
%137 = getelementptr inbounds double, double* %136, i64 3
%138 = load double, double* %137
%139 = load double, double* %9
%140 = call double @llvm.fmuladd.f64(double %138, double %139, double %135)
%141 = load double*, double** %6
%142 = getelementptr inbounds double, double* %141, i64 2
%143 = load double, double* %142
%144 = load double, double* %10
%145 = fneg double %143
%146 = call double @llvm.fmuladd.f64(double %145, double %144, double %140)
%147 = load double*, double** %4
%148 = getelementptr inbounds double, double* %147, i64 1
store double %146, double* %148
%149 = load double*, double** %6
%150 = getelementptr inbounds double, double* %149, i64 0
%151 = load double, double* %150
%152 = load double, double* %7
%153 = load double*, double** %6
%154 = getelementptr inbounds double, double* %153, i64 1
%155 = load double, double* %154
%156 = load double, double* %8
%157 = fmul double %155, %156
%158 = call double @llvm.fmuladd.f64(double %151, double %152, double %157)
%159 = load double*, double** %6
%160 = getelementptr inbounds double, double* %159, i64 2
%161 = load double, double* %160
%162 = load double, double* %9
%163 = fneg double %161
%164 = call double @llvm.fmuladd.f64(double %163, double %162, double %158)
%165 = load double*, double** %6
%166 = getelementptr inbounds double, double* %165, i64 3
%167 = load double, double* %166
%168 = load double, double* %10
%169 = fneg double %167
%170 = call double @llvm.fmuladd.f64(double %169, double %168, double %164)
%171 = load double*, double** %4
%172 = getelementptr inbounds double, double* %171, i64 2
store double %170, double* %172
ret void
}

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