// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlbsp/surfaces.cpp
// Function: GetVertex(double const*, int)
static int      GetVertex(const vec3_t in, const int planenum)
{
    int             h;
    int             i;
    hashvert_t*     hv;
    vec3_t          vert;
#ifdef HLBSP_HASH_FIX
	int				num_hashneighbors;
	int				hashneighbors[MAX_HASH_NEIGHBORS];
#endif

    for (i = 0; i < 3; i++)
    {
        if (fabs(in[i] - VectorRound(in[i])) < 0.001)
        {
            vert[i] = VectorRound(in[i]);
        }
        else
        {
            vert[i] = in[i];
        }
    }

#ifdef HLBSP_HASH_FIX
	h = HashVec(vert, &num_hashneighbors, hashneighbors);
#else
    h = HashVec(vert);
#endif

#ifdef HLBSP_HASH_FIX
  for (i = 0; i < num_hashneighbors; i++)
	for (hv = hashverts[hashneighbors[i]]; hv; hv = hv->next)
#else
    for (hv = hashverts[h]; hv; hv = hv->next)
#endif
    {
        if (fabs(hv->point[0] - vert[0]) < POINT_EPSILON
            && fabs(hv->point[1] - vert[1]) < POINT_EPSILON && fabs(hv->point[2] - vert[2]) < POINT_EPSILON)
        {
            hv->numedges++;
            if (hv->numplanes == 3)
            {
                return hv->num;                            // allready known to be a corner
            }
            for (i = 0; i < hv->numplanes; i++)
            {
                if (hv->planenums[i] == planenum)
                {
                    return hv->num;                        // allready know this plane
                }
            }
            if (hv->numplanes != 2)
            {
                hv->planenums[hv->numplanes] = planenum;
            }
            hv->numplanes++;
            return hv->num;
        }
    }

    hv = hvert_p;
    hv->numedges = 1;
    hv->numplanes = 1;
    hv->planenums[0] = planenum;
    hv->next = hashverts[h];
    hashverts[h] = hv;
    VectorCopy(vert, hv->point);
    hv->num = g_numvertexes;
    hlassume(hv->num != MAX_MAP_VERTS, assume_MAX_MAP_VERTS);
    hvert_p++;

    // emit a vertex
    hlassume(g_numvertexes < MAX_MAP_VERTS, assume_MAX_MAP_VERTS);

    g_dvertexes[g_numvertexes].point[0] = vert[0];
    g_dvertexes[g_numvertexes].point[1] = vert[1];
    g_dvertexes[g_numvertexes].point[2] = vert[2];
    g_numvertexes++;

    return hv->num;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, 0x4(%rsp)
movq %rdi, %r14
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movapd %xmm0, 0x10(%rsp)
addsd 0x6c0f(%rip), %xmm0     # 0x21260
callq 0x4530
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
andpd 0x6c74(%rip), %xmm1     # 0x212e0
cmpltsd 0x95c3(%rip), %xmm1     # 0x23c38
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movlpd %xmm1, 0x40(%rsp,%rbx,8)
incq %rbx
cmpq $0x3, %rbx
jne 0x1a63d
xorl %ebx, %ebx
leaq 0x36aa3f7(%rip), %r14   # 0x36c4a90
leaq 0x36aa410(%rip), %r15   # 0x36c4ab0
leaq 0x36aa421(%rip), %r12   # 0x36c4ac8
xorl %r13d, %r13d
movsd 0x40(%rsp,%r13), %xmm0
subsd (%r13,%r15), %xmm0
mulsd (%r13,%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x4530
cvttsd2si %xmm0, %eax
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd 0x10(%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, 0x38(%rsp,%rbx)
addq $0x8, %r13
addq $0x4, %rbx
cmpq $0x8, %r13
je 0x1a6aa
movl 0x38(%rsp), %eax
movq %rax, 0x30(%rsp)
movl 0x3c(%rsp), %r15d
movl 0x36aa3b0(%rip), %eax   # 0x36c4acc
movl %eax, 0x2c(%rsp)
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x68(%rsp), %xmm2
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x9565(%rip), %r14      # 0x23ca3
xorl %r13d, %r13d
movsd %xmm2, 0x10(%rsp)
cmpl $0x1, %ebx
je 0x1a776
cmpl $-0x1, %ebx
jne 0x1a79a
movsd 0x36aa337(%rip), %xmm0  # 0x36c4a90
mulsd 0x6d2f(%rip), %xmm0     # 0x21490
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x1a83d
cmpl $0x1, %ebx
jne 0x1a79a
movsd 0x36aa312(%rip), %xmm0  # 0x36c4a90
mulsd 0x6d22(%rip), %xmm0     # 0x214a8
addsd 0x694a(%rip), %xmm0     # 0x210d8
ucomisd 0x8(%rsp), %xmm0
ja 0x1a83d
movq 0x30(%rsp), %rax
leal (%rbx,%rax), %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x1, %r12d
je 0x1a7d0
cmpl $-0x1, %r12d
jne 0x1a7ee
movsd 0x36aa2dc(%rip), %xmm0  # 0x36c4a98
mulsd 0x6ccc(%rip), %xmm0     # 0x21490
ucomisd %xmm0, %xmm2
ja 0x1a830
cmpl $0x1, %r12d
jne 0x1a7ee
movsd 0x36aa2c0(%rip), %xmm0  # 0x36c4a98
mulsd 0x6cc8(%rip), %xmm0     # 0x214a8
addsd 0x68f0(%rip), %xmm0     # 0x210d8
ucomisd %xmm2, %xmm0
ja 0x1a830
cmpl $0x4, %r13d
jl 0x1a804
movq %r14, %rdi
xorl %eax, %eax
callq 0x9f84
movsd 0x10(%rsp), %xmm2
movl 0x36aa2be(%rip), %ecx   # 0x36c4ac8
leal (%rcx,%rbp), %eax
cltd
idivl %ecx
movl %edx, %ecx
movl 0x36aa2b4(%rip), %esi   # 0x36c4acc
imull %esi, %ecx
leal (%r15,%r12), %eax
addl %esi, %eax
cltd
idivl %esi
addl %ecx, %edx
movslq %r13d, %rax
movl %edx, 0x70(%rsp,%rax,4)
incl %r13d
incl %r12d
cmpl $0x2, %r12d
jne 0x1a7a8
incl %ebx
cmpl $0x2, %ebx
jne 0x1a747
testl %r13d, %r13d
movapd 0x6a8d(%rip), %xmm5     # 0x212e0
jle 0x1a8da
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
movl %r13d, %eax
xorl %ecx, %ecx
leaq 0x36a2209(%rip), %rdx   # 0x36bca80
movsd 0x93c1(%rip), %xmm3     # 0x23c40
movslq 0x70(%rsp,%rcx,4), %rsi
movq (%rdx,%rsi,8), %r14
testq %r14, %r14
je 0x1a8d2
movsd 0x8(%r14), %xmm4
subsd %xmm0, %xmm4
andpd %xmm5, %xmm4
ucomisd %xmm4, %xmm3
jbe 0x1a8cd
movsd 0x10(%r14), %xmm4
subsd %xmm1, %xmm4
andpd %xmm5, %xmm4
ucomisd %xmm4, %xmm3
jbe 0x1a8cd
movsd 0x18(%r14), %xmm4
subsd %xmm2, %xmm4
andpd %xmm5, %xmm4
ucomisd %xmm4, %xmm3
ja 0x1a9a8
movq (%r14), %r14
jmp 0x1a888
incq %rcx
cmpq %rax, %rcx
jne 0x1a87f
movl 0x2c(%rsp), %ecx
imull 0x30(%rsp), %ecx
addl %r15d, %ecx
movq 0x36aa193(%rip), %r14   # 0x36c4a80
movl $0x1, %eax
movl %eax, 0x30(%r14)
movl %eax, 0x24(%r14)
movl 0x4(%rsp), %eax
movl %eax, 0x28(%r14)
movslq %ecx, %rax
leaq 0x36a2174(%rip), %rcx   # 0x36bca80
movq (%rcx,%rax,8), %rdx
movq %rdx, (%r14)
movq %r14, (%rcx,%rax,8)
movaps 0x40(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
movups %xmm0, 0x8(%r14)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x18(%r14)
leaq 0xff9a85(%rip), %rbx    # 0x10143c4
movl (%rbx), %eax
movl %eax, 0x20(%r14)
addq $0x20, %r14
movl $0xffff, %ebp           # imm = 0xFFFF
xorl %edi, %edi
cmpl %ebp, %eax
setne %dil
movl $0x2c, %esi
callq 0xa731
addq $0x38, 0x36aa118(%rip)  # 0x36c4a80
xorl %edi, %edi
cmpl %ebp, (%rbx)
setl %dil
movl $0x2c, %esi
callq 0xa731
movslq (%rbx), %rax
leaq (%rax,%rax,2), %rcx
leaq 0xff9a48(%rip), %rdx    # 0x10143d0
cvtpd2ps 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsd2ss 0x8(%rsp), %xmm1
movlpd %xmm0, (%rdx,%rcx,4)
movss %xmm1, 0x8(%rdx,%rcx,4)
incl %eax
movl %eax, (%rbx)
jmp 0x1a9e3
incl 0x30(%r14)
movl 0x24(%r14), %eax
cmpq $0x3, %rax
je 0x1a9df
testl %eax, %eax
movl 0x4(%rsp), %edx
jle 0x1a9cf
xorl %ecx, %ecx
cmpl %edx, 0x28(%r14,%rcx,4)
je 0x1a9df
incq %rcx
cmpq %rcx, %rax
jne 0x1a9c0
cmpl $0x2, %eax
je 0x1a9db
cltq
movl %edx, 0x28(%r14,%rax,4)
incl 0x24(%r14)
addq $0x20, %r14
movl (%r14), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq