void doubles_quat_to_mat44(const double q[4], double r[16]) {
  double w = q[0], x = q[1], y = q[2], z = q[3];
  r[0] = w * w + x * x - y * y - z * z;
  r[1] = 2 * x * y - 2 * w * z;
  r[2] = 2 * x * z + 2 * w * y;
  r[3] = 0;
  r[4] = 2 * x * y + 2 * w * z;
  r[5] = w * w - x * x + y * y - z * z;
  r[6] = 2 * y * z - 2 * w * x;
  r[7] = 0;
  r[8] = 2 * x * z - 2 * w * y;
  r[9] = 2 * y * z + 2 * w * x;
  r[10] = w * w - x * x - y * y + z * z;
  r[11] = 0;
  r[12] = 0;
  r[13] = 0;
  r[14] = 0;
  r[15] = 1;
}


x86 assembly (clang, -O0):
<doubles_quat_to_mat44>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xe47(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xe35(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  0xdfb(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xde9(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x18(%rax)
movsd  0xdba(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xda8(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x20(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x28(%rax)
movsd  0xd0e(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xcfc(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x30(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x38(%rax)
movsd  0xcb6(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xca4(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x40(%rax)
movsd  0xc6a(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xc58(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x48(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x50(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x58(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x60(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x68(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x70(%rax)
mov    -0x10(%rbp),%rax
movsd  0xb82(%rip),%xmm0
movsd  %xmm0,0x78(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_quat_to_mat44>:
movsd  (%rdi),%xmm10
movsd  0x8(%rdi),%xmm4
movupd 0x10(%rdi),%xmm12
movapd %xmm10,%xmm9
addsd  %xmm10,%xmm10
movapd %xmm10,%xmm11
movapd %xmm4,%xmm3
movapd %xmm10,%xmm6
mulsd  %xmm4,%xmm10
mulsd  %xmm4,%xmm4
mulsd  %xmm9,%xmm9
movapd %xmm9,%xmm7
addsd  %xmm4,%xmm7
movapd 0xeb8(%rip),%xmm8
movapd %xmm12,%xmm2
xorpd  %xmm8,%xmm2
mulsd  %xmm12,%xmm2
addsd  %xmm2,%xmm7
movapd %xmm12,%xmm0
unpckhpd %xmm12,%xmm0
movapd %xmm0,%xmm5
xorpd  %xmm8,%xmm5
mulsd  %xmm0,%xmm11
movapd %xmm11,%xmm1
xorpd  %xmm8,%xmm1
unpcklpd %xmm1,%xmm7
unpcklpd %xmm12,%xmm3
addpd  %xmm3,%xmm3
movapd %xmm3,%xmm1
unpcklpd %xmm5,%xmm1
mulpd  %xmm12,%xmm1
mulsd  %xmm12,%xmm6
subsd  %xmm4,%xmm9
mulsd  %xmm12,%xmm12
addsd  %xmm9,%xmm12
unpcklpd %xmm12,%xmm11
addpd  %xmm1,%xmm11
shufpd $0x1,%xmm1,%xmm1
addpd  %xmm7,%xmm1
movupd %xmm1,(%rsi)
movapd %xmm3,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm6,%xmm1
movsd  %xmm1,0x10(%rsi)
movq   $0x0,0x18(%rsi)
movupd %xmm11,0x20(%rsi)
movapd %xmm3,%xmm1
unpckhpd %xmm3,%xmm1
mulsd  %xmm0,%xmm1
subsd  %xmm10,%xmm1
movsd  %xmm1,0x30(%rsi)
movq   $0x0,0x38(%rsi)
xorpd  %xmm8,%xmm6
unpcklpd %xmm10,%xmm6
mulpd  %xmm0,%xmm3
addpd  %xmm6,%xmm3
movupd %xmm3,0x40(%rsi)
addsd  %xmm2,%xmm9
mulsd  %xmm0,%xmm0
addsd  %xmm9,%xmm0
movsd  %xmm0,0x50(%rsi)
xorpd  %xmm0,%xmm0
movupd %xmm0,0x58(%rsi)
movupd %xmm0,0x68(%rsi)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x78(%rsi)
ret

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

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