// File: /workspace/github_c_makefile_star2_O2/Alessandro-Barbieri[P]SpaceLib/src/SPACELIB.c
// Function: mtoscrew
int mtoscrew (MAT4 Q, AXIS u, real *phi, real *h, POINT P)
{
	real a,b,c,s,co,d,v,t,t1;
	int i,j;
	int x,y,z;

	a = (real) 0.5*(Q[Z][Y]-Q[Y][Z]);
	b = (real) 0.5*(Q[X][Z]-Q[Z][X]);
	c = (real) 0.5*(Q[Y][X]-Q[X][Y]);
	s = (real) sqrt(a*a+b*b+c*c);
	co = (Q[X][X]+Q[Y][Y]+Q[Z][Z]-1.)/2.;
	*phi = (real) atan2(s,co);

	co = (real) min(1.,max(-1.,co));
	v = (real) 1.-co;

	if (aabs(s)>0.1)                            /* normal case */
	{
		u[X] = a/s; u[Y] = b/s; u[Z] = c/s;
	}
	else if ((*phi!=0) && (co>0))                /* phi small */
	{
		t= ((real)1./v);
		u[X] = (real)sign(Q[Z][Y]-Q[Y][Z])* (real) sqrt(aabs((Q[X][X]-co)*t));
		u[Y] = (real)sign(Q[X][Z]-Q[Z][X])* (real) sqrt(aabs((Q[Y][Y]-co)*t));
		u[Z] = (real)sign(Q[Y][X]-Q[X][Y])* (real) sqrt(aabs((Q[Z][Z]-co)*t));
	}
	else if ((*phi!=0) && (co<0))                /* phi nearly PIG (3.14) */
	{
		t= ((real)1./v);
		u[X]=(real) sqrt(aabs((Q[X][X]-co)*t));
		u[Y]=(real) sqrt(aabs((Q[Y][Y]-co)*t));
		u[Z]=(real) sqrt(aabs((Q[Z][Z]-co)*t));
		if ((u[X]>=u[Y])&&(u[X]>=u[Z]))
			x=X;
		else if ((u[Y]>=u[X])&&(u[Y]>=u[Z]))
			x=Y;
		else
			x=Z;
		y=(x+1)%3; z=(x+2)%3;
		s=((Q[z][y]-Q[y][z])>=0 ? 1 : -1);
		u[x] *= s;
		u[y] *= (real) sign(Q[y][x]+Q[x][y])*s;
		u[z] *= (real) sign(Q[z][x]+Q[x][z])*s;
	}
	else                                        /* phi==0 */
	{
		d=(real)sqrt(Q[X][U]*Q[X][U]+Q[Y][U]*Q[Y][U]+Q[Z][U]*Q[Z][U]);
		if (d==0)
		{
			u[X] = u[Y] = u[Z]= (real) 0.;
		}
		else
		{
			u[X]=Q[X][U]/d; u[Y]=Q[Y][U]/d; u[Z]=Q[Z][U]/d;
		}
	}

	*h = u[X]*Q[X][U] + u[Y]*Q[Y][U] + u[Z]*Q[Z][U];

	P[U]= (real) 1.;
	if (v== (real) 0.)
	{
		P[X]=P[Y]=P[Z]=(real) 0.;
		if (d!=(real)0.)
			return(OK);
		else
			return(NOTOK);
	};
	t1 = (real).5/v;
	for(i=X;i<U;i++)
	{
		for(j=X,t=0;j<U;j++)
			t += -Q[j][i] * Q[j][U];
		P[i] = (t + Q[i][U])*t1;
	}
	return(OK);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movq %rdi, %r14
movsd 0x48(%rdi), %xmm1
movhpd 0x10(%rdi), %xmm1       # xmm1 = xmm1[0],mem[0]
movq %rcx, %r15
movsd 0x30(%rdi), %xmm0
movhpd 0x40(%rdi), %xmm0       # xmm0 = xmm0[0],mem[0]
movq %rdx, %r13
subpd %xmm0, %xmm1
mulpd 0x329c(%rip), %xmm1     # 0xa410
movq %rsi, %r12
movsd 0x20(%rdi), %xmm3
subsd 0x8(%rdi), %xmm3
movsd (%rdi), %xmm4
movsd 0x2f0b(%rip), %xmm2     # 0xa098
mulsd %xmm2, %xmm3
movapd %xmm1, %xmm0
mulpd %xmm1, %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm1, 0x30(%rsp)
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm3, 0x40(%rsp)
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
movapd %xmm4, %xmm1
addsd 0x28(%rdi), %xmm1
addsd 0x50(%rdi), %xmm1
sqrtsd %xmm0, %xmm0
movapd %xmm0, (%rsp)
addsd 0x306c(%rip), %xmm1     # 0xa248
mulsd %xmm2, %xmm1
movsd %xmm1, 0x10(%rsp)
callq 0x22c0
movapd (%rsp), %xmm3
movsd %xmm0, (%r13)
movsd 0x304a(%rip), %xmm1     # 0xa248
maxsd 0x10(%rsp), %xmm1
movsd 0x2e6c(%rip), %xmm4     # 0xa078
movapd %xmm4, %xmm5
minsd %xmm1, %xmm5
movapd %xmm4, %xmm7
subsd %xmm5, %xmm7
movapd 0x2ddc(%rip), %xmm1     # 0xa000
xorpd %xmm3, %xmm1
movapd %xmm3, %xmm2
maxsd %xmm1, %xmm2
ucomisd 0x31e8(%rip), %xmm2     # 0xa420
pushq $0x1
popq %rbp
jbe 0x7273
movsd 0x40(%rsp), %xmm1
divsd %xmm3, %xmm1
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
movapd 0x30(%rsp), %xmm0
divpd %xmm3, %xmm0
movupd %xmm0, (%r12)
movsd %xmm1, 0x10(%r12)
movsd 0x2e2e(%rip), %xmm2     # 0xa098
movapd %xmm1, %xmm0
jmp 0x7740
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x7283
jnp 0x730d
ucomisd %xmm1, %xmm5
jbe 0x730d
movsd (%r14), %xmm0
movsd 0x48(%r14), %xmm8
subsd 0x30(%r14), %xmm8
xorpd %xmm3, %xmm3
cmpltsd %xmm8, %xmm1
andpd %xmm4, %xmm1
divsd %xmm7, %xmm4
cmpltsd %xmm3, %xmm8
movapd %xmm8, %xmm2
andnpd %xmm1, %xmm2
movsd 0x2f81(%rip), %xmm6     # 0xa248
andpd %xmm6, %xmm8
orpd %xmm2, %xmm8
subsd %xmm5, %xmm0
mulsd %xmm4, %xmm0
movapd 0x2d1f(%rip), %xmm1     # 0xa000
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd %xmm3, %xmm0
movapd %xmm7, 0x10(%rsp)
movapd %xmm4, (%rsp)
movapd %xmm5, 0x20(%rsp)
jb 0x73b9
sqrtsd %xmm0, %xmm0
jmp 0x73e3
ucomisd %xmm1, %xmm0
jne 0x7315
jnp 0x7360
ucomisd %xmm5, %xmm1
jbe 0x7360
divsd %xmm7, %xmm4
movsd (%r14), %xmm0
subsd %xmm5, %xmm0
mulsd %xmm4, %xmm0
movapd 0x2ccc(%rip), %xmm2     # 0xa000
xorpd %xmm0, %xmm2
maxsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
movapd %xmm7, 0x10(%rsp)
movapd %xmm4, (%rsp)
movapd %xmm5, 0x20(%rsp)
jb 0x7522
sqrtsd %xmm0, %xmm0
jmp 0x7532
movsd 0x18(%r14), %xmm3
movsd 0x38(%r14), %xmm1
mulsd %xmm1, %xmm1
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x58(%r14), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x770c
jp 0x770c
xorpd %xmm1, %xmm1
movupd %xmm1, (%r12)
andq $0x0, 0x10(%r12)
xorl %ebp, %ebp
jmp 0x7738
movapd %xmm8, 0x30(%rsp)
callq 0x2430
movapd 0x30(%rsp), %xmm8
xorpd %xmm3, %xmm3
movsd 0x2e70(%rip), %xmm6     # 0xa248
movapd 0x20(%rsp), %xmm5
movapd (%rsp), %xmm4
mulsd %xmm8, %xmm0
movsd %xmm0, (%r12)
movsd 0x10(%r14), %xmm8
movsd 0x28(%r14), %xmm0
subsd 0x40(%r14), %xmm8
xorpd %xmm1, %xmm1
cmpltsd %xmm8, %xmm1
movsd 0x2c66(%rip), %xmm7     # 0xa078
andpd %xmm7, %xmm1
cmpltsd %xmm3, %xmm8
movapd %xmm8, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm6, %xmm8
orpd %xmm2, %xmm8
subsd %xmm5, %xmm0
mulsd %xmm4, %xmm0
movapd 0x2bc1(%rip), %xmm1     # 0xa000
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd %xmm3, %xmm0
jb 0x7453
sqrtsd %xmm0, %xmm0
jmp 0x7481
movapd %xmm8, 0x30(%rsp)
callq 0x2430
movapd 0x30(%rsp), %xmm8
movsd 0x2c0a(%rip), %xmm7     # 0xa078
movsd 0x2dd2(%rip), %xmm6     # 0xa248
movapd 0x20(%rsp), %xmm5
movapd (%rsp), %xmm4
mulsd %xmm8, %xmm0
movsd %xmm0, 0x8(%r12)
movsd 0x20(%r14), %xmm8
movsd 0x50(%r14), %xmm0
subsd 0x8(%r14), %xmm8
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm8, %xmm2
andpd %xmm7, %xmm2
cmpltsd %xmm1, %xmm8
movapd %xmm8, %xmm3
andnpd %xmm2, %xmm3
andpd %xmm6, %xmm8
orpd %xmm3, %xmm8
subsd %xmm5, %xmm0
mulsd %xmm0, %xmm4
movapd 0x2b26(%rip), %xmm0     # 0xa000
xorpd %xmm4, %xmm0
maxsd %xmm0, %xmm4
ucomisd %xmm1, %xmm4
jb 0x74ee
sqrtsd %xmm4, %xmm0
jmp 0x7503
movapd %xmm4, %xmm0
movapd %xmm8, (%rsp)
callq 0x2430
movapd (%rsp), %xmm8
movsd 0x2b8d(%rip), %xmm2     # 0xa098
movapd 0x10(%rsp), %xmm7
mulsd %xmm8, %xmm0
movsd %xmm0, 0x10(%r12)
jmp 0x7740
callq 0x2430
movapd 0x20(%rsp), %xmm5
movapd (%rsp), %xmm4
movsd %xmm0, (%r12)
movsd 0x28(%r14), %xmm0
subsd %xmm5, %xmm0
mulsd %xmm4, %xmm0
movapd 0x2ab2(%rip), %xmm1     # 0xa000
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x7566
sqrtsd %xmm0, %xmm0
jmp 0x757a
callq 0x2430
xorpd %xmm1, %xmm1
movapd 0x20(%rsp), %xmm5
movapd (%rsp), %xmm4
movsd %xmm0, 0x8(%r12)
movsd 0x50(%r14), %xmm0
subsd %xmm5, %xmm0
mulsd %xmm0, %xmm4
movapd 0x2a69(%rip), %xmm0     # 0xa000
xorpd %xmm4, %xmm0
maxsd %xmm0, %xmm4
ucomisd %xmm1, %xmm4
jb 0x75ab
sqrtsd %xmm4, %xmm0
jmp 0x75b4
movapd %xmm4, %xmm0
callq 0x2430
movapd 0x10(%rsp), %xmm7
movsd %xmm0, 0x10(%r12)
movsd (%r12), %xmm1
movsd 0x8(%r12), %xmm2
movapd %xmm0, %xmm3
cmplepd %xmm1, %xmm3
movapd %xmm2, %xmm4
cmplepd %xmm1, %xmm4
andpd %xmm3, %xmm4
movd %xmm4, %eax
cmpnlepd %xmm2, %xmm0
cmpnlepd %xmm2, %xmm1
orpd %xmm0, %xmm1
movq %xmm1, %rdx
pushq $0x1
popq %rbp
movl %ebp, %ecx
subl %edx, %ecx
andl $0x1, %edx
xorl %esi, %esi
testb $0x1, %al
cmovnel %esi, %ecx
pushq $0x2
popq %rax
cmoveq %rdx, %rax
leal 0x1(%rcx), %edi
cmpl $0x3, %edi
cmovel %esi, %edi
leal (,%rdi,8), %edx
movl %eax, %esi
shll $0x5, %esi
addq %r14, %rsi
movsd (%rdx,%rsi), %xmm2
shll $0x5, %edi
addq %r14, %rdi
shll $0x3, %eax
subsd (%rax,%rdi), %xmm2
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
cmplesd %xmm2, %xmm0
movsd 0x2a25(%rip), %xmm3     # 0xa078
movapd %xmm0, %xmm4
andpd %xmm3, %xmm4
movsd 0x2be5(%rip), %xmm2     # 0xa248
andnpd %xmm2, %xmm0
orpd %xmm4, %xmm0
leal (,%rcx,8), %r8d
movsd (%r12,%r8), %xmm4
mulsd %xmm0, %xmm4
movsd %xmm4, (%r12,%r8)
movsd (%r8,%rdi), %xmm4
shll $0x5, %ecx
addq %r14, %rcx
addsd (%rdx,%rcx), %xmm4
xorpd %xmm5, %xmm5
cmpltsd %xmm4, %xmm5
andpd %xmm3, %xmm5
cmpltsd %xmm1, %xmm4
movapd %xmm4, %xmm6
andnpd %xmm5, %xmm6
andpd %xmm2, %xmm4
orpd %xmm6, %xmm4
mulsd %xmm0, %xmm4
mulsd (%r12,%rdx), %xmm4
movsd %xmm4, (%r12,%rdx)
movsd (%r8,%rsi), %xmm4
addsd (%rax,%rcx), %xmm4
xorpd %xmm5, %xmm5
cmpltsd %xmm4, %xmm5
andpd %xmm3, %xmm5
cmpltsd %xmm1, %xmm4
movapd %xmm4, %xmm1
andnpd %xmm5, %xmm1
andpd %xmm2, %xmm4
orpd %xmm1, %xmm4
mulsd %xmm0, %xmm4
mulsd (%r12,%rax), %xmm4
movsd %xmm4, (%r12,%rax)
movsd 0x10(%r12), %xmm0
jmp 0x7738
divsd %xmm1, %xmm3
movsd %xmm3, (%r12)
movsd 0x38(%r14), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%r12)
movsd 0x58(%r14), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%r12)
movsd 0x2958(%rip), %xmm2     # 0xa098
movsd (%r12), %xmm3
movsd 0x8(%r12), %xmm1
mulsd 0x38(%r14), %xmm1
mulsd 0x18(%r14), %xmm3
mulsd 0x58(%r14), %xmm0
addsd %xmm1, %xmm3
addsd %xmm3, %xmm0
movsd %xmm0, (%r15)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x18(%rbx)
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm7
jne 0x77a4
jp 0x77a4
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
divsd %xmm7, %xmm2
xorl %eax, %eax
pushq $0x1
popq %rbp
movq %r14, %rcx
cmpq $0x3, %rax
je 0x7793
xorpd %xmm0, %xmm0
xorl %edx, %edx
cmpq $0x60, %rdx
je 0x77d8
movsd (%rcx,%rdx), %xmm1
mulsd 0x18(%r14,%rdx), %xmm1
subsd %xmm1, %xmm0
addq $0x20, %rdx
jmp 0x77bc
movq %rax, %rdx
shlq $0x5, %rdx
addsd 0x18(%r14,%rdx), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
addq $0x8, %rcx
jmp 0x77b0