#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 */
double fabs(double);
double sqrt(double const);
int bot_matrix_to_quat(const double rot[9], double quat[4]) {
  quat[0] = 0.5 * sqrt(rot[0] + rot[4] + rot[8] + 1);
  if (fabs(quat[0]) > 1e-8) {
    double w4 = 1.0 / (4.0 * quat[0]);
    quat[1] = (rot[7] - rot[5]) * w4;
    quat[2] = (rot[2] - rot[6]) * w4;
    quat[3] = (rot[3] - rot[1]) * w4;
  } else {
    quat[1] = sqrt(fabs(-0.5 * (rot[4] + rot[8])));
    quat[2] = sqrt(fabs(-0.5 * (rot[0] + rot[8])));
    quat[3] = sqrt(fabs(-0.5 * (rot[0] + rot[4])));
  }
  double norm = sqrt(quat[0] * quat[0] + quat[1] * quat[1] + quat[2] * quat[2] +
                     quat[3] * quat[3]);
  norm = 1 / norm;
  quat[0] *= norm;
  quat[1] *= norm;
  quat[2] *= norm;
  quat[3] *= norm;
  return 0;
}


x86 assembly (clang, -O0):
<bot_matrix_to_quat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
addsd  0x20(%rax),%xmm0
mov    -0x8(%rbp),%rax
addsd  0x40(%rax),%xmm0
movsd  0xece(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xeb2(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xebf(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe83(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    120d <bot_matrix_to_quat+0xfd>
mov    -0x10(%rbp),%rax
movsd  0xe8d(%rip),%xmm1
mulsd  (%rax),%xmm1
movsd  0xe71(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x38(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x28(%rax),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x30(%rax),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm0
mulsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    12b0 <bot_matrix_to_quat+0x1a0>
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm1
mov    -0x8(%rbp),%rax
addsd  0x40(%rax),%xmm1
movsd  0xdf1(%rip),%xmm0
mulsd  %xmm1,%xmm0
movaps 0xdfe(%rip),%xmm1
pand   %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
addsd  0x40(%rax),%xmm1
movsd  0xdbb(%rip),%xmm0
mulsd  %xmm1,%xmm0
movaps 0xdc8(%rip),%xmm1
pand   %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
addsd  0x20(%rax),%xmm1
movsd  0xd85(%rip),%xmm0
mulsd  %xmm1,%xmm0
movaps 0xd92(%rip),%xmm1
pand   %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x18(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xcf0(%rip),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,0x10(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x18(%rax),%xmm0
movsd  %xmm0,0x18(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_matrix_to_quat>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
addsd  0x20(%rdi),%xmm0
addsd  0x40(%rdi),%xmm0
addsd  0xed3(%rip),%xmm0
mov    %rsi,%r14
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1140 <bot_matrix_to_quat+0x30>
sqrtsd %xmm0,%xmm0
jmp    1145 <bot_matrix_to_quat+0x35>
call   1030 <sqrt@plt>
mulsd  0xebb(%rip),%xmm0
movsd  %xmm0,(%r14)
movapd 0xed6(%rip),%xmm1
andpd  %xmm0,%xmm1
ucomisd 0xeaa(%rip),%xmm1
jbe    11bb <bot_matrix_to_quat+0xab>
movsd  0xeb0(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe84(%rip),%xmm4
movsd  0x38(%rbx),%xmm3
subsd  0x28(%rbx),%xmm3
divsd  %xmm1,%xmm4
mulsd  %xmm4,%xmm3
movsd  %xmm3,0x8(%r14)
movsd  0x10(%rbx),%xmm2
subsd  0x30(%rbx),%xmm2
mulsd  %xmm4,%xmm2
movsd  %xmm2,0x10(%r14)
movsd  0x18(%rbx),%xmm1
subsd  0x8(%rbx),%xmm1
mulsd  %xmm4,%xmm1
jmp    126a <bot_matrix_to_quat+0x15a>
movsd  0x20(%rbx),%xmm0
addsd  0x40(%rbx),%xmm0
mulsd  0xe4b(%rip),%xmm0
andpd  0xe5b(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e5 <bot_matrix_to_quat+0xd5>
sqrtsd %xmm0,%xmm0
jmp    11ee <bot_matrix_to_quat+0xde>
call   1030 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%r14)
movsd  (%rbx),%xmm0
addsd  0x40(%rbx),%xmm0
mulsd  0xe13(%rip),%xmm0
andpd  0xe23(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1219 <bot_matrix_to_quat+0x109>
sqrtsd %xmm0,%xmm0
jmp    121e <bot_matrix_to_quat+0x10e>
call   1030 <sqrt@plt>
movsd  %xmm0,0x10(%r14)
movsd  (%rbx),%xmm0
addsd  0x20(%rbx),%xmm0
mulsd  0xde3(%rip),%xmm0
andpd  0xdf3(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1250 <bot_matrix_to_quat+0x140>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1259 <bot_matrix_to_quat+0x149>
call   1030 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  (%r14),%xmm0
movsd  0x8(%r14),%xmm3
movsd  0x10(%r14),%xmm2
movsd  %xmm1,0x18(%r14)
mulsd  %xmm3,%xmm3
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     129f <bot_matrix_to_quat+0x18f>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    12a8 <bot_matrix_to_quat+0x198>
movapd %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  0xd50(%rip),%xmm1
divsd  %xmm0,%xmm1
unpcklpd %xmm1,%xmm1
movupd (%r14),%xmm0
movupd 0x10(%r14),%xmm2
mulpd  %xmm1,%xmm0
movupd %xmm0,(%r14)
mulpd  %xmm1,%xmm2
movupd %xmm2,0x10(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @bot_matrix_to_quat(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 4
%5 = load double, double* %4
%6 = fadd double %3, %5
%7 = getelementptr inbounds double, double* %0, i64 8
%8 = load double, double* %7
%9 = fadd double %6, %8
%10 = fadd double %9, 1.000000e+00
%11 = tail call double @sqrt(double %10)
%12 = fmul double %11, 5.000000e-01
store double %12, double* %1
%13 = tail call double @llvm.fabs.f64(double %12)
%14 = fcmp ogt double %13, 1.000000e-08
br i1 %14, label %15, label %38
15: ; preds = %2
%16 = fmul double %12, 4.000000e+00
%17 = fdiv double 1.000000e+00, %16
%18 = getelementptr inbounds double, double* %0, i64 7
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %0, i64 5
%21 = load double, double* %20
%22 = fsub double %19, %21
%23 = fmul double %17, %22
%24 = getelementptr inbounds double, double* %1, i64 1
store double %23, double* %24
%25 = getelementptr inbounds double, double* %0, i64 2
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %0, i64 6
%28 = load double, double* %27
%29 = fsub double %26, %28
%30 = fmul double %17, %29
%31 = getelementptr inbounds double, double* %1, i64 2
store double %30, double* %31
%32 = getelementptr inbounds double, double* %0, i64 3
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %0, i64 1
%35 = load double, double* %34
%36 = fsub double %33, %35
%37 = fmul double %17, %36
br label %62
38: ; preds = %2
%39 = load double, double* %4
%40 = load double, double* %7
%41 = fadd double %39, %40
%42 = fmul double %41, -5.000000e-01
%43 = tail call double @llvm.fabs.f64(double %42)
%44 = tail call double @sqrt(double %43)
%45 = getelementptr inbounds double, double* %1, i64 1
store double %44, double* %45
%46 = load double, double* %0
%47 = load double, double* %7
%48 = fadd double %46, %47
%49 = fmul double %48, -5.000000e-01
%50 = tail call double @llvm.fabs.f64(double %49)
%51 = tail call double @sqrt(double %50)
%52 = getelementptr inbounds double, double* %1, i64 2
store double %51, double* %52
%53 = load double, double* %0
%54 = load double, double* %4
%55 = fadd double %53, %54
%56 = fmul double %55, -5.000000e-01
%57 = tail call double @llvm.fabs.f64(double %56)
%58 = tail call double @sqrt(double %57)
%59 = load double, double* %1
%60 = load double, double* %45
%61 = load double, double* %52
br label %62
62: ; preds = %38, %15
%63 = phi double [ %30, %15 ], [ %61, %38 ]
%64 = phi double [ %23, %15 ], [ %60, %38 ]
%65 = phi double [ %12, %15 ], [ %59, %38 ]
%66 = phi double [ %37, %15 ], [ %58, %38 ]
%67 = getelementptr inbounds double, double* %1, i64 3
store double %66, double* %67
%68 = fmul double %64, %64
%69 = tail call double @llvm.fmuladd.f64(double %65, double %65, double %68)
%70 = getelementptr inbounds double, double* %1, i64 2
%71 = tail call double @llvm.fmuladd.f64(double %63, double %63, double %69)
%72 = tail call double @llvm.fmuladd.f64(double %66, double %66, double %71)
%73 = tail call double @sqrt(double %72)
%74 = fdiv double 1.000000e+00, %73
%75 = bitcast double* %1 to <2 x double>*
%76 = load <2 x double>, <2 x double>* %75
%77 = insertelement <2 x double> poison, double %74, i64 0
%78 = shufflevector <2 x double> %77, <2 x double> poison, <2 x i32> zeroinitializer
%79 = fmul <2 x double> %76, %78
%80 = bitcast double* %1 to <2 x double>*
store <2 x double> %79, <2 x double>* %80
%81 = bitcast double* %70 to <2 x double>*
%82 = load <2 x double>, <2 x double>* %81
%83 = fmul <2 x double> %78, %82
%84 = bitcast double* %70 to <2 x double>*
store <2 x double> %83, <2 x double>* %84
ret i32 0
}