// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlbsp/tjunc.cpp
// Function: FindEdge(double const*, double const*, double*, double*)
static wedge_t *FindEdge(const vec3_t p1, const vec3_t p2, vec_t* t1, vec_t* t2)
{
    vec3_t          origin;
    vec3_t          dir;
    wedge_t*        w;
    vec_t           temp;
    int             h;
#ifdef HLBSP_HASH_FIX
	int				num_hashneighbors;
	int				hashneighbors[MAX_HASH_NEIGHBORS];
#endif

    VectorSubtract(p2, p1, dir);
    if (!CanonicalVector(dir))
    {
#if _DEBUG
        Warning("CanonicalVector: degenerate @ (%4.3f %4.3f %4.3f )\n", p1[0], p1[1], p1[2]);
#endif
    }

    *t1 = DotProduct(p1, dir);
    *t2 = DotProduct(p2, dir);

    VectorMA(p1, -*t1, dir, origin);

    if (*t1 > *t2)
    {
        temp = *t1;
        *t1 = *t2;
        *t2 = temp;
    }

#ifdef HLBSP_HASH_FIX
	h = HashVec(origin, &num_hashneighbors, hashneighbors);
#else
    h = HashVec(origin);
#endif

#ifdef HLBSP_HASH_FIX
  for (int i = 0; i < num_hashneighbors; ++i)
	for (w = wedge_hash[hashneighbors[i]]; w; w = w->next)
#else
    for (w = wedge_hash[h]; w; w = w->next)
#endif
    {
#ifdef HLBSP_TJUNC_PRECISION_FIX
		if (fabs (w->origin[0] - origin[0]) > EQUAL_EPSILON ||
			fabs (w->origin[1] - origin[1]) > EQUAL_EPSILON ||
			fabs (w->origin[2] - origin[2]) > EQUAL_EPSILON )
		{
			continue;
		}
		if (fabs (w->dir[0] - dir[0]) > NORMAL_EPSILON ||
			fabs (w->dir[1] - dir[1]) > NORMAL_EPSILON ||
			fabs (w->dir[2] - dir[2]) > NORMAL_EPSILON )
		{
			continue;
		}
#else
        temp = w->origin[0] - origin[0];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->origin[1] - origin[1];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->origin[2] - origin[2];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }

        temp = w->dir[0] - dir[0];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->dir[1] - dir[1];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
        temp = w->dir[2] - dir[2];
        if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON)
        {
            continue;
        }
#endif

        return w;
    }

    hlassume(numwedges < MAX_WEDGES, assume_MAX_WEDGES);
    w = &wedges[numwedges];
    numwedges++;

    w->next = wedge_hash[h];
    wedge_hash[h] = w;

    VectorCopy(origin, w->origin);
    VectorCopy(dir, w->dir);
    w->head.next = w->head.prev = &w->head;
    w->head.t = 99999;
    return w;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movupd (%rsi), %xmm3
