// File: /workspace/github_cpp_makefile_star2_O3/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, 0xc(%rsp)
movq %rdi, %r14
xorl %ebx, %ebx
movsd (%r14,%rbx,8), %xmm0
movapd %xmm0, 0x10(%rsp)
addsd 0x5f6d(%rip), %xmm0     # 0x20250
callq 0x4530
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
andpd 0x5fc2(%rip), %xmm1     # 0x202c0
cmpltsd 0x88f9(%rip), %xmm1     # 0x22c00
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movlpd %xmm1, 0x60(%rsp,%rbx,8)
incq %rbx
cmpq $0x3, %rbx
jne 0x1a2cf
leaq 0x34(%rsp), %r13
leaq 0x50(%rsp), %r14
leaq 0x60(%rsp), %rax
movb $0x1, %bpl
xorl %r15d, %r15d
leaq 0x30(%rsp), %rbx
leaq 0x58(%rsp), %r12
movsd (%rax), %xmm0
leaq 0x36a9754(%rip), %rax   # 0x36c3aa0
subsd (%rax,%r15,8), %xmm0
leaq 0x36a9727(%rip), %rax   # 0x36c3a80
mulsd (%rax,%r15,8), %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, (%r14)
leaq 0x36a972c(%rip), %rcx   # 0x36c3ab8
movl (%rcx,%r15,4), %ecx
addl %ecx, %eax
cltd
idivl %ecx
leal (%rdx,%rcx), %eax
cltd
idivl %ecx
movl %edx, (%r13)
movl $0x1, %r15d
leaq 0x68(%rsp), %rax
movq %r12, %r14
movq %rbx, %r13
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x1a341
movl 0x34(%rsp), %eax
movq %rax, 0x40(%rsp)
movl 0x36a96f2(%rip), %eax   # 0x36c3abc
movl 0x30(%rsp), %r12d
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x8880(%rip), %r14      # 0x22c73
xorl %r13d, %r13d
movl %eax, 0x2c(%rsp)
movl %eax, %esi
xorl %edi, %edi
cmpl $0x1, %ebx
je 0x1a429
cmpl $-0x1, %ebx
jne 0x1a44d
movsd 0x36a9670(%rip), %xmm0  # 0x36c3a80
mulsd 0x6068(%rip), %xmm0     # 0x20480
movsd 0x38(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1a44d
jmp 0x1a4f7
movsd 0x36a964f(%rip), %xmm0  # 0x36c3a80
mulsd 0x6067(%rip), %xmm0     # 0x204a0
addsd 0x5c87(%rip), %xmm0     # 0x200c8
ucomisd 0x38(%rsp), %xmm0
ja 0x1a502
movq 0x40(%rsp), %rax
leal (%rbx,%rax), %ebp
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x1, %r15d
je 0x1a485
cmpl $-0x1, %r15d
jne 0x1a4a5
movsd 0x36a9619(%rip), %xmm0  # 0x36c3a88
mulsd 0x6009(%rip), %xmm0     # 0x20480
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1a4a5
jmp 0x1a4ea
movsd 0x36a95fb(%rip), %xmm0  # 0x36c3a88
mulsd 0x600b(%rip), %xmm0     # 0x204a0
addsd 0x5c2b(%rip), %xmm0     # 0x200c8
ucomisd 0x10(%rsp), %xmm0
ja 0x1a4f7
cmpl $0x4, %edi
jl 0x1a4bd
movq %r14, %rdi
xorl %eax, %eax
callq 0x9e9c
movl 0x36a9602(%rip), %esi   # 0x36c3abc
movl %r13d, %edi
movl 0x36a95f5(%rip), %ecx   # 0x36c3ab8
leal (%rcx,%rbp), %eax
cltd
idivl %ecx
movl %edx, %ecx
imull %esi, %ecx
leal (%r12,%rsi), %eax
addl %r15d, %eax
cltd
idivl %esi
addl %ecx, %edx
movslq %edi, %rax
movl %edx, 0x80(%rsp,%rax,4)
incl %r13d
movl %r13d, %edi
incl %r15d
cmpl $0x2, %r15d
jne 0x1a45b
incl %ebx
cmpl $0x2, %ebx
jne 0x1a3fe
movapd 0x60(%rsp), %xmm5
movsd 0x70(%rsp), %xmm4
testl %r13d, %r13d
movapd 0x5da7(%rip), %xmm3     # 0x202c0
jle 0x1a592
movl %r13d, %eax
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
xorl %ecx, %ecx
leaq 0x36a1541(%rip), %rdx   # 0x36bba70
movsd 0x86d1(%rip), %xmm1     # 0x22c08
movslq 0x80(%rsp,%rcx,4), %rsi
movq (%rdx,%rsi,8), %rbx
testq %rbx, %rbx
je 0x1a58a
movsd 0x8(%rbx), %xmm2
subsd %xmm5, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x1a585
movsd 0x10(%rbx), %xmm2
subsd %xmm0, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x1a585
movsd 0x18(%rbx), %xmm2
subsd %xmm4, %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm2, %xmm1
ja 0x1a654
movq (%rbx), %rbx
jmp 0x1a543
incq %rcx
cmpq %rax, %rcx
jne 0x1a537
movl 0x2c(%rsp), %ecx
imull 0x40(%rsp), %ecx
addl %r12d, %ecx
movq 0x36a94cb(%rip), %rbx   # 0x36c3a70
movl $0x1, %eax
movl %eax, 0x30(%rbx)
movl %eax, 0x24(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0x28(%rbx)
movslq %ecx, %rax
leaq 0x36a14af(%rip), %rcx   # 0x36bba70
movq (%rcx,%rax,8), %rdx
movq %rdx, (%rbx)
movq %rbx, (%rcx,%rax,8)
movupd %xmm5, 0x8(%rbx)
movsd %xmm4, 0x18(%rbx)
leaq 0xff8dd7(%rip), %r14    # 0x10133b4
movl (%r14), %eax
movl %eax, 0x20(%rbx)
addq $0x20, %rbx
movl $0xffff, %ebp           # imm = 0xFFFF
xorl %edi, %edi
cmpl %ebp, %eax
setne %dil
movl $0x2c, %esi
movsd %xmm4, 0x10(%rsp)
movapd %xmm5, 0x40(%rsp)
callq 0xa655
addq $0x38, 0x36a945e(%rip)  # 0x36c3a70
xorl %edi, %edi
cmpl %ebp, (%r14)
setl %dil
movl $0x2c, %esi
callq 0xa655
movslq (%r14), %rax
leaq (%rax,%rax,2), %rcx
leaq 0xff8d8d(%rip), %rdx    # 0x10133c0
cvtpd2ps 0x40(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsd2ss 0x10(%rsp), %xmm1
movlpd %xmm0, (%rdx,%rcx,4)
movss %xmm1, 0x8(%rdx,%rcx,4)
incl %eax
movl %eax, (%r14)
jmp 0x1a694
incl 0x30(%rbx)
movl 0x24(%rbx), %eax
cmpq $0x3, %rax
je 0x1a690
testl %eax, %eax
movl 0xc(%rsp), %edx
jle 0x1a682
xorl %ecx, %ecx
cmpl %edx, 0x28(%rbx,%rcx,4)
je 0x1a690
incq %rcx
cmpq %rcx, %rax
jne 0x1a66a
movl $0x3, %ecx
cmpl $0x2, %eax
je 0x1a68d
cltq
movl %edx, 0x28(%rbx,%rax,4)
movl 0x24(%rbx), %ecx
incl %ecx
movl %ecx, 0x24(%rbx)
addq $0x20, %rbx
movl (%rbx), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq