// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlbsp/portals.cpp
// Function: WritePortalFile_r(node_s const*)
static void     WritePortalFile_r(const node_t* const node)
{
    int             i;
    portal_t*       p;
    Winding*        w;
    dplane_t        plane2;

#ifdef ZHLT_DETAILBRUSH
	if (!node->isportalleaf)
#else
    if (!node->contents)
#endif
    {
        WritePortalFile_r(node->children[0]);
        WritePortalFile_r(node->children[1]);
        return;
    }

    if (node->contents == CONTENTS_SOLID)
    {
        return;
    }

    for (p = node->portals; p;)
    {
        w = p->winding;
        if (w && p->nodes[0] == node)
        {
            if (p->nodes[0]->contents == p->nodes[1]->contents)
            {
                // write out to the file

                // sometimes planes get turned around when they are very near
                // the changeover point between different axis.  interpret the
                // plane the same way vis will, and flip the side orders if needed
                w->getPlane(plane2);
                if (DotProduct(p->plane.normal, plane2.normal) < 1.0 - ON_EPSILON)
                {                                          // backwards...
#ifdef ZHLT_WINDING_FIX
					if (DotProduct(p->plane.normal, plane2.normal) > -1.0 + ON_EPSILON)
					{
						Warning ("Colinear portal @");
						w->Print ();
					}
					else
					{
						Warning ("Backward portal @");
						w->Print ();
					}
#endif
                    fprintf(pf, "%u %i %i ", w->m_NumPoints, p->nodes[1]->visleafnum, p->nodes[0]->visleafnum);
                }
                else
                {
                    fprintf(pf, "%u %i %i ", w->m_NumPoints, p->nodes[0]->visleafnum, p->nodes[1]->visleafnum);
                }

                for (i = 0; i < w->m_NumPoints; i++)
                {
                    fprintf(pf, "(%f %f %f) ", w->m_Points[i][0], w->m_Points[i][1], w->m_Points[i][2]);
                }
                fprintf(pf, "\n");
#ifdef HLBSP_VIEWPORTAL
				if (g_viewportal)
				{
					vec3_t center, center1, center2;
					vec3_t from = {0.0, 0.0, -65536};
					w->getCenter (center);
					VectorMA (center, 0.5, p->plane.normal, center1);
					VectorMA (center, -0.5, p->plane.normal, center2);
					fprintf (pf_view, "%5.2f %5.2f %5.2f\n", from[0], from[1], from[2]);
					fprintf (pf_view, "%5.2f %5.2f %5.2f\n", center1[0], center1[1], center1[2]);
					for (i = 0; i < w->m_NumPoints; i++)
					{
						vec_t *p1, *p2;
						p1 = w->m_Points[i];
						p2 = w->m_Points[(i+1)%w->m_NumPoints];
						fprintf (pf_view, "%5.2f %5.2f %5.2f\n", p1[0], p1[1], p1[2]);
						fprintf (pf_view, "%5.2f %5.2f %5.2f\n", p2[0], p2[1], p2[2]);
						fprintf (pf_view, "%5.2f %5.2f %5.2f\n", center2[0], center2[1], center2[2]);
						fprintf (pf_view, "%5.2f %5.2f %5.2f\n", center1[0], center1[1], center1[2]);
					}
				}
#endif
            }
        }

        if (p->nodes[0] == node)
        {
            p = p->next[0];
        }
        else
        {
            p = p->next[1];
        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
cmpb $0x0, 0x49(%rdi)
je 0x143e3
cmpl $-0x2, 0xa0(%rbx)
je 0x143d1
movq 0xb0(%rbx), %r15
testq %r15, %r15
je 0x143d1
leaq 0xd3e8(%rip), %r14      # 0x21440
movq %rbx, 0x40(%rsp)
movq 0x68(%r15), %r12
testq %r12, %r12
je 0x143ba
movq 0x48(%r15), %rax
cmpq %rbx, %rax
jne 0x143ba
movl 0xa0(%rax), %eax
movq 0x50(%r15), %rcx
cmpl 0xa0(%rcx), %eax
jne 0x143ba
leaq 0x48(%r15), %rbp
leaq 0x50(%r15), %r13
movq %r12, %rdi
leaq 0x78(%rsp), %rsi
callq 0xb672
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm2
mulsd 0x80(%rsp), %xmm2
mulsd 0x78(%rsp), %xmm1
movq %r15, 0x20(%rsp)
movsd 0x10(%r15), %xmm0
mulsd 0x88(%rsp), %xmm0
addsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd 0xd208(%rip), %xmm1     # 0x212e8
ucomisd %xmm0, %xmm1
jbe 0x14114
ucomisd 0xd202(%rip), %xmm0     # 0x212f0
leaq 0xd323(%rip), %rdi      # 0x21418
leaq 0xd30a(%rip), %rax      # 0x21406
cmovaq %rax, %rdi
xorl %eax, %eax
callq 0xa20e
movq %r12, %rdi
callq 0xb614
movq %r13, %rax
jmp 0x1411a
movq %rbp, %rax
movq %r13, %rbp
movq 0x20ba8bf(%rip), %rdi   # 0x20ce9e0
movl 0x8(%r12), %edx
movq (%rax), %rax
movl 0xb8(%rax), %ecx
movq (%rbp), %rax
movl 0xb8(%rax), %r8d
leaq 0xd2e9(%rip), %rsi      # 0x2142a
xorl %eax, %eax
callq 0x4440
cmpl $0x0, 0x8(%r12)
leaq 0xd2df(%rip), %r13      # 0x21434
je 0x1419a
movl $0x10, %r15d
xorl %ebp, %ebp
movq 0x20ba87a(%rip), %rdi   # 0x20ce9e0
movq 0x10(%r12), %rax
movsd -0x10(%rax,%r15), %xmm0
movsd -0x8(%rax,%r15), %xmm1
movsd (%rax,%r15), %xmm2
movq %r13, %rsi
movb $0x3, %al
callq 0x4440
incq %rbp
movl 0x8(%r12), %eax
addq $0x18, %r15
cmpq %rax, %rbp
jb 0x1415f
movq 0x20ba83f(%rip), %rsi   # 0x20ce9e0
movl $0xa, %edi
callq 0x43d0
leaq 0x20bf859(%rip), %rax   # 0x20d3a0b
cmpb $0x1, (%rax)
movq 0x20(%rsp), %r15
jne 0x143ba
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0xbab0
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
movsd %xmm0, 0x18(%rsp)
movapd %xmm0, %xmm4
movsd 0xc066(%rip), %xmm0     # 0x20250
mulsd %xmm0, %xmm4
movsd 0x60(%rsp), %xmm3
movsd 0x68(%rsp), %xmm2
movsd %xmm3, 0x50(%rsp)
addsd %xmm3, %xmm4
movsd %xmm4, 0x38(%rsp)
movsd %xmm1, 0x10(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm2, 0x58(%rsp)
addsd %xmm2, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x70(%rsp), %xmm2
movsd 0x10(%r15), %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm2, 0x48(%rsp)
addsd %xmm2, %xmm1
movsd %xmm1, 0x28(%rsp)
movq 0x20ba797(%rip), %rdi   # 0x20ce9e8
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r14, %rsi
movsd 0xd09c(%rip), %xmm2     # 0x21300
movb $0x3, %al
callq 0x4440
movq 0x20ba776(%rip), %rdi   # 0x20ce9e8
movq %r14, %rsi
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movb $0x3, %al
callq 0x4440
movl 0x8(%r12), %eax
testl %eax, %eax
je 0x143b0
movsd 0xd055(%rip), %xmm0     # 0x212f8
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x50(%rsp), %xmm1
movsd %xmm1, 0x18(%rsp)
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x58(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x48(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movl $0x10, %r15d
movl $0x1, %ebp
movq 0x10(%r12), %rbx
movl %eax, %eax
cmpq %rax, %rbp
movl $0x0, %eax
cmovneq %rbp, %rax
leaq (%rax,%rax,2), %r13
movq 0x20ba6da(%rip), %rdi   # 0x20ce9e8
movsd -0x10(%rbx,%r15), %xmm0
movsd -0x8(%rbx,%r15), %xmm1
movsd (%rbx,%r15), %xmm2
movq %r14, %rsi
movb $0x3, %al
callq 0x4440
movq 0x20ba6b5(%rip), %rdi   # 0x20ce9e8
movsd (%rbx,%r13,8), %xmm0
movsd 0x8(%rbx,%r13,8), %xmm1
movsd 0x10(%rbx,%r13,8), %xmm2
movq %r14, %rsi
movb $0x3, %al
callq 0x4440
movq 0x20ba690(%rip), %rdi   # 0x20ce9e8
movq %r14, %rsi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x3, %al
callq 0x4440
movq 0x20ba66d(%rip), %rdi   # 0x20ce9e8
movq %r14, %rsi
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movb $0x3, %al
callq 0x4440
movl 0x8(%r12), %eax
addq $0x18, %r15
leaq 0x1(%rbp), %rcx
cmpq %rax, %rbp
movq %rcx, %rbp
jb 0x142f0
movq 0x40(%rsp), %rbx
movq 0x20(%rsp), %r15
xorl %eax, %eax
cmpq %rbx, 0x48(%r15)
setne %al
movq 0x58(%r15,%rax,8), %r15
testq %r15, %r15
jne 0x1405d
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%rbx), %rdi
callq 0x14016
movq 0x90(%rbx), %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x14016