movupd (%rdi), %xmm0
subpd %xmm0, %xmm3
movsd 0x10(%rsi), %xmm2
movsd 0x10(%rdi), %xmm1
subsd %xmm1, %xmm2
movapd %xmm3, %xmm4
mulpd %xmm3, %xmm4
unpckhpd %xmm4, %xmm4            # xmm4 = xmm4[1,1]
movapd %xmm3, %xmm5
mulsd %xmm3, %xmm5
addsd %xmm4, %xmm5
movapd %xmm2, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm5, %xmm4
sqrtsd %xmm4, %xmm4
xorpd %xmm7, %xmm7
xorpd %xmm6, %xmm6
movsd 0x1f6a(%rip), %xmm5     # 0x1d118
ucomisd %xmm4, %xmm5
ja 0x1b21b
divsd %xmm4, %xmm2
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
divpd %xmm4, %xmm3
ucomisd 0x1f50(%rip), %xmm3     # 0x1d118
jbe 0x1b1d4
movapd %xmm2, %xmm6
movapd %xmm3, %xmm7
jmp 0x1b21b
movsd 0x7b0c(%rip), %xmm4     # 0x22ce8
ucomisd %xmm3, %xmm4
jbe 0x1b1fc
leaq 0x3be7(%rip), %rax      # 0x1edd0
movapd (%rax), %xmm7
subpd %xmm3, %xmm7
movsd 0x10(%rax), %xmm6
subsd %xmm2, %xmm6
jmp 0x1b21b
movapd %xmm3, %xmm5
unpckhpd %xmm3, %xmm5            # xmm5 = xmm5[1],xmm3[1]
ucomisd 0x1f0c(%rip), %xmm5     # 0x1d118
jbe 0x1b663
shufpd $0x2, %xmm3, %xmm7      # xmm7 = xmm7[0],xmm3[1]
movapd %xmm2, %xmm6
movapd %xmm7, %xmm3
unpckhpd %xmm7, %xmm3            # xmm3 = xmm3[1],xmm7[1]
movapd %xmm0, %xmm2
mulpd %xmm7, %xmm2
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
mulsd %xmm7, %xmm0
addsd %xmm2, %xmm0
mulsd %xmm6, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdx)
movsd 0x8(%rsi), %xmm0
movapd %xmm3, 0x80(%rsp)
mulsd %xmm3, %xmm0
movsd (%rsi), %xmm1
mulsd %xmm7, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rsi), %xmm0
mulsd %xmm6, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rcx)
movsd (%rdx), %xmm1
movupd (%rdi), %xmm3
movapd %xmm1, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movapd %xmm7, 0x60(%rsp)
mulpd %xmm7, %xmm2
subpd %xmm2, %xmm3
movsd 0x10(%rdi), %xmm4
movapd %xmm1, %xmm2
movsd %xmm6, 0x28(%rsp)
mulsd %xmm6, %xmm2
ucomisd %xmm0, %xmm1
jbe 0x1b2b1
movsd %xmm0, (%rdx)
movsd %xmm1, (%rcx)
subsd %xmm2, %xmm4
movsd %xmm4, 0x20(%rsp)
movapd %xmm3, %xmm8
unpckhpd %xmm3, %xmm8            # xmm8 = xmm8[1],xmm3[1]
leaq 0x1c(%rsp), %r13
leaq 0x40(%rsp), %r14
movb $0x1, %bl
xorl %r15d, %r15d
leaq 0x18(%rsp), %rbp
leaq 0x48(%rsp), %r12
movapd %xmm3, 0x50(%rsp)
movapd %xmm8, 0x70(%rsp)
leaq 0x3a307be(%rip), %rax   # 0x3a4bab0
subsd (%rax,%r15,8), %xmm3
leaq 0x3a307e1(%rip), %rax   # 0x3a4bae0
mulsd (%rax,%r15,8), %xmm3
movapd %xmm3, %xmm0
movsd %xmm3, 0x8(%rsp)
callq 0x4530
movapd 0x70(%rsp), %xmm8
cvttsd2si %xmm0, %eax
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%r14)
leaq 0x3a3078b(%rip), %rcx   # 0x3a4bac8
movl (%rcx,%r15,4), %ecx
addl %ecx, %eax
cltd
idivl %ecx
leal (%rdx,%rcx), %eax
cltd
idivl %ecx
movl %edx, (%r13)
movl $0x1, %r15d
movapd %xmm8, %xmm3
movq %r12, %r14
movq %rbp, %r13
testb $0x1, %bl
movl $0x0, %ebx
jne 0x1b2eb
movl 0x1c(%rsp), %eax
movq %rax, 0x38(%rsp)
movl 0x3a30752(%rip), %eax   # 0x3a4bacc
movl 0x18(%rsp), %r15d
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x78cf(%rip), %rbx      # 0x22c73
xorl %r12d, %r12d
movl %eax, 0x14(%rsp)
movl %eax, %esi
xorl %edi, %edi
cmpl $0x1, %r13d
je 0x1b3dc
cmpl $-0x1, %r13d
jne 0x1b400
movsd 0x3a3071d(%rip), %xmm0  # 0x3a4bae0
mulsd 0x608d(%rip), %xmm0     # 0x21458
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1b400
jmp 0x1b4b2
movsd 0x3a306fc(%rip), %xmm0  # 0x3a4bae0
mulsd 0x7904(%rip), %xmm0     # 0x22cf0
addsd 0x4cd4(%rip), %xmm0     # 0x200c8
ucomisd 0x30(%rsp), %xmm0
ja 0x1b4bf
movq 0x38(%rsp), %rax
leal (%rax,%r13), %ebp
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x1, %r14d
je 0x1b439
cmpl $-0x1, %r14d
jne 0x1b459
movsd 0x3a306c5(%rip), %xmm0  # 0x3a4bae8
mulsd 0x602d(%rip), %xmm0     # 0x21458
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1b459
jmp 0x1b4a5
movsd 0x3a306a7(%rip), %xmm0  # 0x3a4bae8
mulsd 0x78a7(%rip), %xmm0     # 0x22cf0
addsd 0x4c77(%rip), %xmm0     # 0x200c8
ucomisd 0x8(%rsp), %xmm0
ja 0x1b4b2
cmpl $0x4, %edi
jl 0x1b478
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9e9c
movapd 0x70(%rsp), %xmm8
movl 0x3a30657(%rip), %esi   # 0x3a4bacc
movl %r12d, %edi
movl 0x3a3064a(%rip), %ecx   # 0x3a4bac8
leal (%rcx,%rbp), %eax
cltd
idivl %ecx
movl %edx, %ecx
imull %esi, %ecx
leal (%r15,%rsi), %eax
addl %r14d, %eax
cltd
idivl %esi
addl %ecx, %edx
movslq %edi, %rax
movl %edx, 0x90(%rsp,%rax,4)
incl %r12d
movl %r12d, %edi
incl %r14d
cmpl $0x2, %r14d
jne 0x1b40f
incl %r13d
cmpl $0x2, %r13d
jne 0x1b3af
testl %r12d, %r12d
movsd 0x28(%rsp), %xmm3
movapd 0x60(%rsp), %xmm4
movapd 0x80(%rsp), %xmm5
movapd 0x50(%rsp), %xmm6
movsd 0x20(%rsp), %xmm7
jle 0x1b5b1
movl %r12d, %ecx
xorl %edx, %edx
leaq 0x3a285ab(%rip), %rsi   # 0x3a43aa0
movapd 0x4dc3(%rip), %xmm0     # 0x202c0
movsd 0x77f3(%rip), %xmm1     # 0x22cf8
movslq 0x90(%rsp,%rdx,4), %rax
movq (%rsi,%rax,8), %rax
testq %rax, %rax
je 0x1b5a5
movsd 0x20(%rax), %xmm2
subsd %xmm6, %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x1b59d
movsd 0x28(%rax), %xmm2
subsd %xmm8, %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x1b59d
movsd 0x30(%rax), %xmm2
subsd %xmm7, %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x1b59d
movsd 0x8(%rax), %xmm2
subsd %xmm4, %xmm2
andpd %xmm0, %xmm2
ucomisd 0x1baf(%rip), %xmm2     # 0x1d118
ja 0x1b59d
movsd 0x10(%rax), %xmm2
subsd %xmm5, %xmm2
andpd %xmm0, %xmm2
ucomisd 0x1b98(%rip), %xmm2     # 0x1d118
ja 0x1b59d
movsd 0x18(%rax), %xmm2
subsd %xmm3, %xmm2
andpd %xmm0, %xmm2
ucomisd 0x1b81(%rip), %xmm2     # 0x1d118
jbe 0x1b651
movq (%rax), %rax
jmp 0x1b511
incq %rdx
cmpq %rcx, %rdx
jne 0x1b505
movl 0x14(%rsp), %ebx
imull 0x38(%rsp), %ebx
addl %r15d, %ebx
xorl %edi, %edi
cmpl $0x20000, 0x3a304db(%rip) # imm = 0x20000
setl %dil
movl $0x13, %esi
callq 0xa655
movslq 0x3a304c6(%rip), %rcx   # 0x3a4baa4
leaq (%rcx,%rcx,4), %rdx
shlq $0x4, %rdx
leaq 0x3a30513(%rip), %rsi   # 0x3a4bb00
leaq (%rsi,%rdx), %rax
incl %ecx
movl %ecx, 0x3a304ab(%rip)   # 0x3a4baa4
movslq %ebx, %rcx
leaq 0x3a2849d(%rip), %rdi   # 0x3a43aa0
movq (%rdi,%rcx,8), %r8
leaq 0x38(%rdx,%rsi), %rdx
movq %r8, -0x38(%rdx)
movq %rax, (%rdi,%rcx,8)
movaps 0x50(%rsp), %xmm0
movaps %xmm0, -0x18(%rdx)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, -0x8(%rdx)
movaps 0x60(%rsp), %xmm0
movups %xmm0, -0x30(%rdx)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, -0x20(%rdx)
movq %rdx, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movabsq $0x40f869f000000000, %rcx # imm = 0x40F869F000000000
movq %rcx, (%rdx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd %xmm5, %xmm4
jbe 0x1b686
leaq 0x3760(%rip), %rax      # 0x1edd0
movapd (%rax), %xmm7
movsd 0x8(%rax), %xmm3
subsd %xmm5, %xmm3
unpcklpd %xmm3, %xmm7            # xmm7 = xmm7[0],xmm3[0]
jmp 0x1b1f1
ucomisd 0x1a8a(%rip), %xmm2     # 0x1d118
ja 0x1b217
ucomisd %xmm2, %xmm4
jbe 0x1b21b
leaq 0x372b(%rip), %rax      # 0x1edd0
movapd (%rax), %xmm7
jmp 0x1b1f1