// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movupd (%rsi), %xmm0
movupd (%rdi), %xmm1
subpd %xmm1, %xmm0
movq %rsp, %r13
movapd %xmm0, (%r13)
movsd 0x10(%rsi), %xmm0
subsd 0x10(%rdi), %xmm0
movsd %xmm0, 0x10(%r13)
movq %r13, %rdi
callq 0xc073
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd (%r13), %xmm0
jne 0x18c9d
jnp 0x18d03
ucomisd 0x23db(%rip), %xmm0     # 0x1b080
ja 0x18d03
movsd 0x7f99(%rip), %xmm2     # 0x20c48
ucomisd %xmm0, %xmm2
jbe 0x18ce6
leaq 0x4074(%rip), %rax      # 0x1cd30
movapd (%rax), %xmm2
movhpd 0x8(%rsp), %xmm0        # xmm0 = xmm0[0],mem[0]
subpd %xmm0, %xmm2
movapd %xmm2, (%rsp)
movsd 0x10(%rax), %xmm1
subsd 0x10(%rsp), %xmm1
movapd %xmm2, %xmm0
movsd %xmm1, 0x10(%rsp)
jmp 0x18d03
andq $0x0, (%rsp)
movsd 0x8(%rsp), %xmm1
xorpd %xmm0, %xmm0
ucomisd 0x2383(%rip), %xmm1     # 0x1b080
jbe 0x190fe
movsd 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
movsd 0x8(%r15), %xmm3
mulsd %xmm2, %xmm3
movsd (%r15), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
movsd 0x10(%r15), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, (%r14)
movsd 0x8(%r12), %xmm3
mulsd %xmm2, %xmm3
movsd (%r12), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
movsd 0x10(%r12), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, (%rbx)
movsd (%r14), %xmm4
movupd (%r15), %xmm6
movapd %xmm4, %xmm5
unpcklpd %xmm4, %xmm5            # xmm5 = xmm5[0],xmm4[0]
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
mulpd %xmm5, %xmm0
subpd %xmm0, %xmm6
movapd %xmm6, 0x50(%rsp)
movapd %xmm6, 0x80(%rsp)
movsd 0x10(%r15), %xmm0
mulsd %xmm4, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd %xmm0, 0x90(%rsp)
ucomisd %xmm3, %xmm4
jbe 0x18dbe
movsd %xmm3, (%r14)
movsd %xmm4, (%rbx)
xorl %ebx, %ebx
leaq 0x3a31d29(%rip), %r14   # 0x3a4aaf0
leaq 0x3a31cf2(%rip), %r15   # 0x3a4aac0
leaq 0x3a31d03(%rip), %r12   # 0x3a4aad8
xorl %r13d, %r13d
cmpq $0x10, %rbx
je 0x18e39
movsd 0x80(%rsp,%rbx), %xmm0
subsd (%rbx,%r15), %xmm0
mulsd (%rbx,%r14), %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x4540
cvttsd2si %xmm0, %eax
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp,%rbx)
movl (%r13,%r12), %ecx
addl %ecx, %eax
cltd
idivl %ecx
leal (%rdx,%rcx), %eax
cltd
idivl %ecx
movl %edx, 0x48(%rsp,%r13)
addq $0x4, %r13
addq $0x8, %rbx
jmp 0x18dd8
movl 0x48(%rsp), %eax
movq %rax, 0x38(%rsp)
movl 0x4c(%rsp), %r15d
movl 0x3a31c8f(%rip), %eax   # 0x3a4aadc
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x68(%rsp), %xmm2
pushq $-0x1
popq %rcx
leaq 0x7d6a(%rip), %rbx      # 0x20bd3
xorl %r14d, %r14d
movl %eax, 0x2c(%rsp)
movl %eax, %esi
xorl %edi, %edi
movl %ecx, %ebp
movsd %xmm2, 0x20(%rsp)
cmpl $-0x1, %ebp
je 0x18eb2
cmpl $0x1, %ebp
je 0x18e90
cmpl $0x2, %ebp
jne 0x18ed2
jmp 0x18f7a
movsd 0x3a31c58(%rip), %xmm0  # 0x3a4aaf0
mulsd 0x7db0(%rip), %xmm0     # 0x20c50
addsd 0x5180(%rip), %xmm0     # 0x1e028
ucomisd 0x30(%rsp), %xmm0
ja 0x18ece
jmp 0x18ed2
movsd 0x3a31c36(%rip), %xmm0  # 0x3a4aaf0
mulsd 0x64f6(%rip), %xmm0     # 0x1f3b8
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x18ed2
incl %ebp
jmp 0x18e7c
movq 0x38(%rsp), %rax
leal (%rax,%rbp), %r13d
pushq $-0x1
popq %r12
cmpl $-0x1, %r12d
je 0x18f13
cmpl $0x1, %r12d
je 0x18ef3
cmpl $0x2, %r12d
jne 0x18f29
jmp 0x18ece
movsd 0x3a31bfd(%rip), %xmm0  # 0x3a4aaf8
mulsd 0x7d4d(%rip), %xmm0     # 0x20c50
addsd 0x511d(%rip), %xmm0     # 0x1e028
ucomisd %xmm2, %xmm0
jbe 0x18f29
jmp 0x18f72
movsd 0x3a31bdd(%rip), %xmm0  # 0x3a4aaf8
mulsd 0x6495(%rip), %xmm0     # 0x1f3b8
ucomisd %xmm0, %xmm2
ja 0x18f72
cmpl $0x4, %edi
jl 0x18f47
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8b1f
movsd 0x20(%rsp), %xmm2
movl 0x3a31b98(%rip), %esi   # 0x3a4aadc
movl %r14d, %edi
movl 0x3a31b8b(%rip), %ecx   # 0x3a4aad8
leal (%rcx,%r13), %eax
cltd
idivl %ecx
movl %edx, %ecx
imull %esi, %ecx
leal (%r15,%rsi), %eax
addl %r12d, %eax
cltd
idivl %esi
addl %ecx, %edx
movslq %edi, %rax
movl %edx, 0x70(%rsp,%rax,4)
incl %r14d
movl %r14d, %edi
incl %r12d
jmp 0x18edf
movl 0x2c(%rsp), %ebp
imull 0x38(%rsp), %ebp
addl %r15d, %ebp
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %r14d
movapd 0x50(%rsp), %xmm3
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
leaq 0x3a29aff(%rip), %rbx   # 0x3a42ab0
movapd 0x5257(%rip), %xmm4     # 0x1e210
movsd 0x7c97(%rip), %xmm5     # 0x20c58
movsd 0x20b7(%rip), %xmm6     # 0x1b080
cmpq %r14, %rcx
je 0x19066
movslq 0x70(%rsp,%rcx,4), %rax
leaq (%rbx,%rax,8), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x1905e
movsd 0x20(%rax), %xmm7
subsd 0x50(%rsp), %xmm7
andpd %xmm4, %xmm7
ucomisd %xmm5, %xmm7
ja 0x18fdb
movsd 0x28(%rax), %xmm7
subsd %xmm3, %xmm7
andpd %xmm4, %xmm7
ucomisd %xmm5, %xmm7
ja 0x18fdb
movsd 0x30(%rax), %xmm7
subsd 0x40(%rsp), %xmm7
andpd %xmm4, %xmm7
ucomisd %xmm5, %xmm7
ja 0x18fdb
movsd 0x8(%rax), %xmm7
subsd %xmm0, %xmm7
andpd %xmm4, %xmm7
ucomisd %xmm6, %xmm7
ja 0x18fdb
movsd 0x10(%rax), %xmm7
subsd %xmm1, %xmm7
andpd %xmm4, %xmm7
ucomisd %xmm6, %xmm7
ja 0x18fdb
movsd 0x18(%rax), %xmm7
subsd %xmm2, %xmm7
andpd %xmm4, %xmm7
ucomisd %xmm6, %xmm7
ja 0x18fdb
jmp 0x190ec
incq %rcx
jmp 0x18fc9
xorl %edi, %edi
cmpl $0x20000, 0x3a31a42(%rip) # imm = 0x20000
setl %dil
pushq $0x13
popq %rsi
callq 0x92bb
movslq 0x3a31a2f(%rip), %rcx   # 0x3a4aab4
imulq $0x50, %rcx, %rdx
leaq 0x3a31a80(%rip), %rsi   # 0x3a4ab10
leaq (%rsi,%rdx), %rax
incl %ecx
movl %ecx, 0x3a31a18(%rip)   # 0x3a4aab4
movslq %ebp, %rcx
movq (%rbx,%rcx,8), %rdi
leaq 0x38(%rdx,%rsi), %rdx
movq %rdi, -0x38(%rdx)
movq %rax, (%rbx,%rcx,8)
movaps 0x50(%rsp), %xmm0
movaps %xmm0, -0x18(%rdx)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, -0x8(%rdx)
movaps (%rsp), %xmm0
movups %xmm0, -0x30(%rdx)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, -0x20(%rdx)
movq %rdx, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movabsq $0x40f869f000000000, %rcx # imm = 0x40F869F000000000
movq %rcx, (%rdx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd %xmm1, %xmm2
jbe 0x19133
leaq 0x3c25(%rip), %rax      # 0x1cd30
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm2
movsd %xmm0, (%rsp)
subsd %xmm1, %xmm2
movsd %xmm2, 0x8(%rsp)
movsd 0x10(%rax), %xmm1
subsd 0x10(%rsp), %xmm1
jmp 0x18cde
andq $0x0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm3
ucomisd 0x1f39(%rip), %xmm3     # 0x1b080
ja 0x18d03
xorpd %xmm1, %xmm1
ucomisd %xmm3, %xmm2
jbe 0x18cde
leaq 0x3bce(%rip), %rax      # 0x1cd30
movapd (%rax), %xmm0
movapd %xmm0, (%rsp)
movsd 0x10(%rax), %xmm1
subsd %xmm3, %xmm1
jmp 0x18cde