// File: istellartech[P]OpenTsiolkovsky/src/../lib/Eigen/src/Geometry/EulerAngles.h
// Function: Eigen::MatrixBase<Eigen::Transpose<Eigen::Matrix<double, 3, 3, 0, 3, 3>>>::eulerAngles(long, long, long) const
inline Matrix<typename MatrixBase<Derived>::Scalar,3,1>
MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
{
  using std::atan2;
  using std::sin;
  using std::cos;
  /* Implemented from Graphics Gems IV */
  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3)

  Matrix<Scalar,3,1> res;
  typedef Matrix<typename Derived::Scalar,2,1> Vector2;

  const Index odd = ((a0+1)%3 == a1) ? 0 : 1;
  const Index i = a0;
  const Index j = (a0 + 1 + odd)%3;
  const Index k = (a0 + 2 - odd)%3;
  
  if (a0==a2)
  {
    res[0] = atan2(coeff(j,i), coeff(k,i));
    if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0)))
    {
      res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI);
      Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
      res[1] = -atan2(s2, coeff(i,i));
    }
    else
    {
      Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm();
      res[1] = atan2(s2, coeff(i,i));
    }
    
    // With a=(0,1,0), we have i=0; j=1; k=2, and after computing the first two angles,
    // we can compute their respective rotation, and apply its inverse to M. Since the result must
    // be a rotation around x, we have:
    //
    //  c2  s1.s2 c1.s2                   1  0   0 
    //  0   c1    -s1       *    M    =   0  c3  s3
    //  -s2 s1.c2 c1.c2                   0 -s3  c3
    //
    //  Thus:  m11.c1 - m21.s1 = c3  &   m12.c1 - m22.s1 = s3
    
    Scalar s1 = sin(res[0]);
    Scalar c1 = cos(res[0]);
    res[2] = atan2(c1*coeff(j,k)-s1*coeff(k,k), c1*coeff(j,j) - s1 * coeff(k,j));
  } 
  else
  {
    res[0] = atan2(coeff(j,k), coeff(k,k));
    Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm();
    if((odd && res[0]<Scalar(0)) || ((!odd) && res[0]>Scalar(0))) {
      res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI);
      res[1] = atan2(-coeff(i,k), -c2);
    }
    else
      res[1] = atan2(-coeff(i,k), c2);
    Scalar s1 = sin(res[0]);
    Scalar c1 = cos(res[0]);
    res[2] = atan2(s1*coeff(k,i)-c1*coeff(j,i), c1*coeff(j,j) - s1 * coeff(k,j));
  }
  if (!odd)
    res = -res;
  
  return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0xe8(%rbp)
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
callq 0x1d670
movq -0x18(%rbp), %rax
addq $0x1, %rax
movl $0x3, %ecx
cqto
idivq %rcx
movq -0x20(%rbp), %rsi
movl $0x1, %eax
xorl %ecx, %ecx
cmpq %rsi, %rdx
cmovel %ecx, %eax
cltq
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
addq -0x30(%rbp), %rax
movl $0x3, %ecx
cqto
idivq %rcx
movq %rdx, -0x40(%rbp)
movq -0x18(%rbp), %rax
addq $0x2, %rax
subq -0x30(%rbp), %rax
movl $0x3, %ecx
cqto
idivq %rcx
movq %rdx, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x4dcf8
movq -0xd8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xf8(%rbp)
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movsd -0xf8(%rbp), %xmm0
movsd (%rax), %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0xf0(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x4d92c
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
ja 0x4d958
cmpq $0x0, -0x30(%rbp)
jne 0x4dab2
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4dab2
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4d99f
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
movsd 0x54a7(%rip), %xmm1     # 0x52e38
subsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0x4d9c3
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd 0x5481(%rip), %xmm0     # 0x52e38
addsd (%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
movq -0xe8(%rbp), %rdi
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd -0x120(%rbp), %xmm0
movq -0xd8(%rbp), %rdi
movsd %xmm0, (%rax)
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movq %rax, -0x118(%rbp)
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movq -0x118(%rbp), %rsi
movq %rax, %rdx
leaq -0x60(%rbp), %rdi
callq 0x4ed30
leaq -0x60(%rbp), %rdi
callq 0x4ed80
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x110(%rbp)
movq -0x38(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movsd -0x110(%rbp), %xmm0
movsd (%rax), %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x108(%rbp)
movl $0x1, %esi
callq 0x1de40
movsd -0x108(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x4db59
movq -0xd8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movq %rax, -0x138(%rbp)
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movq -0x138(%rbp), %rsi
movq %rax, %rdx
leaq -0x80(%rbp), %rdi
callq 0x4ed30
leaq -0x80(%rbp), %rdi
callq 0x4ed80
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movq -0x38(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movsd -0x130(%rbp), %xmm0
movsd (%rax), %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x128(%rbp)
movl $0x1, %esi
callq 0x1de40
movsd -0x128(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
callq 0x6120
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x88(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
callq 0x6810
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x178(%rbp)
movq -0x48(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4ecf0
movsd -0x178(%rbp), %xmm1
movsd -0x170(%rbp), %xmm0
movsd -0x168(%rbp), %xmm2
movq -0xd8(%rbp), %rdi
mulsd (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x148(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x158(%rbp)
movq -0x40(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x150(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4ecf0
movsd -0x160(%rbp), %xmm2
movsd -0x158(%rbp), %xmm1
movsd -0x150(%rbp), %xmm3
movsd -0x148(%rbp), %xmm0
mulsd (%rax), %xmm2
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x140(%rbp)
movl $0x2, %esi
callq 0x1de40
movsd -0x140(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x4e112
movq -0xd8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
movq -0x48(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4ecf0
movsd -0x190(%rbp), %xmm0
movsd (%rax), %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x188(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd -0x188(%rbp), %xmm0
movq -0xd8(%rbp), %rdi
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movq %rax, -0x180(%rbp)
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4ecf0
movq -0x180(%rbp), %rsi
movq %rax, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x4ed30
leaq -0xb0(%rbp), %rdi
callq 0x4ed80
movsd %xmm0, -0x98(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4ddda
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
ja 0x4de06
cmpq $0x0, -0x30(%rbp)
jne 0x4df17
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4df17
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4de4d
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
movsd 0x4ff9(%rip), %xmm1     # 0x52e38
subsd %xmm1, %xmm0
movsd %xmm0, -0x198(%rbp)
jmp 0x4de71
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd 0x4fd3(%rip), %xmm0     # 0x52e38
addsd (%rax), %xmm0
movsd %xmm0, -0x198(%rbp)
movq -0xe8(%rbp), %rdi
movsd -0x198(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd -0x1a8(%rbp), %xmm0
movq -0xd8(%rbp), %rdi
movsd %xmm0, (%rax)
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4ecf0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd -0x98(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x1a0(%rbp)
movl $0x1, %esi
callq 0x1de40
movsd -0x1a0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x4df78
movq -0xd8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4ecf0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd -0x98(%rbp), %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x1b0(%rbp)
movl $0x1, %esi
callq 0x1de40
movsd -0x1b0(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
callq 0x6120
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0xb8(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
callq 0x6810
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0xc0(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x1e8(%rbp)
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1e0(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0x1f0(%rbp)
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4ecf0
movsd -0x1f0(%rbp), %xmm1
movsd -0x1e8(%rbp), %xmm0
movsd -0x1e0(%rbp), %xmm2
movq -0xd8(%rbp), %rdi
mulsd (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1c0(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0x1d0(%rbp)
movq -0x40(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4ecf0
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1c8(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x1d8(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4ecf0
movsd -0x1d8(%rbp), %xmm2
movsd -0x1d0(%rbp), %xmm1
movsd -0x1c8(%rbp), %xmm3
movsd -0x1c0(%rbp), %xmm0
mulsd (%rax), %xmm2
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
callq 0x60c0
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x1b8(%rbp)
movl $0x2, %esi
callq 0x1de40
movsd -0x1b8(%rbp), %xmm0
movsd %xmm0, (%rax)
cmpq $0x0, -0x30(%rbp)
jne 0x4e13f
movq -0xe8(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x4eda0
movq -0xe8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x4edf0
movq -0xe0(%rbp), %rax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
nop