// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlvis/zones.cpp
// Function: MakeZones()
Zones* MakeZones(void)
{
    UINT32 x;
    UINT32 func_vis_count = 0;

    ParseEntities();

    // Note: we arent looping through entities because we only care if it has a winding/bounding box

    // First count the number of func_vis's
    for (x=0; x<g_nummodels; x++)
    {
        entity_t*       ent = EntityForModel(x);

        if (!strcasecmp(ValueForKey(ent, "classname"), "func_vis"))
        {
            UINT32 value = atoi(ValueForKey(ent, "node"));
            if (value)
            {
                func_vis_count++;
            }
            else
            {
                Error("func_vis with no \"node\" id\n");
            }
        }
    }

    if (!func_vis_count)
    {
        return NULL;
    }

    Zones* zones = new Zones(func_vis_count);

    for (x=0; x<g_nummodels; x++)
    {
        dmodel_t*       mod = g_dmodels + x;
        entity_t*       ent = EntityForModel(x);

        if (!strcasecmp(ValueForKey(ent, "classname"), "func_vis"))
        {
            UINT32 func_vis_id = atoi(ValueForKey(ent, "node"));

            {
                epair_t* keyvalue;
    
                for (keyvalue = ent->epairs; keyvalue; keyvalue = keyvalue->next)
                {
                    UINT32 other_id = atoi(keyvalue->key);
                    if (other_id)
                    {
                        zones->flag(func_vis_id, other_id);
                    }
                }
            }
    
            {
                UINT32          j;
                BoundingBox     bounds;
                dface_t*        f = g_dfaces + mod->firstface;
            
                for (j = 0; j < mod->numfaces; j++, f++)
                {
                    Winding*        w = WindingFromFace(f);
                    UINT32          k;

                    for (k = 0; k < w->m_NumPoints; k++)
                    {
                        bounds.add(w->m_Points[k]);
                    }
                    delete w;
                }

                zones->set(func_vis_id, bounds);

                Log("Adding zone %u : mins(%4.3f %4.3f %4.3f) maxs(%4.3f %4.3f %4.3f)\n", func_vis_id, 
                    bounds.m_Mins[0],bounds.m_Mins[1],bounds.m_Mins[2],
                    bounds.m_Maxs[0],bounds.m_Maxs[1],bounds.m_Maxs[2]);
            }
        }
    }

    return zones;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
callq 0x6422
leaq 0xb4c5(%rip), %rax      # 0x1c2b0
xorl %r14d, %r14d
cmpl $0x0, (%rax)
je 0x111af
leaq 0x180a(%rip), %rbx      # 0x12608
leaq 0x53cb(%rip), %r14      # 0x161d0
leaq 0x53cd(%rip), %r15      # 0x161d9
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %r13d, %edi
callq 0x6f1f
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x62ad
movq %rax, %rdi
movq %r14, %rsi
callq 0x3250
testl %eax, %eax
jne 0x10e5f
movq %r12, %rdi
movq %r15, %rsi
callq 0x62ad
movq %rax, %rdi
callq 0x33c0
testl %eax, %eax
je 0x10e51
incl %ebp
jmp 0x10e5f
leaq 0x5386(%rip), %rdi      # 0x161de
xorl %eax, %eax
callq 0x8cb4
incl %r13d
leaq 0xb447(%rip), %rax      # 0x1c2b0
cmpl (%rax), %r13d
jb 0x10e11
testl %ebp, %ebp
je 0x111ac
movl $0x28, %edi
callq 0x3230
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
callq 0x111e6
leaq 0xb41c(%rip), %rax      # 0x1c2b0
cmpl $0x0, (%rax)
je 0x111af
xorl %ebx, %ebx
leaq 0x1e0d3ca(%rip), %r15   # 0x1e1e270
leaq 0x1cf33a3(%rip), %r12   # 0x1d04250
leaq 0xff339c(%rip), %r13    # 0x1004250
movq %r14, 0x50(%rsp)
movl %ebx, %edi
callq 0x6f1f
movq %rax, %rbp
movq %rax, %rdi
leaq 0x173b(%rip), %rsi      # 0x12608
callq 0x62ad
movq %rax, %rdi
leaq 0x52f4(%rip), %rsi      # 0x161d0
callq 0x3250
testl %eax, %eax
jne 0x11195
movq %rbx, 0x18(%rsp)
movq %rbp, %rdi
leaq 0x52e1(%rip), %rsi      # 0x161d9
callq 0x62ad
movq %rax, %rdi
callq 0x33c0
movq 0x18(%rbp), %rbx
movl %eax, 0x14(%rsp)
movl %eax, %eax
movq %rax, 0x20(%rsp)
testq %rbx, %rbx
movb $0x1, %bpl
je 0x10f5e
movq 0x8(%rbx), %rdi
callq 0x33c0
testl %eax, %eax
je 0x10f56
movl 0x8(%r14), %ecx
cmpl 0x14(%rsp), %ecx
jbe 0x10f56
cmpl %eax, %ecx
jbe 0x10f56
movq 0x18(%r14), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %eax, %eax
movb %bpl, (%rcx,%rax)
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rax
movb %bpl, (%rax,%rdx)
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x10f1c
movq 0x18(%rsp), %rax
shlq $0x6, %rax
addq 0xa062(%rip), %rax      # 0x1afd0
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x3c(%rax)
movss 0x4365(%rip), %xmm0     # 0x152e4
movss %xmm0, 0x10(%rsp)
movss 0x4353(%rip), %xmm0     # 0x152e0
movss %xmm0, 0xc(%rsp)
movaps 0x42f6(%rip), %xmm0     # 0x15290
movaps %xmm0, 0x30(%rsp)
movaps 0x42da(%rip), %xmm0     # 0x15280
movaps %xmm0, 0x40(%rsp)
je 0x11111
movq 0x28(%rsp), %rax
movslq 0x38(%rax), %rax
leaq (%rax,%rax,4), %rbx
shlq $0x2, %rbx
addq 0xa01f(%rip), %rbx      # 0x1afe8
xorl %r14d, %r14d
movss 0x430c(%rip), %xmm0     # 0x152e0
movss %xmm0, 0xc(%rsp)
movss 0x4302(%rip), %xmm0     # 0x152e4
movss %xmm0, 0x10(%rsp)
movaps 0x42a1(%rip), %xmm0     # 0x15290
movaps %xmm0, 0x30(%rsp)
movaps 0x4285(%rip), %xmm0     # 0x15280
movaps %xmm0, 0x40(%rsp)
movl $0x20, %edi
callq 0x3230
movq %rax, %rbp
movswl 0x8(%rbx), %esi
movq %rax, %rdi
callq 0xaf26
cmpw $0x0, 0x8(%rbx)
jle 0x1108d
xorl %eax, %eax
xorl %ecx, %ecx
movslq 0x4(%rbx), %rdx
addq %rcx, %rdx
movslq (%r15,%rdx,4), %rdx
movl %edx, %esi
negl %esi
testq %rdx, %rdx
leaq 0x2(%r12,%rsi,4), %rsi
leaq (%r12,%rdx,4), %rdx
cmovsq %rsi, %rdx
movzwl (%rdx), %edx
leaq (%rdx,%rdx,2), %rdx
movss (%r13,%rdx,4), %xmm0
movq 0x10(%rbp), %rsi
movss %xmm0, (%rsi,%rax)
movss 0x4(%r13,%rdx,4), %xmm0
movq 0x10(%rbp), %rsi
movss %xmm0, 0x4(%rsi,%rax)
movss 0x8(%r13,%rdx,4), %xmm0
movq 0x10(%rbp), %rdx
movss %xmm0, 0x8(%rdx,%rax)
incq %rcx
movswq 0x8(%rbx), %rdx
addq $0xc, %rax
cmpq %rdx, %rcx
jl 0x11024
movl 0x8(%rbp), %ecx
testq %rcx, %rcx
movss 0x10(%rsp), %xmm1
movss 0xc(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
movaps 0x30(%rsp), %xmm4
je 0x110db
movq 0x10(%rbp), %rax
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movsd (%rax,%rdx), %xmm0
minps %xmm0, %xmm4
maxps %xmm0, %xmm3
movss 0x8(%rax,%rdx), %xmm0
minss %xmm0, %xmm2
maxss %xmm0, %xmm1
addq $0xc, %rdx
cmpq %rdx, %rcx
jne 0x110b9
movaps %xmm4, 0x30(%rsp)
movaps %xmm3, 0x40(%rsp)
movss %xmm2, 0xc(%rsp)
movss %xmm1, 0x10(%rsp)
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x8(%rax)
incl %r14d
addq $0x14, %rbx
movq 0x28(%rsp), %rax
cmpl 0x3c(%rax), %r14d
jb 0x11000
movq 0x50(%rsp), %r14
movl 0x14(%rsp), %eax
cmpl %eax, 0x8(%r14)
movss 0x10(%rsp), %xmm5
movss 0xc(%rsp), %xmm2
movaps 0x40(%rsp), %xmm4
movaps 0x30(%rsp), %xmm1
jbe 0x11158
movq 0x20(%r14), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movlps %xmm1, (%rax,%rcx,8)
movss %xmm2, 0x8(%rax,%rcx,8)
movlps %xmm4, 0xc(%rax,%rcx,8)
movss %xmm5, 0x14(%rax,%rcx,8)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm2, %xmm2
xorps %xmm3, %xmm3
cvtss2sd %xmm4, %xmm3
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
cvtss2sd %xmm4, %xmm4
cvtss2sd %xmm5, %xmm5
leaq 0x5075(%rip), %rdi      # 0x161fa
movl 0x14(%rsp), %esi
movb $0x6, %al
callq 0x89c6
movq 0x18(%rsp), %rbx
incq %rbx
leaq 0xb111(%rip), %rax      # 0x1c2b0
movl (%rax), %eax
cmpq %rax, %rbx
jb 0x10eb9
jmp 0x111af
xorl %r14d, %r14d
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rax, %r14
movl $0x28, %esi
jmp 0x111d9
movq %rax, %r14
movl $0x20, %esi
movq %rbp, %rdi
callq 0x3240
movq %r14, %rdi
callq 0x3410