// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movq %rdi, %rbx
cmpb $0x0, 0x49(%rdi)
je 0x122eb
cmpl $-0x2, 0xa0(%rbx)
jne 0x12311
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%rbx), %rdi
callq 0x122b6
movq 0x90(%rbx), %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x122b6
leaq 0xb0(%rbx), %rax
leaq 0xd081(%rip), %rbp      # 0x1f3a0
movq %rbx, (%rsp)
movq (%rax), %r15
testq %r15, %r15
je 0x122d9
movq 0x68(%r15), %r14
testq %r14, %r14
je 0x12609
movq 0x48(%r15), %rax
cmpq %rbx, %rax
jne 0x12609
movl 0xa0(%rax), %eax
movq 0x50(%r15), %rcx
cmpl 0xa0(%rcx), %eax
jne 0x12609
movq %r15, %rbx
addq $0x48, %r15
leaq 0x50(%rbx), %r12
movq %r14, %rdi
leaq 0x58(%rsp), %rsi
callq 0xa1a8
movsd (%rbx), %xmm1
movsd 0x8(%rbx), %xmm2
mulsd 0x60(%rsp), %xmm2
mulsd 0x58(%rsp), %xmm1
movq %rbx, 0x8(%rsp)
movsd 0x10(%rbx), %xmm0
mulsd 0x68(%rsp), %xmm0
addsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd 0xcea0(%rip), %xmm1     # 0x1f248
ucomisd %xmm0, %xmm1
jbe 0x123dc
ucomisd 0xce9a(%rip), %xmm0     # 0x1f250
leaq 0xcfbb(%rip), %rdi      # 0x1f378
leaq 0xcfa2(%rip), %rax      # 0x1f366
cmovaq %rax, %rdi
xorl %eax, %eax
callq 0x8e95
movq %r14, %rdi
callq 0xa150
movq %r12, %rax
jmp 0x123e2
movq %r15, %rax
movq %r12, %r15
leaq 0xcfab(%rip), %rbx      # 0x1f394
movq 0x20bb600(%rip), %rdi   # 0x20cd9f0
movl 0x8(%r14), %edx
movq (%rax), %rax
movl 0xb8(%rax), %ecx
movq (%r15), %rax
movl 0xb8(%rax), %r8d
leaq 0xcf7c(%rip), %rsi      # 0x1f38a
xorl %eax, %eax
callq 0x4450
pushq $0x10
popq %r15
xorl %r12d, %r12d
movl 0x8(%r14), %eax
movq 0x20bb5c9(%rip), %rsi   # 0x20cd9f0
cmpq %rax, %r12
jae 0x1245a
movq 0x10(%r14), %rax
movsd -0x10(%rax,%r15), %xmm0
movsd -0x8(%rax,%r15), %xmm1
movsd (%rax,%r15), %xmm2
movq %rsi, %rdi
movq %rbx, %rsi
movb $0x3, %al
callq 0x4450
incq %r12
addq $0x18, %r15
jmp 0x1241c
pushq $0xa
popq %rdi
callq 0x43e0
leaq 0x20c05b2(%rip), %rax   # 0x20d2a1b
cmpb $0x1, (%rax)
movq (%rsp), %rbx
movq 0x8(%rsp), %r15
jne 0x12609
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
callq 0xa53c
movsd (%r15), %xmm4
movsd 0x8(%r15), %xmm5
movapd %xmm4, %xmm2
movsd 0xbd11(%rip), %xmm3     # 0x1e1b0
mulsd %xmm3, %xmm2
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
addsd %xmm0, %xmm2
movsd %xmm2, 0x38(%rsp)
movapd %xmm5, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x30(%rsp)
movsd 0x50(%rsp), %xmm2
movsd 0x10(%r15), %xmm6
movapd %xmm6, %xmm7
mulsd %xmm3, %xmm7
addsd %xmm2, %xmm7
movsd %xmm7, 0x28(%rsp)
movsd 0xcd67(%rip), %xmm3     # 0x1f258
mulsd %xmm3, %xmm4
addsd %xmm0, %xmm4
movsd %xmm4, 0x20(%rsp)
mulsd %xmm3, %xmm5
addsd %xmm1, %xmm5
movsd %xmm5, 0x18(%rsp)
mulsd %xmm3, %xmm6
addsd %xmm2, %xmm6
movsd %xmm6, 0x10(%rsp)
movq 0x20bb4d6(%rip), %rdi   # 0x20cd9f8
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %rbp, %rsi
movsd 0xcd2b(%rip), %xmm2     # 0x1f260
movb $0x3, %al
callq 0x4450
pushq $0x10
popq %r15
xorl %r12d, %r12d
movq 0x20bb4ae(%rip), %rdi   # 0x20cd9f8
movq %rbp, %rsi
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movb $0x3, %al
callq 0x4450
movl 0x8(%r14), %eax
cmpq %rax, %r12
jae 0x12600
movq 0x10(%r14), %rbx
incq %r12
cmpq %rax, %r12
movl $0x0, %eax
cmovneq %r12, %rax
imulq $0x18, %rax, %r13
movq 0x20bb467(%rip), %rdi   # 0x20cd9f8
movsd -0x10(%rbx,%r15), %xmm0
movsd -0x8(%rbx,%r15), %xmm1
movsd (%rbx,%r15), %xmm2
movq %rbp, %rsi
movb $0x3, %al
callq 0x4450
movq 0x20bb442(%rip), %rdi   # 0x20cd9f8
movsd (%rbx,%r13), %xmm0
movsd 0x8(%rbx,%r13), %xmm1
movsd 0x10(%rbx,%r13), %xmm2
movq %rbp, %rsi
movb $0x3, %al
callq 0x4450
movq 0x20bb41d(%rip), %rdi   # 0x20cd9f8
movq %rbp, %rsi
movsd 0x20(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movb $0x3, %al
callq 0x4450
addq $0x18, %r15
jmp 0x12543
movq (%rsp), %rbx
movq 0x8(%rsp), %r15
xorl %eax, %eax
cmpq %rbx, 0x48(%r15)
setne %al
leaq (%r15,%rax,8), %rax
addq $0x58, %rax
jmp 0x12323