// File: /workspace/github_cpp_makefile_star2_O1/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 0x14638
cmpl $-0x2, 0xa0(%rbx)
je 0x14626
movq 0xb0(%rbx), %r15
testq %r15, %r15
je 0x14626
leaq 0xe19b(%rip), %r14      # 0x22448
movq %rbx, 0x40(%rsp)
movq 0x68(%r15), %r12
testq %r12, %r12
je 0x1460f
movq 0x48(%r15), %rax
cmpq %rbx, %rax
jne 0x1460f
movl 0xa0(%rax), %eax
movq 0x50(%r15), %rcx
cmpl 0xa0(%rcx), %eax
jne 0x1460f
leaq 0x48(%r15), %rbp
leaq 0x50(%r15), %r13
movq %r12, %rdi
leaq 0x78(%rsp), %rsi
callq 0xb766
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 0xdfbb(%rip), %xmm1     # 0x222f0
ucomisd %xmm0, %xmm1
jbe 0x14369
ucomisd 0xdfb5(%rip), %xmm0     # 0x222f8
leaq 0xe0d6(%rip), %rdi      # 0x22420
leaq 0xe0bd(%rip), %rax      # 0x2240e
cmovaq %rax, %rdi
xorl %eax, %eax
callq 0xa2f6
movq %r12, %rdi
callq 0xb708
movq %r13, %rax
jmp 0x1436f
movq %rbp, %rax
movq %r13, %rbp
movq 0x20bb67a(%rip), %rdi   # 0x20cf9f0
movl 0x8(%r12), %edx
movq (%rax), %rax
movl 0xb8(%rax), %ecx
movq (%rbp), %rax
movl 0xb8(%rax), %r8d
leaq 0xe09c(%rip), %rsi      # 0x22432
xorl %eax, %eax
callq 0x4440
cmpl $0x0, 0x8(%r12)
leaq 0xe092(%rip), %r13      # 0x2243c
je 0x143ef
movl $0x10, %r15d
xorl %ebp, %ebp
movq 0x20bb635(%rip), %rdi   # 0x20cf9f0
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 0x143b4
movq 0x20bb5fa(%rip), %rsi   # 0x20cf9f0
movl $0xa, %edi
callq 0x43d0
leaq 0x20c0614(%rip), %rax   # 0x20d4a1b
cmpb $0x1, (%rax)
movq 0x20(%rsp), %r15
jne 0x1460f
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0xbc26
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
movsd %xmm0, 0x18(%rsp)
movapd %xmm0, %xmm4
movsd 0xce21(%rip), %xmm0     # 0x21260
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 0x20bb552(%rip), %rdi   # 0x20cf9f8
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r14, %rsi
movsd 0xde4f(%rip), %xmm2     # 0x22308
movb $0x3, %al
callq 0x4440
movq 0x20bb531(%rip), %rdi   # 0x20cf9f8
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 0x14605
movsd 0xde08(%rip), %xmm0     # 0x22300
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 0x20bb495(%rip), %rdi   # 0x20cf9f8
movsd -0x10(%rbx,%r15), %xmm0
movsd -0x8(%rbx,%r15), %xmm1
movsd (%rbx,%r15), %xmm2
movq %r14, %rsi
movb $0x3, %al
callq 0x4440
movq 0x20bb470(%rip), %rdi   # 0x20cf9f8
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 0x20bb44b(%rip), %rdi   # 0x20cf9f8
movq %r14, %rsi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x3, %al
callq 0x4440
movq 0x20bb428(%rip), %rdi   # 0x20cf9f8
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 0x14545
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 0x142b2
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%rbx), %rdi
callq 0x1426b
movq 0x90(%rbx), %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1426b