// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rcx, 0x28(%rsp)
movq %rdx, %r12
movq %rsi, 0x20(%rsp)
movq %rdi, %r14
leaq 0x168(%rsp), %r15
leaq 0x130(%rsp), %rbx
callq 0x23a0
movsd %xmm0, (%rsp)
leaq 0x50(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2480
leaq 0x150(%rsp), %rbp
leaq 0x188(%rsp), %r15
leaq 0x30(%rsp), %rbx
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x23e0
movsd (%rbx), %xmm0
movapd 0x41b3(%rip), %xmm1     # 0xa000
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd (%rsp), %xmm0
ja 0x5e9a
movsd 0x38(%rsp), %xmm0
movapd 0x4196(%rip), %xmm1     # 0xa000
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd (%rsp), %xmm0
ja 0x5e9a
movsd 0x40(%rsp), %xmm0
movapd 0x4179(%rip), %xmm1     # 0xa000
xorpd %xmm0, %xmm1
maxsd %xmm1, %xmm0
ucomisd (%rsp), %xmm0
jbe 0x6041
movq %r13, 0x18(%rsp)
leaq 0x50(%rsp), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2030
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2030
movsd %xmm0, 0x10(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2030
movapd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm3
mulsd %xmm3, %xmm1
movsd 0x8(%rsp), %xmm4
subsd %xmm4, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd 0x434f(%rip), %xmm2     # 0xa248
divsd %xmm2, %xmm1
mulsd %xmm4, %xmm0
subsd %xmm0, %xmm3
divsd %xmm2, %xmm3
movsd %xmm3, 0x10(%rsp)
leaq 0x70(%rsp), %rbx
movq %rbp, %rdi
movapd %xmm1, %xmm0
movq %rbx, %rsi
callq 0x2230
movq %r12, 0x8(%rsp)
leaq 0x90(%rsp), %r12
movq %r15, %rdi
movsd 0x10(%rsp), %xmm0
movq %r12, %rsi
callq 0x2230
leaq 0xd0(%rsp), %r13
pushq $0x3
popq %rbp
pushq $0x1
popq %r15
leaq 0x130(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl %ebp, %ecx
movl %r15d, %r8d
callq 0x2220
leaq 0xb0(%rsp), %rbx
leaq 0x168(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movl %r15d, %r8d
callq 0x2220
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x18(%rbx)
movq %rax, 0x18(%r13)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2290
movq 0x20(%rsp), %r12
movsd %xmm0, (%r12)
movq %r13, %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %r13
movq %r13, %rdx
callq 0x2440
pushq $0x4
popq %rdx
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %ecx
callq 0x22b0
addq $0x20, %r14
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x22b0
movq %r14, %rdi
movq %r14, %rsi
callq 0x2110
movq %r13, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
callq 0x2310
movsd (%r12), %xmm0
ucomisd (%rsp), %xmm0
jbe 0x6022
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
jmp 0x602f
andq $0x0, (%r12)
movq 0x18(%rsp), %rax
andl $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 %rbp, %rsi
movq %rbx, %rdx
callq 0x23e0
movq %rbx, %rdi
callq 0x2060
movq 0x20(%rsp), %rax
movsd %xmm0, (%rax)
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x6079
orl $-0x1, (%r13)
jmp 0x602f
movl $0x2, (%r13)
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rbx
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x23e0
leaq 0x90(%rsp), %r15
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x23e0
leaq 0x20(%r14), %rsi
movq %r15, %rdi
callq 0x2110
pushq $0x4
popq %rdx
pushq $0x1
popq %rcx
leaq 0x130(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x22b0
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2310
jmp 0x602f