// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, %rbx
xorl %eax, %eax
movsd 0xd6ac(%rip), %xmm0     # 0x212d8
movsd 0xd6ac(%rip), %xmm1     # 0x212e0
movsd (%rsi,%rax,8), %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rsp,%rax,8)
movsd (%rdx,%rax,8), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x18(%rsp,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x13c34
movl $0xfffffffe, 0x20bad4c(%rip) # imm = 0xFFFFFFFE
movq $0x0, 0x20bad51(%rip) # 0x20ce9c0
xorl %ebp, %ebp
movb $0x1, %r14b
xorl %r12d, %r12d
addq %rbp, %r12
callq 0x14e62
movq %rax, %r15
movq %rax, 0x30(%rsp,%r12,8)
shlq $0x6, %r12
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp,%r12)
movapd %xmm0, 0x70(%rsp,%r12)
movapd %xmm0, 0x80(%rsp,%r12)
movapd %xmm0, 0x90(%rsp,%r12)
testb $0x1, %r14b
je 0x13cc6
movsd (%rsp,%rbp,8), %xmm0
movsd 0xc404(%rip), %xmm1     # 0x200c8
jmp 0x13cdb
movsd 0x18(%rsp,%rbp,8), %xmm0
xorps 0xc5dd(%rip), %xmm0     # 0x202b0
movsd 0xc59d(%rip), %xmm1     # 0x20278
leaq (%rsp,%r12), %r13
addq $0x60, %r13
movsd %xmm1, (%r13,%rbp,8)
movsd %xmm0, 0x30(%r13)
movups (%r13), %xmm0
movupd 0x10(%r13), %xmm1
movupd 0x20(%r13), %xmm2
movupd %xmm2, 0x20(%r15)
movupd %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
movupd 0x30(%r13), %xmm0
movupd %xmm0, 0x30(%r15)
movl $0x20, %edi
callq 0x42f0
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
callq 0xc710
movq %r12, 0x68(%r15)
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x20babca(%rip), %rdx   # 0x20ce910
callq 0x13b0c
movl $0x3, %r12d
testb $0x1, %r14b
movl $0x0, %r14d
jne 0x13c77
incq %rbp
cmpq $0x3, %rbp
jne 0x13c71
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x13d9e
movq 0x30(%rsp,%r14,8), %rax
movq 0x68(%rax), %rdi
leaq (%rsp,%r15), %rsi
addq $0x60, %rsi
movl $0x1, %edx
movsd 0xc6e7(%rip), %xmm0     # 0x20480
callq 0xcea2
addq $0x40, %r15
cmpq $0x180, %r15            # imm = 0x180
jne 0x13d76
incq %r14
addq $0x40, %rbx
cmpq $0x6, %r14
jne 0x13d73
addq $0x1e8, %rsp            # imm = 0x1E8
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