void quat_to_zvec(double vec[3], double quat[4]) {
  vec[0] = 2.0 * (quat[2] * quat[0] - quat[1] * quat[3]);
  vec[1] = 2.0 * (quat[1] * quat[2] + quat[0] * quat[3]);
  vec[2] = ((quat[3]) * (quat[3])) - ((quat[0]) * (quat[0])) -
           ((quat[1]) * (quat[1])) + ((quat[2]) * (quat[2]));
}


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

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

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

LLVM IR (-O2):
define void @quat_to_zvec(double* nocapture writeonly %0, double* nocapture %1) {
%3 = getelementptr inbounds double, double* %1, i64 2
%4 = load double, double* %3
%5 = load double, double* %1
%6 = getelementptr inbounds double, double* %1, i64 1
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %1, i64 3
%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 = fmul double %12, 2.000000e+00
store double %13, double* %0
%14 = load double, double* %6
%15 = load double, double* %3
%16 = load double, double* %1
%17 = load double, double* %8
%18 = fmul double %16, %17
%19 = tail call double @llvm.fmuladd.f64(double %14, double %15, double %18)
%20 = fmul double %19, 2.000000e+00
%21 = getelementptr inbounds double, double* %0, i64 1
store double %20, double* %21
%22 = load double, double* %8
%23 = load double, double* %1
%24 = fneg double %23
%25 = fmul double %23, %24
%26 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %25)
%27 = load double, double* %6
%28 = fneg double %27
%29 = tail call double @llvm.fmuladd.f64(double %28, double %27, double %26)
%30 = load double, double* %3
%31 = tail call double @llvm.fmuladd.f64(double %30, double %30, double %29)
%32 = getelementptr inbounds double, double* %0, i64 2
store double %31, double* %32
ret void
}