#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ normalize(double *, double *, int);
int sqrt(double);
void rotation_matrix_to_quaternion(double *q, double **R) {
  double S;
  double tr = R[0][0] + R[1][1] + R[2][2];
  if (tr > 0) {
    S = sqrt(tr + 1.0) * 2;
    q[0] = 0.25 * S;
    q[1] = (R[2][1] - R[1][2]) / S;
    q[2] = (R[0][2] - R[2][0]) / S;
    q[3] = (R[1][0] - R[0][1]) / S;
  } else if ((R[0][0] > R[1][1]) && (R[0][0] > R[2][2])) {
    S = sqrt(1.0 + R[0][0] - R[1][1] - R[2][2]) * 2;
    q[0] = (R[2][1] - R[1][2]) / S;
    q[1] = 0.25 * S;
    q[2] = (R[0][1] + R[1][0]) / S;
    q[3] = (R[0][2] + R[2][0]) / S;
  } else if (R[1][1] > R[2][2]) {
    S = sqrt(1.0 + R[1][1] - R[0][0] - R[2][2]) * 2;
    q[0] = (R[0][2] - R[2][0]) / S;
    q[1] = (R[0][1] + R[1][0]) / S;
    q[2] = 0.25 * S;
    q[3] = (R[1][2] + R[2][1]) / S;
  } else {
    S = sqrt(1.0 + R[2][2] - R[0][0] - R[1][1]) * 2;
    q[0] = (R[1][0] - R[0][1]) / S;
    q[1] = (R[0][2] + R[2][0]) / S;
    q[2] = (R[1][2] + R[2][1]) / S;
    q[3] = 0.25 * S;
  }
  normalize(q, q, 4);
}


