// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlcsg/qcsg.cpp
// Function: WriteFace(int, bface_s const*, int)
void            WriteFace(const int hull, const bface_t* const f
#ifdef ZHLT_DETAILBRUSH
						  , int detaillevel
#endif
						  )
{
    unsigned int    i;
    Winding*        w;

    ThreadLock();
    if (!hull)
        c_csgfaces++;

    // .p0 format
    w = f->w;

    // plane summary
#ifdef ZHLT_DETAILBRUSH
	fprintf (out[hull], "%i %i %i %i %u\n", detaillevel, f->planenum, f->texinfo, f->contents, w->m_NumPoints);
#else
    fprintf(out[hull], "%i %i %i %u\n", f->planenum, f->texinfo, f->contents, w->m_NumPoints);
#endif

    // for each of the points on the face
    for (i = 0; i < w->m_NumPoints; i++)
    {
        // write the co-ords
#ifdef HLCSG_PRICISION_FIX
        fprintf(out[hull], "%5.8f %5.8f %5.8f\n", w->m_Points[i][0], w->m_Points[i][1], w->m_Points[i][2]);
#else
        fprintf(out[hull], "%5.2f %5.2f %5.2f\n", w->m_Points[i][0], w->m_Points[i][1], w->m_Points[i][2]);
#endif
    }

    // put in an extra line break
    fprintf(out[hull], "\n");
#ifdef HLCSG_VIEWSURFACE
	if (g_viewsurface)
	{
		static bool side = false;
		side = !side;
		if (side)
		{
			vec3_t center, center2;
			w->getCenter (center);
			VectorAdd (center, f->plane->normal, center2);
			fprintf (out_view[hull], "%5.2f %5.2f %5.2f\n", center2[0], center2[1], center2[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 (out_view[hull], "%5.2f %5.2f %5.2f\n", center[0], center[1], center[2]);
				fprintf (out_view[hull], "%5.2f %5.2f %5.2f\n", p1[0], p1[1], p1[2]);
				fprintf (out_view[hull], "%5.2f %5.2f %5.2f\n", p2[0], p2[1], p2[2]);
			}
			fprintf (out_view[hull], "%5.2f %5.2f %5.2f\n", center[0], center[1], center[2]);
			fprintf (out_view[hull], "%5.2f %5.2f %5.2f\n", center2[0], center2[1], center2[2]);
		}
	}
#endif

    ThreadUnlock();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0x18(%rsp)
movq %rsi, %r14
movl %edi, %r15d
callq 0xa058
testl %r15d, %r15d
jne 0x13191
incl 0x61b84d3(%rip)         # 0x61cb664
movq 0x18(%r14), %rbx
movslq %r15d, %r12
leaq 0x61b84d1(%rip), %r13   # 0x61cb670
movq (%r13,%r12,8), %rdi
movl 0x8(%r14), %ecx
movl 0x20(%r14), %r8d
movq %r14, 0x10(%rsp)
movl 0x28(%r14), %r9d
movl 0x8(%rbx), %eax
movl %eax, (%rsp)
leaq 0xa617(%rip), %rsi      # 0x1d7d9
xorl %ebp, %ebp
movl 0x18(%rsp), %edx
xorl %eax, %eax
callq 0x44a0
pushq $0x10
popq %r14
leaq 0xa60f(%rip), %r15      # 0x1d7e9
movl 0x8(%rbx), %eax
movq (%r13,%r12,8), %rsi
cmpq %rax, %rbp
jae 0x13215
movq 0x10(%rbx), %rax
movsd -0x10(%rax,%r14), %xmm0
movsd -0x8(%rax,%r14), %xmm1
movsd (%rax,%r14), %xmm2
movq %rsi, %rdi
movq %r15, %rsi
movb $0x3, %al
callq 0x44a0
incq %rbp
addq $0x18, %r14
jmp 0x131da
pushq $0xa
popq %rdi
callq 0x4400
cmpb $0x1, 0x61b843f(%rip)   # 0x61cb663
jne 0x133ab
movb 0x61b8460(%rip), %al    # 0x61cb690
movl %eax, %ecx
xorb $0x1, %cl
movb %cl, 0x61b8455(%rip)    # 0x61cb690
testb %al, %al
jne 0x133ab
leaq 0x20(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa79e
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movsd (%r15), %xmm0
addsd (%rax), %xmm0
movsd 0x8(%r15), %xmm1
addsd 0x8(%rax), %xmm1
movsd 0x10(%r15), %xmm2
addsd 0x10(%rax), %xmm2
leaq 0x61b841e(%rip), %rax   # 0x61cb6a0
movq (%rax,%r12,8), %rdi
leaq 0xa56f(%rip), %rsi      # 0x1d7fc
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm2, 0x40(%rsp)
movb $0x3, %al
callq 0x44a0
pushq $0x10
popq %r13
xorl %ebp, %ebp
movl 0x8(%rbx), %eax
cmpq %rax, %rbp
jae 0x1335d
movq 0x10(%rbx), %r15
incq %rbp
cmpq %rax, %rbp
movl $0x0, %eax
cmovneq %rbp, %rax
imulq $0x18, %rax, %r14
leaq 0x61b83ca(%rip), %rax   # 0x61cb6a0
movq (%rax,%r12,8), %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
leaq 0xa509(%rip), %rsi      # 0x1d7fc
movb $0x3, %al
callq 0x44a0
leaq 0x61b839f(%rip), %rax   # 0x61cb6a0
movq (%rax,%r12,8), %rdi
movsd -0x10(%r15,%r13), %xmm0
movsd -0x8(%r15,%r13), %xmm1
movsd (%r15,%r13), %xmm2
leaq 0xa4dc(%rip), %rsi      # 0x1d7fc
movb $0x3, %al
callq 0x44a0
leaq 0x61b8372(%rip), %rax   # 0x61cb6a0
movq (%rax,%r12,8), %rdi
movsd (%r15,%r14), %xmm0
movsd 0x8(%r15,%r14), %xmm1
movsd 0x10(%r15,%r14), %xmm2
leaq 0xa4af(%rip), %rsi      # 0x1d7fc
movb $0x3, %al
callq 0x44a0
addq $0x18, %r13
jmp 0x132ac
leaq 0x61b833c(%rip), %r14   # 0x61cb6a0
movq (%r14,%r12,8), %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
leaq 0xa47b(%rip), %rbx      # 0x1d7fc
movq %rbx, %rsi
movb $0x3, %al
callq 0x44a0
movq (%r14,%r12,8), %rdi
movq %rbx, %rsi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movb $0x3, %al
callq 0x44a0
callq 0xa069
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq