// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlbsp/portals.cpp
// Function: MakeHeadnodePortals(node_s*, double const*, double const*)
void            MakeHeadnodePortals(node_t* node, const vec3_t mins, const vec3_t maxs)
{
    vec3_t          bounds[2];
    int             i, j, n;
    portal_t*       p;
    portal_t*       portals[6];
    dplane_t        bplanes[6];
    dplane_t*       pl;

    // pad with some space so there will never be null volume leafs
    for (i = 0; i < 3; i++)
    {
        bounds[0][i] = mins[i] - SIDESPACE;
        bounds[1][i] = maxs[i] + SIDESPACE;
    }

    g_outside_node.contents = CONTENTS_SOLID;
    g_outside_node.portals = NULL;

    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < 2; j++)
        {
            n = j * 3 + i;

            p = AllocPortal();
            portals[n] = p;

            pl = &bplanes[n];
            memset(pl, 0, sizeof(*pl));
            if (j)
            {
                pl->normal[i] = -1;
                pl->dist = -bounds[j][i];
            }
            else
            {
                pl->normal[i] = 1;
                pl->dist = bounds[j][i];
            }
            p->plane = *pl;
            p->winding = new Winding(*pl);
            AddPortalToNodes(p, node, &g_outside_node);
        }
    }

    // clip the basewindings by all the other planes
    for (i = 0; i < 6; i++)
    {
        for (j = 0; j < 6; j++)
        {
            if (j == i)
            {
                continue;
            }
            portals[i]->winding->Clip(bplanes[j], true);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x10(%rsp)
xorl %eax, %eax
movsd 0xd392(%rip), %xmm0     # 0x1f238
movsd 0xd392(%rip), %xmm1     # 0x1f240
cmpq $0x3, %rax
je 0x11ed7
movsd (%rsi,%rax,8), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x20(%rsp,%rax,8)
movsd (%rdx,%rax,8), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x38(%rsp,%rax,8)
incq %rax
jmp 0x11eae
movl $0xfffffffe, 0x20bbadf(%rip) # imm = 0xFFFFFFFE
andq $0x0, 0x20bbae7(%rip)   # 0x20cd9d0
leaq 0x80(%rsp), %r14
leaq 0x50(%rsp), %r15
xorl %r13d, %r13d
movq %r14, (%rsp)
cmpq $0x3, %r13
je 0x12015
movq %r15, 0x8(%rsp)
xorl %ebx, %ebx
movq %r13, 0x18(%rsp)
cmpq $0x180, %rbx            # imm = 0x180
je 0x11ffb
callq 0x12fb8
movq %rax, %r12
movq %rax, (%r15)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14,%rbx)
movapd %xmm0, 0x10(%r14,%rbx)
movapd %xmm0, 0x20(%r14,%rbx)
movapd %xmm0, 0x30(%r14,%rbx)
testq %rbx, %rbx
je 0x11f67
movsd 0x38(%rsp,%r13,8), %xmm0
xorps 0xc2a3(%rip), %xmm0     # 0x1e200
movsd 0xc263(%rip), %xmm1     # 0x1e1c8
jmp 0x11f76
movsd 0x20(%rsp,%r13,8), %xmm0
movsd 0xc0b2(%rip), %xmm1     # 0x1e028
leaq (%r14,%rbx), %rbp
movq (%rsp), %rax
movsd %xmm1, (%rax,%rbx)
movsd %xmm0, 0x30(%r14,%rbx)
movupd (%rbp), %xmm0
movupd 0x10(%rbp), %xmm1
movupd 0x20(%rbp), %xmm2
movups 0x30(%rbp), %xmm3
movups %xmm3, 0x30(%r12)
movupd %xmm2, 0x20(%r12)
movupd %xmm1, 0x10(%r12)
movupd %xmm0, (%r12)
pushq $0x20
popq %rdi
callq 0x42f0
movq %rax, %r13
movq %rax, %rdi
movq %rbp, %rsi
callq 0xb018
movq %r13, 0x68(%r12)
movq %r12, %rdi
movq 0x10(%rsp), %rsi
leaq 0x20bb93f(%rip), %rdx   # 0x20cd920
callq 0x11d8c
addq $0xc0, %rbx
addq $0x18, %r15
movq 0x18(%rsp), %r13
jmp 0x11f13
incq %r13
addq $0x48, (%rsp)
addq $0x40, %r14
movq 0x8(%rsp), %r15
addq $0x8, %r15
jmp 0x11efd
xorl %r15d, %r15d
leaq 0x80(%rsp), %r12
pushq $0x1
popq %rbx
cmpq $0x6, %r15
je 0x12063
movq %r12, %r14
xorl %r13d, %r13d
cmpq $0x6, %r13
je 0x1205e
cmpq %r13, %r15
je 0x12055
movq 0x50(%rsp,%r15,8), %rax
movq 0x68(%rax), %rdi
movq %r14, %rsi
movl %ebx, %edx
movsd 0xc390(%rip), %xmm0     # 0x1e3e0
callq 0xb666
incq %r13
addq $0x40, %r14
jmp 0x1202f
incq %r15
jmp 0x12023
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x20
popq %rsi
movq %r13, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4550