// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movl %esi, %ebp
movq %rdi, %r14
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0x17ff9
movsd (%r14,%rbx,8), %xmm0
movapd %xmm0, 0x10(%rsp)
addsd 0x61f6(%rip), %xmm0     # 0x1e1b0
callq 0x4540
movapd 0x10(%rsp), %xmm3
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
movapd 0x623b(%rip), %xmm2     # 0x1e210
andpd %xmm2, %xmm1
cmpltsd 0x8b7e(%rip), %xmm1     # 0x20b60
andpd %xmm1, %xmm0
andnpd %xmm3, %xmm1
orpd %xmm0, %xmm1
movlpd %xmm1, 0x60(%rsp,%rbx,8)
incq %rbx
jmp 0x17fa0
movl %ebp, 0xc(%rsp)
xorl %ebx, %ebx
leaq 0x36aaa8a(%rip), %r14   # 0x36c2a90
leaq 0x36aaaa3(%rip), %r15   # 0x36c2ab0
leaq 0x36aaab4(%rip), %r12   # 0x36c2ac8
xorl %r13d, %r13d
cmpq $0x10, %rbx
je 0x18075
movsd 0x60(%rsp,%rbx), %xmm0
subsd (%rbx,%r15), %xmm0
mulsd (%rbx,%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x4540
cvttsd2si %xmm0, %eax
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp,%rbx)
movl (%r13,%r12), %ecx
addl %ecx, %eax
cltd
idivl %ecx
leal (%rdx,%rcx), %eax
cltd
idivl %ecx
movl %edx, 0x38(%rsp,%r13)
addq $0x4, %r13
addq $0x8, %rbx
jmp 0x18017
movl 0x38(%rsp), %eax
movq %rax, 0x40(%rsp)
movl 0x3c(%rsp), %r12d
movl 0x36aaa43(%rip), %eax   # 0x36c2acc
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x58(%rsp), %xmm2
pushq $-0x1
popq %rcx
leaq 0x8b2e(%rip), %r14      # 0x20bd3
xorl %r15d, %r15d
movl %eax, 0x2c(%rsp)
movl %eax, %esi
xorl %edi, %edi
movl %ecx, %ebp
movsd %xmm2, 0x10(%rsp)
cmpl $-0x1, %ebp
je 0x180ee
cmpl $0x1, %ebp
je 0x180cc
cmpl $0x2, %ebp
jne 0x1810e
jmp 0x181b7
movsd 0x36aa9bc(%rip), %xmm0  # 0x36c2a90
mulsd 0x6324(%rip), %xmm0     # 0x1e400
addsd 0x5f44(%rip), %xmm0     # 0x1e028
ucomisd 0x30(%rsp), %xmm0
ja 0x1810a
jmp 0x1810e
movsd 0x36aa99a(%rip), %xmm0  # 0x36c2a90
mulsd 0x62e2(%rip), %xmm0     # 0x1e3e0
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1810e
incl %ebp
jmp 0x180b8
movq 0x40(%rsp), %rax
leal (%rax,%rbp), %ebx
pushq $-0x1
popq %r13
cmpl $-0x1, %r13d
je 0x1814e
cmpl $0x1, %r13d
je 0x1812e
cmpl $0x2, %r13d
jne 0x18164
jmp 0x1810a
movsd 0x36aa962(%rip), %xmm0  # 0x36c2a98
mulsd 0x62c2(%rip), %xmm0     # 0x1e400
addsd 0x5ee2(%rip), %xmm0     # 0x1e028
ucomisd %xmm2, %xmm0
jbe 0x18164
jmp 0x181af
movsd 0x36aa942(%rip), %xmm0  # 0x36c2a98
mulsd 0x6282(%rip), %xmm0     # 0x1e3e0
ucomisd %xmm0, %xmm2
ja 0x181af
cmpl $0x4, %edi
jl 0x18182
movq %r14, %rdi
xorl %eax, %eax
callq 0x8b1f
movsd 0x10(%rsp), %xmm2
movl 0x36aa94d(%rip), %esi   # 0x36c2acc
movl %r15d, %edi
movl 0x36aa940(%rip), %ecx   # 0x36c2ac8
leal (%rbx,%rcx), %eax
cltd
idivl %ecx
movl %edx, %ecx
imull %esi, %ecx
leal (%r12,%rsi), %eax
addl %r13d, %eax
cltd
idivl %esi
addl %ecx, %edx
movslq %edi, %rax
movl %edx, 0x80(%rsp,%rax,4)
incl %r15d
movl %r15d, %edi
incl %r13d
jmp 0x1811a
movl 0x2c(%rsp), %esi
imull 0x40(%rsp), %esi
addl %r12d, %esi
movapd 0x60(%rsp), %xmm5
movsd 0x70(%rsp), %xmm4
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
leaq 0x36a2899(%rip), %rcx   # 0x36baa80
movsd 0x8979(%rip), %xmm1     # 0x20b68
movapd 0x6019(%rip), %xmm3     # 0x1e210
cmpq %r15, %rax
je 0x182a2
movslq 0x80(%rsp,%rax,4), %rdx
leaq (%rcx,%rdx,8), %r14
movq (%r14), %r14
testq %r14, %r14
je 0x18252
movsd 0x8(%r14), %xmm2
subsd %xmm5, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x1820c
movsd 0x10(%r14), %xmm2
subsd %xmm0, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x1820c
movsd 0x18(%r14), %xmm2
subsd %xmm4, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x1820c
jmp 0x18257
incq %rax
jmp 0x181f7
incl 0x30(%r14)
movslq 0x24(%r14), %rax
cmpq $0x3, %rax
je 0x1835e
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movl 0xc(%rsp), %edi
cmpq %rcx, %rdx
je 0x18291
leaq 0x1(%rcx), %rsi
cmpl %edi, 0x28(%r14,%rcx,4)
movq %rsi, %rcx
jne 0x18279
jmp 0x1835e
cmpl $0x2, %eax
jne 0x1834f
pushq $0x3
popq %rax
jmp 0x1835a
movq 0x36aa7d7(%rip), %r14   # 0x36c2a80
pushq $0x1
popq %rax
movl %eax, 0x30(%r14)
movl %eax, 0x24(%r14)
movl 0xc(%rsp), %eax
movl %eax, 0x28(%r14)
movslq %esi, %rax
movq (%rcx,%rax,8), %rdx
movq %rdx, (%r14)
movq %r14, (%rcx,%rax,8)
movupd %xmm5, 0x8(%r14)
movsd %xmm4, 0x18(%r14)
leaq 0xffa0e7(%rip), %r15    # 0x10123c4
movl (%r15), %eax
movl %eax, 0x20(%r14)
addq $0x20, %r14
movl $0xffff, %ebp           # imm = 0xFFFF
xorl %edi, %edi
cmpl %ebp, %eax
setne %dil
pushq $0x2c
popq %rbx
movl %ebx, %esi
movsd %xmm4, 0x10(%rsp)
movapd %xmm5, 0x40(%rsp)
callq 0x92bb
addq $0x38, 0x36aa76d(%rip)  # 0x36c2a80
xorl %edi, %edi
cmpl %ebp, (%r15)
setl %dil
movl %ebx, %esi
callq 0x92bb
movslq (%r15), %rax
imulq $0xc, %rax, %rcx
leaq 0xffa09f(%rip), %rdx    # 0x10123d0
cvtpd2ps 0x40(%rsp), %xmm0
cvtsd2ss 0x10(%rsp), %xmm1
movlpd %xmm0, (%rdx,%rcx)
movss %xmm1, 0x8(%rdx,%rcx)
incl %eax
movl %eax, (%r15)
jmp 0x18362
movl %edi, 0x28(%r14,%rax,4)
movl 0x24(%r14), %eax
incl %eax
movl %eax, 0x24(%r14)
addq $0x20, %r14
movl (%r14), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq