// File: /workspace/github_cpp_makefile_star2_O1/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 0x6466
leaq 0xafa9(%rip), %rax      # 0x1c2c0
cmpl $0x0, (%rax)
je 0x11395
leaq 0x12f5(%rip), %rbx      # 0x12618
leaq 0x4eb9(%rip), %r14      # 0x161e3
leaq 0x4ebb(%rip), %r15      # 0x161ec
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %r13d, %edi
callq 0x6fe9
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x62f1
movq %rax, %rdi
movq %r14, %rsi
callq 0x3260
testl %eax, %eax
jne 0x11384
movq %r12, %rdi
movq %r15, %rsi
callq 0x62f1
movq %rax, %rdi
callq 0x33d0
testl %eax, %eax
je 0x11376
incl %ebp
jmp 0x11384
leaq 0x4e74(%rip), %rdi      # 0x161f1
xorl %eax, %eax
callq 0x8d9c
incl %r13d
leaq 0xaf32(%rip), %rax      # 0x1c2c0
cmpl (%rax), %r13d
jb 0x11336
jmp 0x11397
xorl %ebp, %ebp
testl %ebp, %ebp
je 0x116d5
movl $0x28, %edi
callq 0x3240
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
callq 0x11710
leaq 0xaf03(%rip), %rax      # 0x1c2c0
cmpl $0x0, (%rax)
je 0x116d8
xorl %ebx, %ebx
leaq 0x1e0ceb1(%rip), %r15   # 0x1e1e280
leaq 0x1cf2e8a(%rip), %r12   # 0x1d04260
leaq 0xff2e83(%rip), %r13    # 0x1004260
movq %r14, 0x50(%rsp)
movl %ebx, %edi
callq 0x6fe9
movq %rax, %rbp
movq %rax, %rdi
leaq 0x1222(%rip), %rsi      # 0x12618
callq 0x62f1
movq %rax, %rdi
leaq 0x4dde(%rip), %rsi      # 0x161e3
callq 0x3260
testl %eax, %eax
jne 0x116be
movq %rbx, 0x18(%rsp)
movq %rbp, %rdi
leaq 0x4dcb(%rip), %rsi      # 0x161ec
callq 0x62f1
movq %rax, %rdi
callq 0x33d0
movq 0x18(%rbp), %rbx
movl %eax, 0x14(%rsp)
movl %eax, %eax
movq %rax, 0x20(%rsp)
testq %rbx, %rbx
movb $0x1, %bpl
je 0x11487
movq 0x8(%rbx), %rdi
callq 0x33d0
testl %eax, %eax
je 0x1147f
movl 0x8(%r14), %ecx
cmpl 0x14(%rsp), %ecx
jbe 0x1147f
cmpl %eax, %ecx
jbe 0x1147f
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 0x11445
movq 0x18(%rsp), %rax
shlq $0x6, %rax
addq 0x9b39(%rip), %rax      # 0x1afd0
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x3c(%rax)
movss 0x3e4c(%rip), %xmm0     # 0x152f4
movss %xmm0, 0x10(%rsp)
movss 0x3e3a(%rip), %xmm0     # 0x152f0
movss %xmm0, 0xc(%rsp)
movaps 0x3ded(%rip), %xmm0     # 0x152b0
movaps %xmm0, 0x30(%rsp)
movaps 0x3dd1(%rip), %xmm0     # 0x152a0
movaps %xmm0, 0x40(%rsp)
je 0x1163a
movq 0x28(%rsp), %rax
movslq 0x38(%rax), %rax
leaq (%rax,%rax,4), %rbx
shlq $0x2, %rbx
addq 0x9af6(%rip), %rbx      # 0x1afe8
xorl %r14d, %r14d
movss 0x3df3(%rip), %xmm0     # 0x152f0
movss %xmm0, 0xc(%rsp)
movss 0x3de9(%rip), %xmm0     # 0x152f4
movss %xmm0, 0x10(%rsp)
movaps 0x3d98(%rip), %xmm0     # 0x152b0
movaps %xmm0, 0x30(%rsp)
movaps 0x3d7c(%rip), %xmm0     # 0x152a0
movaps %xmm0, 0x40(%rsp)
movl $0x20, %edi
callq 0x3240
movq %rax, %rbp
movswl 0x8(%rbx), %esi
movq %rax, %rdi
callq 0xb0f2
cmpw $0x0, 0x8(%rbx)
jle 0x115b6
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 0x1154d
movl 0x8(%rbp), %ecx
testq %rcx, %rcx
movss 0x10(%rsp), %xmm1
movss 0xc(%rsp), %xmm2
movaps 0x40(%rsp), %xmm3
movaps 0x30(%rsp), %xmm4
je 0x11604
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 0x115e2
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 0x11529
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 0x11681
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 0x4b5f(%rip), %rdi      # 0x1620d
movl 0x14(%rsp), %esi
movb $0x6, %al
callq 0x8aae
movq 0x18(%rsp), %rbx
incq %rbx
leaq 0xabf8(%rip), %rax      # 0x1c2c0
movl (%rax), %eax
cmpq %rax, %rbx
jb 0x113e2
jmp 0x116d8
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 0x11702
movq %rax, %r14
movl $0x20, %esi
movq %rbp, %rdi
callq 0x3250
movq %r14, %rdi
callq 0x3420
nop