void bot_quat_rotate_to(const double rot[4], const double v[3], double r[3]) {
  double ab = rot[0] * rot[1], ac = rot[0] * rot[2], ad = rot[0] * rot[3];
  double nbb = -rot[1] * rot[1], bc = rot[1] * rot[2], bd = rot[1] * rot[3];
  double ncc = -rot[2] * rot[2], cd = rot[2] * rot[3], ndd = -rot[3] * rot[3];
  r[0] = 2 * ((ncc + ndd) * v[0] + (bc - ad) * v[1] + (ac + bd) * v[2]) + v[0];
  r[1] = 2 * ((ad + bc) * v[0] + (nbb + ndd) * v[1] + (cd - ab) * v[2]) + v[1];
  r[2] = 2 * ((bd - ac) * v[0] + (ab + cd) * v[1] + (nbb + ncc) * v[2]) + v[2];
}


x86 assembly (clang, -O0):
<bot_quat_rotate_to>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm1
addsd  -0x60(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x38(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x48(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x20(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
pop    %rbp
ret

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

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

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