#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 atan2(double, double);
double fabs(double);
double sqrt(double);
void RotToZYXEulerAngle(double R[3][3], double *alpha, double *beta,
                        double *gamma) {
  if (fabs(1.0 + R[2][0]) < 1.0E-6) {
    *alpha = 0;
    *beta = 3.14159265358979323846 / 2.0;
    *gamma = atan2(R[0][1], R[1][1]);
  } else if (fabs(1.0 - R[2][0]) < 1.0E-6) {
    *alpha = 0;
    *beta = -3.14159265358979323846 / 2.0;
    *gamma = atan2(R[0][1], R[1][1]);
  } else {
    *alpha = atan2(R[1][0], R[0][0]);
    *beta = atan2(-R[2][0], sqrt(R[0][0] * R[0][0] + R[1][0] * R[1][0]));
    *gamma = atan2(R[2][1], R[2][2]);
  }
  return;
}


x86 assembly (clang, -O0):
<RotToZYXEulerAngle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xec4(%rip),%xmm1
addsd  0x30(%rax),%xmm1
movaps 0xed0(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xea4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a5 <RotToZYXEulerAngle+0x85>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    12bd <RotToZYXEulerAngle+0x19d>
mov    -0x8(%rbp),%rax
movsd  0xe57(%rip),%xmm1
subsd  0x30(%rax),%xmm1
movaps 0xe63(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe37(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1212 <RotToZYXEulerAngle+0xf2>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0xe26(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    12b8 <RotToZYXEulerAngle+0x198>
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x30(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x18(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
call   1030 <atan2@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x38(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x40(%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    12bd <RotToZYXEulerAngle+0x19d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RotToZYXEulerAngle>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movsd  0x30(%rdi),%xmm0
movsd  0xec5(%rip),%xmm2
addsd  %xmm0,%xmm2
andpd  0xec9(%rip),%xmm2
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
movsd  0xeb0(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    1172 <RotToZYXEulerAngle+0x52>
movq   $0x0,(%r12)
movabs $0x3ff921fb54442d18,%rax
21 f9 3f
jmp    119e <RotToZYXEulerAngle+0x7e>
movsd  0xe86(%rip),%xmm2
subsd  %xmm0,%xmm2
andpd  0xe8a(%rip),%xmm2
ucomisd %xmm2,%xmm1
jbe    11ab <RotToZYXEulerAngle+0x8b>
movq   $0x0,(%r12)
movabs $0xbff921fb54442d18,%rax
21 f9 bf
mov    %rax,(%r15)
lea    0x8(%rbx),%rax
add    $0x20,%rbx
jmp    121d <RotToZYXEulerAngle+0xfd>
movsd  (%rbx),%xmm1
movsd  0x18(%rbx),%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%r12)
movsd  0x30(%rbx),%xmm2
xorpd  0xe54(%rip),%xmm2
movsd  (%rbx),%xmm0
movsd  0x18(%rbx),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11f4 <RotToZYXEulerAngle+0xd4>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1207 <RotToZYXEulerAngle+0xe7>
movapd %xmm2,(%rsp)
call   1040 <sqrt@plt>
movapd (%rsp),%xmm2
movapd %xmm0,%xmm1
movapd %xmm2,%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%r15)
lea    0x38(%rbx),%rax
add    $0x40,%rbx
movsd  (%rax),%xmm0
movsd  (%rbx),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @RotToZYXEulerAngle([3 x double]* %0, double* %1, double* %2, double* %3) {
%5 = alloca [3 x double]*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
store [3 x double]* %0, [3 x double]** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%9 = load [3 x double]*, [3 x double]** %5
%10 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 2
%11 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%12 = load double, double* %11
%13 = fadd double 1.000000e+00, %12
%14 = call double @llvm.fabs.f64(double %13)
%15 = fcmp olt double %14, 0x3EB0C6F7A0B5ED8D
br i1 %15, label %16, label %29
16: ; preds = %4
%17 = load double*, double** %6
store double 0.000000e+00, double* %17
%18 = load double*, double** %7
store double 0x3FF921FB54442D18, double* %18
%19 = load [3 x double]*, [3 x double]** %5
%20 = getelementptr inbounds [3 x double], [3 x double]* %19, i64 0
%21 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 1
%22 = load double, double* %21
%23 = load [3 x double]*, [3 x double]** %5
%24 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 1
%25 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 0, i64 1
%26 = load double, double* %25
%27 = call double @atan2(double %22, double %26)
%28 = load double*, double** %8
store double %27, double* %28
br label %98
29: ; preds = %4
%30 = load [3 x double]*, [3 x double]** %5
%31 = getelementptr inbounds [3 x double], [3 x double]* %30, i64 2
%32 = getelementptr inbounds [3 x double], [3 x double]* %31, i64 0, i64 0
%33 = load double, double* %32
%34 = fsub double 1.000000e+00, %33
%35 = call double @llvm.fabs.f64(double %34)
%36 = fcmp olt double %35, 0x3EB0C6F7A0B5ED8D
br i1 %36, label %37, label %50
37: ; preds = %29
%38 = load double*, double** %6
store double 0.000000e+00, double* %38
%39 = load double*, double** %7
store double 0xBFF921FB54442D18, double* %39
%40 = load [3 x double]*, [3 x double]** %5
%41 = getelementptr inbounds [3 x double], [3 x double]* %40, i64 0
%42 = getelementptr inbounds [3 x double], [3 x double]* %41, i64 0, i64 1
%43 = load double, double* %42
%44 = load [3 x double]*, [3 x double]** %5
%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
%47 = load double, double* %46
%48 = call double @atan2(double %43, double %47)
%49 = load double*, double** %8
store double %48, double* %49
br label %97
50: ; preds = %29
%51 = load [3 x double]*, [3 x double]** %5
%52 = getelementptr inbounds [3 x double], [3 x double]* %51, i64 1
%53 = getelementptr inbounds [3 x double], [3 x double]* %52, i64 0, i64 0
%54 = load double, double* %53
%55 = load [3 x double]*, [3 x double]** %5
%56 = getelementptr inbounds [3 x double], [3 x double]* %55, i64 0
%57 = getelementptr inbounds [3 x double], [3 x double]* %56, i64 0, i64 0
%58 = load double, double* %57
%59 = call double @atan2(double %54, double %58)
%60 = load double*, double** %6
store double %59, double* %60
%61 = load [3 x double]*, [3 x double]** %5
%62 = getelementptr inbounds [3 x double], [3 x double]* %61, i64 2
%63 = getelementptr inbounds [3 x double], [3 x double]* %62, i64 0, i64 0
%64 = load double, double* %63
%65 = fneg double %64
%66 = load [3 x double]*, [3 x double]** %5
%67 = getelementptr inbounds [3 x double], [3 x double]* %66, i64 0
%68 = getelementptr inbounds [3 x double], [3 x double]* %67, i64 0, i64 0
%69 = load double, double* %68
%70 = load [3 x double]*, [3 x double]** %5
%71 = getelementptr inbounds [3 x double], [3 x double]* %70, i64 0
%72 = getelementptr inbounds [3 x double], [3 x double]* %71, i64 0, i64 0
%73 = load double, double* %72
%74 = load [3 x double]*, [3 x double]** %5
%75 = getelementptr inbounds [3 x double], [3 x double]* %74, i64 1
%76 = getelementptr inbounds [3 x double], [3 x double]* %75, i64 0, i64 0
%77 = load double, double* %76
%78 = load [3 x double]*, [3 x double]** %5
%79 = getelementptr inbounds [3 x double], [3 x double]* %78, i64 1
%80 = getelementptr inbounds [3 x double], [3 x double]* %79, i64 0, i64 0
%81 = load double, double* %80
%82 = fmul double %77, %81
%83 = call double @llvm.fmuladd.f64(double %69, double %73, double %82)
%84 = call double @sqrt(double %83)
%85 = call double @atan2(double %65, double %84)
%86 = load double*, double** %7
store double %85, double* %86
%87 = load [3 x double]*, [3 x double]** %5
%88 = getelementptr inbounds [3 x double], [3 x double]* %87, i64 2
%89 = getelementptr inbounds [3 x double], [3 x double]* %88, i64 0, i64 1
%90 = load double, double* %89
%91 = load [3 x double]*, [3 x double]** %5
%92 = getelementptr inbounds [3 x double], [3 x double]* %91, i64 2
%93 = getelementptr inbounds [3 x double], [3 x double]* %92, i64 0, i64 2
%94 = load double, double* %93
%95 = call double @atan2(double %90, double %94)
%96 = load double*, double** %8
store double %95, double* %96
br label %97
97: ; preds = %50, %37
br label %98
98: ; preds = %97, %16
ret void
}

LLVM IR (-O2):
define void @RotToZYXEulerAngle([3 x double]* nocapture %0, double* nocapture writeonly %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 0
%6 = load double, double* %5
%7 = fadd double %6, 1.000000e+00
%8 = tail call double @llvm.fabs.f64(double %7)
%9 = fcmp olt double %8, 0x3EB0C6F7A0B5ED8D
br i1 %9, label %10, label %13
10: ; preds = %4
store double 0.000000e+00, double* %1
store double 0x3FF921FB54442D18, double* %2
%11 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 1
%12 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 1
br label %36
13: ; preds = %4
%14 = fsub double 1.000000e+00, %6
%15 = tail call double @llvm.fabs.f64(double %14)
%16 = fcmp olt double %15, 0x3EB0C6F7A0B5ED8D
br i1 %16, label %17, label %20
17: ; preds = %13
store double 0.000000e+00, double* %1
store double 0xBFF921FB54442D18, double* %2
%18 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 1
%19 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 1
br label %36
20: ; preds = %13
%21 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 0
%22 = load double, double* %21
%23 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 0
%24 = load double, double* %23
%25 = tail call double @atan2(double %22, double %24)
store double %25, double* %1
%26 = load double, double* %5
%27 = fneg double %26
%28 = load double, double* %23
%29 = load double, double* %21
%30 = fmul double %29, %29
%31 = tail call double @llvm.fmuladd.f64(double %28, double %28, double %30)
%32 = tail call double @sqrt(double %31)
%33 = tail call double @atan2(double %27, double %32)
store double %33, double* %2
%34 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 1
%35 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 2
br label %36
36: ; preds = %17, %20, %10
%37 = phi double* [ %19, %17 ], [ %35, %20 ], [ %12, %10 ]
%38 = phi double* [ %18, %17 ], [ %34, %20 ], [ %11, %10 ]
%39 = load double, double* %38
%40 = load double, double* %37
%41 = tail call double @atan2(double %39, double %40)
store double %41, double* %3
ret void
}