// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rcx, %rbx
movq %rsi, %r12
movq %rdi, %r15
movsd 0x10(%rsi), %xmm5
subsd 0x10(%rdi), %xmm5
movq %rdx, %r14
movupd (%rsi), %xmm4
movupd (%rdi), %xmm0
subpd %xmm0, %xmm4
movapd %xmm4, %xmm0
mulpd %xmm4, %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm4, %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movapd %xmm5, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jb 0x1b5e2
sqrtsd %xmm0, %xmm0
jmp 0x1b601
movapd %xmm4, 0x10(%rsp)
movsd %xmm5, (%rsp)
callq 0x4240
movsd (%rsp), %xmm5
movapd 0x10(%rsp), %xmm4
xorpd %xmm2, %xmm2
movsd 0x2b07(%rip), %xmm1     # 0x1e110
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
divpd %xmm1, %xmm4
movd %eax, %xmm1
pshufd $0x0, %xmm1, %xmm3      # xmm3 = xmm1[0,0,0,0]
pslld $0x1f, %xmm3
psrad $0x1f, %xmm3
ja 0x1b63b
divsd %xmm0, %xmm5
movapd %xmm5, %xmm2
pandn %xmm4, %xmm3
ja 0x1b695
ucomisd 0x2ac7(%rip), %xmm3     # 0x1e110
ja 0x1b695
movsd 0x86c5(%rip), %xmm0     # 0x23d18
ucomisd %xmm3, %xmm0
jbe 0x1b677
leaq 0x4780(%rip), %rax      # 0x1fde0
movapd (%rax), %xmm0
subpd %xmm3, %xmm0
movsd 0x10(%rax), %xmm4
subsd %xmm2, %xmm4
movapd %xmm0, %xmm3
jmp 0x1b699
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
ucomisd 0x2a89(%rip), %xmm1     # 0x1e110
jbe 0x1bad6
xorpd %xmm0, %xmm0
movsd %xmm0, %xmm3            # xmm3 = xmm0[0],xmm3[1]
movapd %xmm2, %xmm4
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
movsd 0x8(%r15), %xmm0
mulsd %xmm2, %xmm0
movsd (%r15), %xmm1
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%r15), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%r14)
movsd 0x8(%r12), %xmm0
movapd %xmm2, 0x70(%rsp)
mulsd %xmm2, %xmm0
movsd (%r12), %xmm1
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%r12), %xmm0
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rbx)
movsd (%r14), %xmm1
movupd (%r15), %xmm5
movapd %xmm1, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movapd %xmm3, 0x50(%rsp)
mulpd %xmm3, %xmm2
subpd %xmm2, %xmm5
movapd %xmm5, 0x10(%rsp)
movapd %xmm5, 0x90(%rsp)
movsd 0x10(%r15), %xmm3
movapd %xmm1, %xmm2
movsd %xmm4, 0x30(%rsp)
mulsd %xmm4, %xmm2
subsd %xmm2, %xmm3
movsd %xmm3, 0x28(%rsp)
movsd %xmm3, 0xa0(%rsp)
ucomisd %xmm0, %xmm1
jbe 0x1b762
movsd %xmm0, (%r14)
movsd %xmm1, (%rbx)
xorl %ebx, %ebx
leaq 0x3a31385(%rip), %r14   # 0x3a4caf0
leaq 0x3a3134e(%rip), %r15   # 0x3a4cac0
leaq 0x3a3135f(%rip), %r12   # 0x3a4cad8
xorl %r13d, %r13d
movsd 0x90(%rsp,%r13), %xmm0
subsd (%r13,%r15), %xmm0
mulsd (%r13,%r14), %xmm0
movsd %xmm0, (%rsp)
callq 0x4530
cvttsd2si %xmm0, %eax
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp,%r13)
movl (%rbx,%r12), %ecx
addl %ecx, %eax
cltd
idivl %ecx
leal (%rdx,%rcx), %eax
cltd
idivl %ecx
movl %edx, 0x48(%rsp,%rbx)
addq $0x8, %r13
addq $0x4, %rbx
cmpq $0x8, %r13
je 0x1b77c
movl 0x48(%rsp), %eax
movq %rax, 0x38(%rsp)
movl 0x4c(%rsp), %r14d
movl 0x3a312ed(%rip), %eax   # 0x3a4cadc
movl %eax, 0xc(%rsp)
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x68(%rsp), %xmm2
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0x8491(%rip), %rbx      # 0x23ca3
xorl %r13d, %r13d
movsd %xmm2, (%rsp)
cmpl $0x1, %r12d
je 0x1b84c
cmpl $-0x1, %r12d
jne 0x1b870
movsd 0x3a312c2(%rip), %xmm0  # 0x3a4caf0
mulsd 0x6c2a(%rip), %xmm0     # 0x22460
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x1b916
cmpl $0x1, %r12d
jne 0x1b870
movsd 0x3a3129c(%rip), %xmm0  # 0x3a4caf0
mulsd 0x84c4(%rip), %xmm0     # 0x23d20
addsd 0x5874(%rip), %xmm0     # 0x210d8
ucomisd 0x40(%rsp), %xmm0
ja 0x1b916
movq 0x38(%rsp), %rax
leal (%r12,%rax), %ebp
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x1, %r15d
je 0x1b8a7
cmpl $-0x1, %r15d
jne 0x1b8c5
movsd 0x3a31265(%rip), %xmm0  # 0x3a4caf8
mulsd 0x6bc5(%rip), %xmm0     # 0x22460
ucomisd %xmm0, %xmm2
ja 0x1b909
cmpl $0x1, %r15d
jne 0x1b8c5
movsd 0x3a31249(%rip), %xmm0  # 0x3a4caf8
mulsd 0x8469(%rip), %xmm0     # 0x23d20
addsd 0x5819(%rip), %xmm0     # 0x210d8
ucomisd %xmm2, %xmm0
ja 0x1b909
cmpl $0x4, %r13d
jl 0x1b8da
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9f84
movsd (%rsp), %xmm2
movl 0x3a311f8(%rip), %ecx   # 0x3a4cad8
leal (%rcx,%rbp), %eax
cltd
idivl %ecx
movl %edx, %ecx
movl 0x3a311ee(%rip), %esi   # 0x3a4cadc
imull %esi, %ecx
leal (%r14,%r15), %eax
addl %esi, %eax
cltd
idivl %esi
addl %ecx, %edx
movslq %r13d, %rax
movl %edx, 0x80(%rsp,%rax,4)
incl %r13d
incl %r15d
cmpl $0x2, %r15d
jne 0x1b87f
incl %r12d
cmpl $0x2, %r12d
jne 0x1b81a
testl %r13d, %r13d
setg %cl
jle 0x1ba1b
movl %r13d, %edx
movapd 0x10(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
xorl %esi, %esi
leaq 0x3a2916b(%rip), %rdi   # 0x3a44ab0
movapd 0x5993(%rip), %xmm1     # 0x212e0
movsd 0x83d3(%rip), %xmm2     # 0x23d28
movapd 0x50(%rsp), %xmm4
movsd 0x30(%rsp), %xmm5
movsd 0x28(%rsp), %xmm6
movapd 0x70(%rsp), %xmm7
movslq 0x80(%rsp,%rsi,4), %rax
movq (%rdi,%rax,8), %rax
testq %rax, %rax
je 0x1ba0a
movsd 0x20(%rax), %xmm3
subsd 0x10(%rsp), %xmm3
andpd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
ja 0x1ba02
movsd 0x28(%rax), %xmm3
subsd %xmm0, %xmm3
andpd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
ja 0x1ba02
movsd 0x30(%rax), %xmm3
subsd %xmm6, %xmm3
andpd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
ja 0x1ba02
movsd 0x8(%rax), %xmm3
subsd %xmm4, %xmm3
andpd %xmm1, %xmm3
ucomisd 0x273e(%rip), %xmm3     # 0x1e110
ja 0x1ba02
movsd 0x10(%rax), %xmm3
subsd %xmm7, %xmm3
andpd %xmm1, %xmm3
ucomisd 0x2727(%rip), %xmm3     # 0x1e110
ja 0x1ba02
movsd 0x18(%rax), %xmm3
subsd %xmm5, %xmm3
andpd %xmm1, %xmm3
ucomisd 0x2710(%rip), %xmm3     # 0x1e110
jbe 0x1ba1b
movq (%rax), %rax
jmp 0x1b979
incq %rsi
cmpq %rdx, %rsi
setb %cl
jne 0x1b96d
jmp 0x1ba1b
testb $0x1, %cl
jne 0x1bac4
movl 0xc(%rsp), %ebx
imull 0x38(%rsp), %ebx
addl %r14d, %ebx
xorl %edi, %edi
cmpl $0x20000, 0x3a31078(%rip) # imm = 0x20000
setl %dil
movl $0x13, %esi
callq 0xa731
movslq 0x3a31063(%rip), %rcx   # 0x3a4cab4
leaq (%rcx,%rcx,4), %rdx
shlq $0x4, %rdx
leaq 0x3a310b0(%rip), %rsi   # 0x3a4cb10
leaq (%rsi,%rdx), %rax
incl %ecx
movl %ecx, 0x3a31048(%rip)   # 0x3a4cab4
movslq %ebx, %rcx
leaq 0x3a2903a(%rip), %rdi   # 0x3a44ab0
movq (%rdi,%rcx,8), %r8
leaq 0x38(%rdx,%rsi), %rdx
movq %r8, -0x38(%rdx)
movq %rax, (%rdi,%rcx,8)
movaps 0x10(%rsp), %xmm0
movaps %xmm0, -0x18(%rdx)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, -0x8(%rdx)
movaps 0x50(%rsp), %xmm0
movups %xmm0, -0x30(%rdx)
movsd 0x30(%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 %xmm1, %xmm0
jbe 0x1bb02
leaq 0x42fd(%rip), %rax      # 0x1fde0
movapd (%rax), %xmm3
movsd 0x8(%rax), %xmm0
subsd %xmm1, %xmm0
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
movsd 0x10(%rax), %xmm4
subsd %xmm2, %xmm4
jmp 0x1b699
xorpd %xmm3, %xmm3
ucomisd 0x2602(%rip), %xmm2     # 0x1e110
ja 0x1b695
xorpd %xmm4, %xmm4
ucomisd %xmm2, %xmm0
jbe 0x1b699
leaq 0x42b7(%rip), %rax      # 0x1fde0
movapd (%rax), %xmm3
jmp 0x1baf4