// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
xorl %eax, %eax
movsd 0xe496(%rip), %xmm0     # 0x222e0
movsd 0xe496(%rip), %xmm1     # 0x222e8
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
cmpq $0x3, %rax
jne 0x13e52
movl $0xfffffffe, 0x20bbb3d(%rip) # imm = 0xFFFFFFFE
movq $0x0, 0x20bbb42(%rip) # 0x20cf9d0
leaq 0x80(%rsp), %rbp
leaq 0x50(%rsp), %rbx
movq $0x0, (%rsp)
movq %rbp, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
xorl %r14d, %r14d
callq 0x150f5
movq %rax, %r15
movq %rax, (%rbx)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rbp,%r14)
movapd %xmm0, 0x10(%rbp,%r14)
movapd %xmm0, 0x20(%rbp,%r14)
movapd %xmm0, 0x30(%rbp,%r14)
testq %r14, %r14
je 0x13f06
movq 0x8(%rsp), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, (%rax,%r14)
movq (%rsp), %rax
movsd 0x38(%rsp,%rax,8), %xmm0
xorps 0xd3cc(%rip), %xmm0     # 0x212d0
jmp 0x13f23
movq 0x8(%rsp), %rax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax,%r14)
movq (%rsp), %rax
movsd 0x20(%rsp,%rax,8), %xmm0
leaq (%r14,%rbp), %r13
movsd %xmm0, 0x30(%rbp,%r14)
movupd (%r13), %xmm0
movupd 0x10(%r13), %xmm1
movupd 0x20(%r13), %xmm2
movups 0x30(%r13), %xmm3
movups %xmm3, 0x30(%r15)
movupd %xmm2, 0x20(%r15)
movupd %xmm1, 0x10(%r15)
movupd %xmm0, (%r15)
movl $0x20, %edi
callq 0x42f0
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
callq 0xc8e2
movq %r12, 0x68(%r15)
movq %r15, %rdi
movq 0x18(%rsp), %rsi
leaq 0x20bb99a(%rip), %rdx   # 0x20cf920
callq 0x13d28
movl $0xc0, %eax
addq %rax, %r14
addq $0x18, %rbx
cmpq %rax, %r14
je 0x13eb0
movq (%rsp), %rcx
incq %rcx
addq $0x40, %rbp
addq $0x48, 0x8(%rsp)
movq 0x10(%rsp), %rbx
addq $0x8, %rbx
movq %rcx, (%rsp)
cmpq $0x3, %rcx
jne 0x13ea8
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x13ffb
movq 0x50(%rsp,%r14,8), %rax
movq 0x68(%rax), %rdi
leaq (%rsp,%r15), %rsi
addq $0x80, %rsi
movl $0x1, %edx
movsd 0xd49a(%rip), %xmm0     # 0x21490
callq 0xd070
addq $0x40, %r15
cmpq $0x180, %r15            # imm = 0x180
jne 0x13fd0
incq %r14
addq $0x40, %rbx
cmpq $0x6, %r14
jne 0x13fcd
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x20, %esi
movq %r12, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4540