// File: /workspace/github_c_makefile_star2_O3/Alessandro-Barbieri[P]SpaceLib/src/SPACELI4.c
// Function: intersection
void intersection(LINE l1, LINE l2, LINEP lmindist, real * mindist, PLANE pl,
		  POINT I, int *inttype)
{
	VECTOR deltap,v1,v2,u3;
	POINT A,B;
	real a,c1,c2,alpha,beta,zero;

	zero = zerom();          /* machine zero */
	vect(l2.P,l1.P,deltap);  /* deltap=(P2-P1) */
	cross(l1.dir,l2.dir,u3); /* u3 is orthogonal to l1 and l2 */

				 /* l1 and l2 are not parallel */
	if (aabs(u3[X]) > zero || aabs(u3[Y]) > zero || aabs(u3[Z]) > zero)
	{
		c1 = dot(l1.dir,deltap); /* c1=U1t*(P2-P1) */
		c2 = dot(l2.dir,deltap); /* c2=U2t*(P2-P1) */
		a = dot(l1.dir,l2.dir);  /* a=U1t*U2 */
		alpha = (real) ( (a*c2-c1) / (pow(a,2)-1) );
		beta = (real) ( (c2-a*c1) / (pow(a,2)-1) );
		vector(l1.dir,alpha,v1); /* builds vector l1.P->A */
		vector(l2.dir,beta,v2);  /* builds vector l2.P->B */
		sumv(l1.P,v1,A);         /* point A in the reference frame */
		sumv(l2.P,v2,B);         /* point B in the reference frame */
		A[U]=B[U]=1;
		*mindist = dist(A,B);    /* minimum distance between l1, l2 */
		middle(A,B,I);           /* middle point between A and B */
		pcopy(I,lmindist->P);    /* origin of minimum distance line */
		vcopy(u3,lmindist->dir); /* u3 is the dir. of this line */
		unitv(lmindist->dir,lmindist->dir);
		plane2(I,u3,pl);         /* builds the minimum distance pl. */
		if ( (*mindist) > zero ) /* l1 and l2 are oblique lines */
			*inttype=1;      /* intersection is middle point */
		else			 /* l1 and l2 are incident lines */
		{
			*mindist=0.;
			*inttype=0;      /* I is the real intersection */
		}
	}
	else                              /* l1 is parallel to l2 */
	{
		cross(deltap,l1.dir,v1);
		*mindist = mod(v1);	  /* min. dist. between l1, l2 */
		if ( (*mindist) < zero)   /* l1==l2 */
			*inttype = -1;
		else 			  /* l1!=l2 */
		{
			*inttype = 2; 	  /* no intersection between l1, l2 */
			cross(deltap,l1.dir,v1); /* dir. of min. dist. line */
			cross(v1,l1.dir,v2);
			unitv(v2,lmindist->dir);
			pcopy(l1.P,lmindist->P);
			plane2(l1.P,v1,pl); 	 /* pl. containing l1, l2 */
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, %r13
movq %rdx, 0x20(%rsp)
movq %rsi, %r12
movq %rdi, %r15
leaq 0x168(%rsp), %r14
leaq 0x130(%rsp), %rbx
callq 0x2360
movsd %xmm0, 0x8(%rsp)
leaq 0x50(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2430
leaq 0x150(%rsp), %r14
leaq 0x188(%rsp), %rbp
leaq 0x30(%rsp), %rbx
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2390
movsd (%rbx), %xmm0
movapd 0x3be1(%rip), %xmm1     # 0xa020
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd 0x8(%rsp), %xmm0
ja 0x648f
movsd 0x38(%rsp), %xmm0
movapd 0x3bc3(%rip), %xmm1     # 0xa020
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd 0x8(%rsp), %xmm0
ja 0x648f
movsd 0x40(%rsp), %xmm0
movapd 0x3ba5(%rip), %xmm1     # 0xa020
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd 0x8(%rsp), %xmm0
jbe 0x664d
leaq 0x50(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2030
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2030
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2030
movapd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm3
mulsd %xmm3, %xmm1
movsd 0x28(%rsp), %xmm4
subsd %xmm4, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd 0x3daf(%rip), %xmm2     # 0xa298
divsd %xmm2, %xmm1
mulsd %xmm4, %xmm0
subsd %xmm0, %xmm3
divsd %xmm2, %xmm3
movsd %xmm3, 0x18(%rsp)
leaq 0x70(%rsp), %rbx
movq %r14, %rdi
movapd %xmm1, %xmm0
movq %rbx, %rsi
callq 0x2220
leaq 0x90(%rsp), %r14
movq %rbp, %rdi
movsd 0x18(%rsp), %xmm0
movq %r14, %rsi
callq 0x2220
leaq 0xd0(%rsp), %rbp
leaq 0x130(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movl $0x3, %ecx
movl $0x1, %r8d
callq 0x2210
leaq 0xb0(%rsp), %rbx
leaq 0x168(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x3, %ecx
movl $0x1, %r8d
callq 0x2210
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x18(%rbx)
movq %rax, 0x18(%rbp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2280
movsd %xmm0, (%r12)
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x23f0
movq %r13, %rdi
movq %r15, %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x22a0
addq $0x20, %r15
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x3, %edx
movl $0x1, %ecx
callq 0x22a0
movq %r15, %rdi
movq %r15, %rsi
callq 0x2110
movq %rbx, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x2110
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2030
xorps 0x3a17(%rip), %xmm0     # 0xa020
movlps %xmm0, 0x18(%rbx)
movsd (%r12), %xmm0
ucomisd 0x8(%rsp), %xmm0
jbe 0x6628
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
jmp 0x663b
movq $0x0, (%r12)
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rbx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2390
movq %rbx, %rdi
callq 0x2060
movsd %xmm0, (%r12)
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x6689
movq 0x10(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0x663b
movq 0x10(%rsp), %rax
movl $0x2, (%rax)
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rbx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2390
leaq 0x90(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2390
leaq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x2110
leaq 0x130(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x22a0
movq %rbx, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x2110
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2030
xorpd 0x3915(%rip), %xmm0     # 0xa020
movlpd %xmm0, 0x18(%rbx)
jmp 0x663b