x86 assembly (clang, -O0):
<rotation_matrix_to_quaternion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
addsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
addsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1218 <rotation_matrix_to_quaternion+0xf8>
movsd  0xe94(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe6e(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
subsd  0x10(%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
subsd  (%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
subsd  0x8(%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    14dd <rotation_matrix_to_quaternion+0x3bd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
ucomisd 0x8(%rax),%xmm0
jbe    1320 <rotation_matrix_to_quaternion+0x200>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
ucomisd 0x10(%rax),%xmm0
jbe    1320 <rotation_matrix_to_quaternion+0x200>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0xda5(%rip),%xmm0
addsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
subsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
subsd  0x10(%rax),%xmm0
call   1040 <sqrt@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
subsd  0x10(%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xd3f(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
addsd  (%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
addsd  (%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    14d8 <rotation_matrix_to_quaternion+0x3b8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
ucomisd 0x10(%rax),%xmm0
jbe    140c <rotation_matrix_to_quaternion+0x2ec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0xcb8(%rip),%xmm0
addsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
subsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
subsd  0x10(%rax),%xmm0
call   1040 <sqrt@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
subsd  (%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
addsd  (%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  0xc2f(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
addsd  0x8(%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    14d3 <rotation_matrix_to_quaternion+0x3b3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsd  0xbec(%rip),%xmm0
addsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
subsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
subsd  0x8(%rax),%xmm0
call   1040 <sqrt@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
subsd  0x8(%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
addsd  (%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
addsd  0x8(%rax),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  0xb3b(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    14d8 <rotation_matrix_to_quaternion+0x3b8>
jmp    14dd <rotation_matrix_to_quaternion+0x3bd>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <normalize@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotation_matrix_to_quaternion>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%rax
mov    0x8(%rsi),%rcx
movsd  (%rax),%xmm1
movsd  0x8(%rcx),%xmm0
movapd %xmm1,%xmm3
addsd  %xmm0,%xmm3
mov    0x10(%rsi),%rax
movsd  0x10(%rax),%xmm2
addsd  %xmm2,%xmm3
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm3
jbe    11c8 <rotation_matrix_to_quaternion+0xa8>
addsd  0xe9f(%rip),%xmm3
movapd %xmm3,%xmm0
call   1040 <sqrt@plt>
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0xe8d(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
mov    0x8(%rbx),%rax
mov    0x10(%rbx),%rcx
movsd  0x8(%rcx),%xmm0
subsd  0x10(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%r14)
mov    (%rbx),%rdx
movsd  0x10(%rdx),%xmm0
subsd  (%rcx),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%r14)
movsd  (%rax),%xmm0
subsd  0x8(%rdx),%xmm0
divsd  %xmm1,%xmm0
jmp    132f <rotation_matrix_to_quaternion+0x20f>
ucomisd %xmm0,%xmm1
jbe    124b <rotation_matrix_to_quaternion+0x12b>
ucomisd %xmm2,%xmm1
jbe    124b <rotation_matrix_to_quaternion+0x12b>
addsd  0xe24(%rip),%xmm1
subsd  %xmm0,%xmm1
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
call   1040 <sqrt@plt>
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mov    0x8(%rbx),%rax
mov    0x10(%rbx),%rcx
movsd  0x8(%rcx),%xmm0
subsd  0x10(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
movsd  0xdef(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%r14)
mov    (%rbx),%rdx
movsd  0x8(%rdx),%xmm0
addsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%r14)
movsd  0x10(%rdx),%xmm0
addsd  (%rcx),%xmm0
divsd  %xmm1,%xmm0
jmp    132f <rotation_matrix_to_quaternion+0x20f>
ucomisd %xmm2,%xmm0
jbe    12c1 <rotation_matrix_to_quaternion+0x1a1>
addsd  0xda7(%rip),%xmm0
subsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
call   1040 <sqrt@plt>
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mov    (%rbx),%rax
mov    0x10(%rbx),%rcx
movsd  0x10(%rax),%xmm0
subsd  (%rcx),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
movsd  0x8(%rax),%xmm0
mov    0x8(%rbx),%rax
addsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%r14)
movsd  0xd61(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%r14)
movsd  0x10(%rax),%xmm0
addsd  0x8(%rcx),%xmm0
divsd  %xmm1,%xmm0
jmp    132f <rotation_matrix_to_quaternion+0x20f>
addsd  0xd37(%rip),%xmm2
subsd  %xmm1,%xmm2
subsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
call   1040 <sqrt@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    (%rbx),%rax
mov    0x8(%rbx),%rcx
movsd  (%rcx),%xmm1
subsd  0x8(%rax),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
movsd  0x10(%rax),%xmm1
mov    0x10(%rbx),%rax
addsd  (%rax),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%r14)
movsd  0x10(%rcx),%xmm1
addsd  0x8(%rax),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%r14)
mulsd  0xcd9(%rip),%xmm0
movsd  %xmm0,0x18(%r14)
mov    %r14,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <normalize@plt>

LLVM IR (-O0):
define void @rotation_matrix_to_quaternion(double* %0, double** %1) {
%3 = alloca double*
%4 = alloca double**
%5 = alloca double
%6 = alloca double
store double* %0, double** %3
store double** %1, double*** %4
%7 = load double**, double*** %4
%8 = getelementptr inbounds double*, double** %7, i64 0
%9 = load double*, double** %8
%10 = getelementptr inbounds double, double* %9, i64 0
%11 = load double, double* %10
%12 = load double**, double*** %4
%13 = getelementptr inbounds double*, double** %12, i64 1
%14 = load double*, double** %13
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = fadd double %11, %16
%18 = load double**, double*** %4
%19 = getelementptr inbounds double*, double** %18, i64 2
%20 = load double*, double** %19
%21 = getelementptr inbounds double, double* %20, i64 2
%22 = load double, double* %21
%23 = fadd double %17, %22
store double %23, double* %6
%24 = load double, double* %6
%25 = fcmp ogt double %24, 0.000000e+00
br i1 %25, label %26, label %81
26: ; preds = %2
%27 = load double, double* %6
%28 = fadd double %27, 1.000000e+00
%29 = call i32 @sqrt(double %28)
%30 = mul nsw i32 %29, 2
%31 = sitofp i32 %30 to double
store double %31, double* %5
%32 = load double, double* %5
%33 = fmul double 2.500000e-01, %32
%34 = load double*, double** %3
%35 = getelementptr inbounds double, double* %34, i64 0
store double %33, double* %35
%36 = load double**, double*** %4
%37 = getelementptr inbounds double*, double** %36, i64 2
%38 = load double*, double** %37
%39 = getelementptr inbounds double, double* %38, i64 1
%40 = load double, double* %39
%41 = load double**, double*** %4
%42 = getelementptr inbounds double*, double** %41, i64 1
%43 = load double*, double** %42
%44 = getelementptr inbounds double, double* %43, i64 2
%45 = load double, double* %44
%46 = fsub double %40, %45
%47 = load double, double* %5
%48 = fdiv double %46, %47
%49 = load double*, double** %3
%50 = getelementptr inbounds double, double* %49, i64 1
store double %48, double* %50
%51 = load double**, double*** %4
%52 = getelementptr inbounds double*, double** %51, i64 0
%53 = load double*, double** %52
%54 = getelementptr inbounds double, double* %53, i64 2
%55 = load double, double* %54
%56 = load double**, double*** %4
%57 = getelementptr inbounds double*, double** %56, i64 2
%58 = load double*, double** %57
%59 = getelementptr inbounds double, double* %58, i64 0
%60 = load double, double* %59
%61 = fsub double %55, %60
%62 = load double, double* %5
%63 = fdiv double %61, %62
%64 = load double*, double** %3
%65 = getelementptr inbounds double, double* %64, i64 2
store double %63, double* %65
%66 = load double**, double*** %4
%67 = getelementptr inbounds double*, double** %66, i64 1
%68 = load double*, double** %67
%69 = getelementptr inbounds double, double* %68, i64 0
%70 = load double, double* %69
%71 = load double**, double*** %4
%72 = getelementptr inbounds double*, double** %71, i64 0
%73 = load double*, double** %72
%74 = getelementptr inbounds double, double* %73, i64 1
%75 = load double, double* %74
%76 = fsub double %70, %75
%77 = load double, double* %5
%78 = fdiv double %76, %77
%79 = load double*, double** %3
%80 = getelementptr inbounds double, double* %79, i64 3
store double %78, double* %80
br label %332
81: ; preds = %2
%82 = load double**, double*** %4
%83 = getelementptr inbounds double*, double** %82, i64 0
%84 = load double*, double** %83
%85 = getelementptr inbounds double, double* %84, i64 0
%86 = load double, double* %85
%87 = load double**, double*** %4
%88 = getelementptr inbounds double*, double** %87, i64 1
%89 = load double*, double** %88
%90 = getelementptr inbounds double, double* %89, i64 1
%91 = load double, double* %90
%92 = fcmp ogt double %86, %91
br i1 %92, label %93, label %176
93: ; preds = %81
%94 = load double**, double*** %4
%95 = getelementptr inbounds double*, double** %94, i64 0
%96 = load double*, double** %95
%97 = getelementptr inbounds double, double* %96, i64 0
%98 = load double, double* %97
%99 = load double**, double*** %4
%100 = getelementptr inbounds double*, double** %99, i64 2
%101 = load double*, double** %100
%102 = getelementptr inbounds double, double* %101, i64 2
%103 = load double, double* %102
%104 = fcmp ogt double %98, %103
br i1 %104, label %105, label %176
105: ; preds = %93
%106 = load double**, double*** %4
%107 = getelementptr inbounds double*, double** %106, i64 0
%108 = load double*, double** %107
%109 = getelementptr inbounds double, double* %108, i64 0
%110 = load double, double* %109
%111 = fadd double 1.000000e+00, %110
%112 = load double**, double*** %4
%113 = getelementptr inbounds double*, double** %112, i64 1
%114 = load double*, double** %113
%115 = getelementptr inbounds double, double* %114, i64 1
%116 = load double, double* %115
%117 = fsub double %111, %116
%118 = load double**, double*** %4
%119 = getelementptr inbounds double*, double** %118, i64 2
%120 = load double*, double** %119
%121 = getelementptr inbounds double, double* %120, i64 2
%122 = load double, double* %121
%123 = fsub double %117, %122
%124 = call i32 @sqrt(double %123)
%125 = mul nsw i32 %124, 2
%126 = sitofp i32 %125 to double
store double %126, double* %5
%127 = load double**, double*** %4
%128 = getelementptr inbounds double*, double** %127, i64 2
%129 = load double*, double** %128
%130 = getelementptr inbounds double, double* %129, i64 1
%131 = load double, double* %130
%132 = load double**, double*** %4
%133 = getelementptr inbounds double*, double** %132, i64 1
%134 = load double*, double** %133
%135 = getelementptr inbounds double, double* %134, i64 2
%136 = load double, double* %135
%137 = fsub double %131, %136
%138 = load double, double* %5
%139 = fdiv double %137, %138
%140 = load double*, double** %3
%141 = getelementptr inbounds double, double* %140, i64 0
store double %139, double* %141
%142 = load double, double* %5
%143 = fmul double 2.500000e-01, %142
%144 = load double*, double** %3
%145 = getelementptr inbounds double, double* %144, i64 1
store double %143, double* %145
%146 = load double**, double*** %4
%147 = getelementptr inbounds double*, double** %146, i64 0
%148 = load double*, double** %147
%149 = getelementptr inbounds double, double* %148, i64 1
%150 = load double, double* %149
%151 = load double**, double*** %4
%152 = getelementptr inbounds double*, double** %151, i64 1
%153 = load double*, double** %152
%154 = getelementptr inbounds double, double* %153, i64 0
%155 = load double, double* %154
%156 = fadd double %150, %155
%157 = load double, double* %5
%158 = fdiv double %156, %157
%159 = load double*, double** %3
%160 = getelementptr inbounds double, double* %159, i64 2
store double %158, double* %160
%161 = load double**, double*** %4
%162 = getelementptr inbounds double*, double** %161, i64 0
%163 = load double*, double** %162
%164 = getelementptr inbounds double, double* %163, i64 2
%165 = load double, double* %164
%166 = load double**, double*** %4
%167 = getelementptr inbounds double*, double** %166, i64 2
%168 = load double*, double** %167
%169 = getelementptr inbounds double, double* %168, i64 0
%170 = load double, double* %169
%171 = fadd double %165, %170
%172 = load double, double* %5
%173 = fdiv double %171, %172
%174 = load double*, double** %3
%175 = getelementptr inbounds double, double* %174, i64 3
store double %173, double* %175
br label %331
176: ; preds = %93, %81
%177 = load double**, double*** %4
%178 = getelementptr inbounds double*, double** %177, i64 1
%179 = load double*, double** %178
%180 = getelementptr inbounds double, double* %179, i64 1
%181 = load double, double* %180
%182 = load double**, double*** %4
%183 = getelementptr inbounds double*, double** %182, i64 2
%184 = load double*, double** %183
%185 = getelementptr inbounds double, double* %184, i64 2
%186 = load double, double* %185
%187 = fcmp ogt double %181, %186
br i1 %187, label %188, label %259
188: ; preds = %176
%189 = load double**, double*** %4
%190 = getelementptr inbounds double*, double** %189, i64 1
%191 = load double*, double** %190
%192 = getelementptr inbounds double, double* %191, i64 1
%193 = load double, double* %192
%194 = fadd double 1.000000e+00, %193
%195 = load double**, double*** %4
%196 = getelementptr inbounds double*, double** %195, i64 0
%197 = load double*, double** %196
%198 = getelementptr inbounds double, double* %197, i64 0
%199 = load double, double* %198
%200 = fsub double %194, %199
%201 = load double**, double*** %4
%202 = getelementptr inbounds double*, double** %201, i64 2
%203 = load double*, double** %202
%204 = getelementptr inbounds double, double* %203, i64 2
%205 = load double, double* %204
%206 = fsub double %200, %205
%207 = call i32 @sqrt(double %206)
%208 = mul nsw i32 %207, 2
%209 = sitofp i32 %208 to double
store double %209, double* %5
%210 = load double**, double*** %4
%211 = getelementptr inbounds double*, double** %210, i64 0
%212 = load double*, double** %211
%213 = getelementptr inbounds double, double* %212, i64 2
%214 = load double, double* %213
%215 = load double**, double*** %4
%216 = getelementptr inbounds double*, double** %215, i64 2
%217 = load double*, double** %216
%218 = getelementptr inbounds double, double* %217, i64 0
%219 = load double, double* %218
%220 = fsub double %214, %219
%221 = load double, double* %5
%222 = fdiv double %220, %221
%223 = load double*, double** %3
%224 = getelementptr inbounds double, double* %223, i64 0
store double %222, double* %224
%225 = load double**, double*** %4
%226 = getelementptr inbounds double*, double** %225, i64 0
%227 = load double*, double** %226
%228 = getelementptr inbounds double, double* %227, i64 1
%229 = load double, double* %228
%230 = load double**, double*** %4
%231 = getelementptr inbounds double*, double** %230, i64 1
%232 = load double*, double** %231
%233 = getelementptr inbounds double, double* %232, i64 0
%234 = load double, double* %233
%235 = fadd double %229, %234
%236 = load double, double* %5
%237 = fdiv double %235, %236
%238 = load double*, double** %3
%239 = getelementptr inbounds double, double* %238, i64 1
store double %237, double* %239
%240 = load double, double* %5
%241 = fmul double 2.500000e-01, %240
%242 = load double*, double** %3
%243 = getelementptr inbounds double, double* %242, i64 2
store double %241, double* %243
%244 = load double**, double*** %4
%245 = getelementptr inbounds double*, double** %244, i64 1
%246 = load double*, double** %245
%247 = getelementptr inbounds double, double* %246, i64 2
%248 = load double, double* %247
%249 = load double**, double*** %4
%250 = getelementptr inbounds double*, double** %249, i64 2
%251 = load double*, double** %250
%252 = getelementptr inbounds double, double* %251, i64 1
%253 = load double, double* %252
%254 = fadd double %248, %253
%255 = load double, double* %5
%256 = fdiv double %254, %255
%257 = load double*, double** %3
%258 = getelementptr inbounds double, double* %257, i64 3
store double %256, double* %258
br label %330
259: ; preds = %176
%260 = load double**, double*** %4
%261 = getelementptr inbounds double*, double** %260, i64 2
%262 = load double*, double** %261
%263 = getelementptr inbounds double, double* %262, i64 2
%264 = load double, double* %263
%265 = fadd double 1.000000e+00, %264
%266 = load double**, double*** %4
%267 = getelementptr inbounds double*, double** %266, i64 0
%268 = load double*, double** %267
%269 = getelementptr inbounds double, double* %268, i64 0
%270 = load double, double* %269
%271 = fsub double %265, %270
%272 = load double**, double*** %4
%273 = getelementptr inbounds double*, double** %272, i64 1
%274 = load double*, double** %273
%275 = getelementptr inbounds double, double* %274, i64 1
%276 = load double, double* %275
%277 = fsub double %271, %276
%278 = call i32 @sqrt(double %277)
%279 = mul nsw i32 %278, 2
%280 = sitofp i32 %279 to double
store double %280, double* %5
%281 = load double**, double*** %4
%282 = getelementptr inbounds double*, double** %281, i64 1
%283 = load double*, double** %282
%284 = getelementptr inbounds double, double* %283, i64 0
%285 = load double, double* %284
%286 = load double**, double*** %4
%287 = getelementptr inbounds double*, double** %286, i64 0
%288 = load double*, double** %287
%289 = getelementptr inbounds double, double* %288, i64 1
%290 = load double, double* %289
%291 = fsub double %285, %290
%292 = load double, double* %5
%293 = fdiv double %291, %292
%294 = load double*, double** %3
%295 = getelementptr inbounds double, double* %294, i64 0
store double %293, double* %295
%296 = load double**, double*** %4
%297 = getelementptr inbounds double*, double** %296, i64 0
%298 = load double*, double** %297
%299 = getelementptr inbounds double, double* %298, i64 2
%300 = load double, double* %299
%301 = load double**, double*** %4
%302 = getelementptr inbounds double*, double** %301, i64 2
%303 = load double*, double** %302
%304 = getelementptr inbounds double, double* %303, i64 0
%305 = load double, double* %304
%306 = fadd double %300, %305
%307 = load double, double* %5
%308 = fdiv double %306, %307
%309 = load double*, double** %3
%310 = getelementptr inbounds double, double* %309, i64 1
store double %308, double* %310
%311 = load double**, double*** %4
%312 = getelementptr inbounds double*, double** %311, i64 1
%313 = load double*, double** %312
%314 = getelementptr inbounds double, double* %313, i64 2
%315 = load double, double* %314
%316 = load double**, double*** %4
%317 = getelementptr inbounds double*, double** %316, i64 2
%318 = load double*, double** %317
%319 = getelementptr inbounds double, double* %318, i64 1
%320 = load double, double* %319
%321 = fadd double %315, %320
%322 = load double, double* %5
%323 = fdiv double %321, %322
%324 = load double*, double** %3
%325 = getelementptr inbounds double, double* %324, i64 2
store double %323, double* %325
%326 = load double, double* %5
%327 = fmul double 2.500000e-01, %326
%328 = load double*, double** %3
%329 = getelementptr inbounds double, double* %328, i64 3
store double %327, double* %329
br label %330
330: ; preds = %259, %188
br label %331
331: ; preds = %330, %105
br label %332
332: ; preds = %331, %26
%333 = load double*, double** %3
%334 = load double*, double** %3
%335 = call i32 @normalize(double* %333, double* %334, i32 4)
ret void
}

LLVM IR (-O2):
define void @rotation_matrix_to_quaternion(double* %0, double** nocapture %1) {
%3 = load double*, double** %1
%4 = load double, double* %3
%5 = getelementptr inbounds double*, double** %1, i64 1
%6 = load double*, double** %5
%7 = getelementptr inbounds double, double* %6, i64 1
%8 = load double, double* %7
%9 = fadd double %4, %8
%10 = getelementptr inbounds double*, double** %1, i64 2
%11 = load double*, double** %10
%12 = getelementptr inbounds double, double* %11, i64 2
%13 = load double, double* %12
%14 = fadd double %9, %13
%15 = fcmp ogt double %14, 0.000000e+00
br i1 %15, label %16, label %43
16: ; preds = %2
%17 = fadd double %14, 1.000000e+00
%18 = tail call i32 @sqrt(double %17)
%19 = shl nsw i32 %18, 1
%20 = sitofp i32 %19 to double
%21 = fmul double %20, 2.500000e-01
store double %21, double* %0
%22 = load double*, double** %10
%23 = getelementptr inbounds double, double* %22, i64 1
%24 = load double, double* %23
%25 = load double*, double** %5
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = fsub double %24, %27
%29 = fdiv double %28, %20
%30 = getelementptr inbounds double, double* %0, i64 1
store double %29, double* %30
%31 = load double*, double** %1
%32 = getelementptr inbounds double, double* %31, i64 2
%33 = load double, double* %32
%34 = load double, double* %22
%35 = fsub double %33, %34
%36 = fdiv double %35, %20
%37 = getelementptr inbounds double, double* %0, i64 2
store double %36, double* %37
%38 = load double, double* %25
%39 = getelementptr inbounds double, double* %31, i64 1
%40 = load double, double* %39
%41 = fsub double %38, %40
%42 = fdiv double %41, %20
br label %136
43: ; preds = %2
%44 = fcmp ogt double %4, %8
%45 = fcmp ogt double %4, %13
%46 = select i1 %44, i1 %45, i1 false
br i1 %46, label %47, label %76
47: ; preds = %43
%48 = fadd double %4, 1.000000e+00
%49 = fsub double %48, %8
%50 = fsub double %49, %13
%51 = tail call i32 @sqrt(double %50)
%52 = shl nsw i32 %51, 1
%53 = sitofp i32 %52 to double
%54 = load double*, double** %10
%55 = getelementptr inbounds double, double* %54, i64 1
%56 = load double, double* %55
%57 = load double*, double** %5
%58 = getelementptr inbounds double, double* %57, i64 2
%59 = load double, double* %58
%60 = fsub double %56, %59
%61 = fdiv double %60, %53
store double %61, double* %0
%62 = fmul double %53, 2.500000e-01
%63 = getelementptr inbounds double, double* %0, i64 1
store double %62, double* %63
%64 = load double*, double** %1
%65 = getelementptr inbounds double, double* %64, i64 1
%66 = load double, double* %65
%67 = load double, double* %57
%68 = fadd double %66, %67
%69 = fdiv double %68, %53
%70 = getelementptr inbounds double, double* %0, i64 2
store double %69, double* %70
%71 = getelementptr inbounds double, double* %64, i64 2
%72 = load double, double* %71
%73 = load double, double* %54
%74 = fadd double %72, %73
%75 = fdiv double %74, %53
br label %136
76: ; preds = %43
%77 = fcmp ogt double %8, %13
br i1 %77, label %78, label %107
78: ; preds = %76
%79 = fadd double %8, 1.000000e+00
%80 = fsub double %79, %4
%81 = fsub double %80, %13
%82 = tail call i32 @sqrt(double %81)
%83 = shl nsw i32 %82, 1
%84 = sitofp i32 %83 to double
%85 = load double*, double** %1
%86 = getelementptr inbounds double, double* %85, i64 2
%87 = load double, double* %86
%88 = load double*, double** %10
%89 = load double, double* %88
%90 = fsub double %87, %89
%91 = fdiv double %90, %84
store double %91, double* %0
%92 = getelementptr inbounds double, double* %85, i64 1
%93 = load double, double* %92
%94 = load double*, double** %5
%95 = load double, double* %94
%96 = fadd double %93, %95
%97 = fdiv double %96, %84
%98 = getelementptr inbounds double, double* %0, i64 1
store double %97, double* %98
%99 = fmul double %84, 2.500000e-01
%100 = getelementptr inbounds double, double* %0, i64 2
store double %99, double* %100
%101 = getelementptr inbounds double, double* %94, i64 2
%102 = load double, double* %101
%103 = getelementptr inbounds double, double* %88, i64 1
%104 = load double, double* %103
%105 = fadd double %102, %104
%106 = fdiv double %105, %84
br label %136
107: ; preds = %76
%108 = fadd double %13, 1.000000e+00
%109 = fsub double %108, %4
%110 = fsub double %109, %8
%111 = tail call i32 @sqrt(double %110)
%112 = shl nsw i32 %111, 1
%113 = sitofp i32 %112 to double
%114 = load double*, double** %5
%115 = load double, double* %114
%116 = load double*, double** %1
%117 = getelementptr inbounds double, double* %116, i64 1
%118 = load double, double* %117
%119 = fsub double %115, %118
%120 = fdiv double %119, %113
store double %120, double* %0
%121 = getelementptr inbounds double, double* %116, i64 2
%122 = load double, double* %121
%123 = load double*, double** %10
%124 = load double, double* %123
%125 = fadd double %122, %124
%126 = fdiv double %125, %113
%127 = getelementptr inbounds double, double* %0, i64 1
store double %126, double* %127
%128 = getelementptr inbounds double, double* %114, i64 2
%129 = load double, double* %128
%130 = getelementptr inbounds double, double* %123, i64 1
%131 = load double, double* %130
%132 = fadd double %129, %131
%133 = fdiv double %132, %113
%134 = getelementptr inbounds double, double* %0, i64 2
store double %133, double* %134
%135 = fmul double %113, 2.500000e-01
br label %136
136: ; preds = %47, %107, %78, %16
%137 = phi double [ %75, %47 ], [ %135, %107 ], [ %106, %78 ], [ %42, %16 ]
%138 = getelementptr inbounds double, double* %0, i64 3
store double %137, double* %138
%139 = tail call i32 @normalize(double* %0, double* %0, i32 4)
ret void
}