int quat_to_R(double quat[4], double R[3][3]) {
  double q0 = quat[0];
  double q1 = quat[1];
  double q2 = quat[2];
  double q3 = quat[3];
  R[0][0] = 1 - 2 * q2 * q2 - 2 * q3 * q3;
  R[1][1] = 1 - 2 * q3 * q3 - 2 * q1 * q1;
  R[2][2] = 1 - 2 * q1 * q1 - 2 * q2 * q2;
  R[0][1] = 2 * q1 * q2 - 2 * q0 * q3;
  R[1][0] = 2 * q1 * q2 + 2 * q0 * q3;
  R[0][2] = 2 * q1 * q3 + 2 * q0 * q2;
  R[2][0] = 2 * q1 * q3 - 2 * q0 * q2;
  R[1][2] = 2 * q2 * q3 - 2 * q0 * q1;
  R[2][1] = 2 * q2 * q3 + 2 * q0 * q1;
  return 0;
}


x86 assembly (clang, -O0):
<quat_to_R>:
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  0xeb5(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe90(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe7c(%rip),%xmm0
mulsd  -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  0xe43(%rip),%xmm1
mulsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe1e(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe0a(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x20(%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,0x20(%rax)
movsd  0xdd0(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xdab(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xd97(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x28(%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,0x40(%rax)
movsd  0xd5d(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xd4b(%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  0xd11(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xcff(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movsd  0xcdc(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xcca(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  0xca7(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xc95(%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,0x30(%rax)
movsd  0xc5b(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xc49(%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,0x28(%rax)
movsd  0xc0f(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  0xbfd(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x38(%rax)
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat_to_R>:
movsd  0x8(%rdi),%xmm8
movupd 0x10(%rdi),%xmm12
movapd %xmm12,%xmm6
addsd  %xmm12,%xmm6
movapd 0xee1(%rip),%xmm11
movapd %xmm12,%xmm9
movsd  %xmm8,%xmm9
movapd 0xedf(%rip),%xmm3
mulpd  %xmm9,%xmm3
movapd %xmm3,%xmm13
movapd %xmm3,%xmm14
xorpd  %xmm11,%xmm14
movapd %xmm3,%xmm10
movapd %xmm3,%xmm4
movapd %xmm3,%xmm0
unpcklpd %xmm6,%xmm14
unpcklpd %xmm6,%xmm3
xorpd  %xmm11,%xmm6
mulsd  %xmm12,%xmm6
movsd  0xeb3(%rip),%xmm2
movapd %xmm6,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm12,%xmm5
unpckhpd %xmm12,%xmm5
unpckhpd %xmm13,%xmm13
mulsd  %xmm5,%xmm13
addsd  %xmm2,%xmm13
mulsd  %xmm8,%xmm10
subsd  %xmm10,%xmm2
movsd  (%rdi),%xmm7
addsd  %xmm6,%xmm2
movsd  %xmm2,0x40(%rsi)
addsd  %xmm7,%xmm7
movapd %xmm7,%xmm2
unpcklpd %xmm7,%xmm2
mulpd  %xmm12,%xmm2
movapd %xmm2,%xmm6
unpckhpd %xmm2,%xmm6
xorpd  %xmm11,%xmm6
unpcklpd %xmm6,%xmm1
mulpd  %xmm12,%xmm4
shufpd $0x1,%xmm4,%xmm4
addpd  %xmm1,%xmm4
movupd %xmm4,(%rsi)
shufpd $0x1,%xmm12,%xmm12
unpcklpd %xmm0,%xmm0
mulpd  %xmm12,%xmm0
addpd  %xmm2,%xmm0
movupd %xmm0,0x10(%rsi)
xorpd  %xmm11,%xmm2
mulsd  %xmm8,%xmm7
xorpd  %xmm7,%xmm11
unpcklpd %xmm11,%xmm13
mulpd  %xmm9,%xmm14
addpd  %xmm13,%xmm14
movupd %xmm14,0x20(%rsi)
unpcklpd %xmm7,%xmm2
mulpd  %xmm5,%xmm3
addpd  %xmm2,%xmm3
movupd %xmm3,0x30(%rsi)
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @quat_to_R(double* %0, [3 x double]* %1) {
%3 = alloca double*
%4 = alloca [3 x double]*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double* %0, double** %3
store [3 x double]* %1, [3 x 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* %7
%22 = fmul double 2.000000e+00, %21
%23 = load double, double* %7
%24 = fneg double %22
%25 = call double @llvm.fmuladd.f64(double %24, double %23, double 1.000000e+00)
%26 = load double, double* %8
%27 = fmul double 2.000000e+00, %26
%28 = load double, double* %8
%29 = fneg double %27
%30 = call double @llvm.fmuladd.f64(double %29, double %28, double %25)
%31 = load [3 x double]*, [3 x double]** %4
%32 = getelementptr inbounds [3 x double], [3 x double]* %31, i64 0
%33 = getelementptr inbounds [3 x double], [3 x double]* %32, i64 0, i64 0
store double %30, double* %33
%34 = load double, double* %8
%35 = fmul double 2.000000e+00, %34
%36 = load double, double* %8
%37 = fneg double %35
%38 = call double @llvm.fmuladd.f64(double %37, double %36, double 1.000000e+00)
%39 = load double, double* %6
%40 = fmul double 2.000000e+00, %39
%41 = load double, double* %6
%42 = fneg double %40
%43 = call double @llvm.fmuladd.f64(double %42, double %41, double %38)
%44 = load [3 x double]*, [3 x double]** %4
%45 = getelementptr inbounds [3 x double], [3 x double]* %44, i64 1
%46 = getelementptr inbounds [3 x double], [3 x double]* %45, i64 0, i64 1
store double %43, double* %46
%47 = load double, double* %6
%48 = fmul double 2.000000e+00, %47
%49 = load double, double* %6
%50 = fneg double %48
%51 = call double @llvm.fmuladd.f64(double %50, double %49, double 1.000000e+00)
%52 = load double, double* %7
%53 = fmul double 2.000000e+00, %52
%54 = load double, double* %7
%55 = fneg double %53
%56 = call double @llvm.fmuladd.f64(double %55, double %54, double %51)
%57 = load [3 x double]*, [3 x double]** %4
%58 = getelementptr inbounds [3 x double], [3 x double]* %57, i64 2
%59 = getelementptr inbounds [3 x double], [3 x double]* %58, i64 0, i64 2
store double %56, 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 = fneg double %66
%68 = call double @llvm.fmuladd.f64(double %61, double %62, double %67)
%69 = load [3 x double]*, [3 x double]** %4
%70 = getelementptr inbounds [3 x double], [3 x double]* %69, i64 0
%71 = getelementptr inbounds [3 x double], [3 x double]* %70, i64 0, i64 1
store double %68, double* %71
%72 = load double, double* %6
%73 = fmul double 2.000000e+00, %72
%74 = load double, double* %7
%75 = load double, double* %5
%76 = fmul double 2.000000e+00, %75
%77 = load double, double* %8
%78 = fmul double %76, %77
%79 = call double @llvm.fmuladd.f64(double %73, double %74, double %78)
%80 = load [3 x double]*, [3 x double]** %4
%81 = getelementptr inbounds [3 x double], [3 x double]* %80, i64 1
%82 = getelementptr inbounds [3 x double], [3 x double]* %81, i64 0, i64 0
store double %79, double* %82
%83 = load double, double* %6
%84 = fmul double 2.000000e+00, %83
%85 = load double, double* %8
%86 = load double, double* %5
%87 = fmul double 2.000000e+00, %86
%88 = load double, double* %7
%89 = fmul double %87, %88
%90 = call double @llvm.fmuladd.f64(double %84, double %85, double %89)
%91 = load [3 x double]*, [3 x double]** %4
%92 = getelementptr inbounds [3 x double], [3 x double]* %91, i64 0
%93 = getelementptr inbounds [3 x double], [3 x double]* %92, i64 0, i64 2
store double %90, double* %93
%94 = load double, double* %6
%95 = fmul double 2.000000e+00, %94
%96 = load double, double* %8
%97 = load double, double* %5
%98 = fmul double 2.000000e+00, %97
%99 = load double, double* %7
%100 = fmul double %98, %99
%101 = fneg double %100
%102 = call double @llvm.fmuladd.f64(double %95, double %96, double %101)
%103 = load [3 x double]*, [3 x double]** %4
%104 = getelementptr inbounds [3 x double], [3 x double]* %103, i64 2
%105 = getelementptr inbounds [3 x double], [3 x double]* %104, i64 0, i64 0
store double %102, double* %105
%106 = load double, double* %7
%107 = fmul double 2.000000e+00, %106
%108 = load double, double* %8
%109 = load double, double* %5
%110 = fmul double 2.000000e+00, %109
%111 = load double, double* %6
%112 = fmul double %110, %111
%113 = fneg double %112
%114 = call double @llvm.fmuladd.f64(double %107, double %108, double %113)
%115 = load [3 x double]*, [3 x double]** %4
%116 = getelementptr inbounds [3 x double], [3 x double]* %115, i64 1
%117 = getelementptr inbounds [3 x double], [3 x double]* %116, i64 0, i64 2
store double %114, double* %117
%118 = load double, double* %7
%119 = fmul double 2.000000e+00, %118
%120 = load double, double* %8
%121 = load double, double* %5
%122 = fmul double 2.000000e+00, %121
%123 = load double, double* %6
%124 = fmul double %122, %123
%125 = call double @llvm.fmuladd.f64(double %119, double %120, double %124)
%126 = load [3 x double]*, [3 x double]** %4
%127 = getelementptr inbounds [3 x double], [3 x double]* %126, i64 2
%128 = getelementptr inbounds [3 x double], [3 x double]* %127, i64 0, i64 1
store double %125, double* %128
ret i32 0
}

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