// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movl %edx, %ebp
movq %rsi, %r14
movl %edi, %r15d
callq 0xb551
testl %r15d, %r15d
jne 0x15602
incl 0x61b8052(%rip)         # 0x61cd654
movq 0x18(%r14), %rbx
movslq %r15d, %r12
leaq 0x61b8050(%rip), %r13   # 0x61cd660
movq (%r13,%r12,8), %rdi
movl 0x8(%r14), %ecx
movl 0x20(%r14), %r8d
movq %r14, 0x8(%rsp)
movl 0x28(%r14), %r9d
movl 0x8(%rbx), %eax
movl %eax, (%rsp)
leaq 0xb2b6(%rip), %rsi      # 0x208e9
movl %ebp, %edx
xorl %eax, %eax
callq 0x4460
cmpl $0x0, 0x8(%rbx)
je 0x15684
movl $0x10, %ebp
xorl %r14d, %r14d
leaq 0xb2a8(%rip), %r15      # 0x208f9
movq (%r13,%r12,8), %rdi
movq 0x10(%rbx), %rax
movsd -0x10(%rax,%rbp), %xmm0
movsd -0x8(%rax,%rbp), %xmm1
movsd (%rax,%rbp), %xmm2
movq %r15, %rsi
movb $0x3, %al
callq 0x4460
incq %r14
movl 0x8(%rbx), %eax
addq $0x18, %rbp
cmpq %rax, %r14
jb 0x15651
movq (%r13,%r12,8), %rsi
movl $0xa, %edi
callq 0x43e0
cmpb $0x1, 0x61b7fb9(%rip)   # 0x61cd653
jne 0x15835
movb 0x61b7fda(%rip), %al    # 0x61cd680
movl %eax, %ecx
xorb $0x1, %cl
movb %cl, 0x61b7fcf(%rip)    # 0x61cd680
testb %al, %al
jne 0x15835
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbd96
movq 0x8(%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 0x61b7f98(%rip), %rax   # 0x61cd690
movq (%rax,%r12,8), %rdi
leaq 0xb209(%rip), %rsi      # 0x2090c
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x30(%rsp)
movsd %xmm2, 0x28(%rsp)
movb $0x3, %al
callq 0x4460
movl 0x8(%rbx), %eax
testl %eax, %eax
je 0x157e7
movl $0x10, %r13d
movl $0x1, %ebp
movq 0x10(%rbx), %r15
movl %eax, %eax
cmpq %rax, %rbp
movq %rbp, %rax
movl $0x0, %ecx
cmoveq %rcx, %rax
leaq (%rax,%rax,2), %r14
leaq 0x61b7f3e(%rip), %rax   # 0x61cd690
movq (%rax,%r12,8), %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0xb19d(%rip), %rsi      # 0x2090c
movb $0x3, %al
callq 0x4460
leaq 0x61b7f13(%rip), %rax   # 0x61cd690
movq (%rax,%r12,8), %rdi
movsd -0x10(%r15,%r13), %xmm0
movsd -0x8(%r15,%r13), %xmm1
movsd (%r15,%r13), %xmm2
leaq 0xb170(%rip), %rsi      # 0x2090c
movb $0x3, %al
callq 0x4460
leaq 0x61b7ee6(%rip), %rax   # 0x61cd690
movq (%rax,%r12,8), %rdi
movsd (%r15,%r14,8), %xmm0
movsd 0x8(%r15,%r14,8), %xmm1
movsd 0x10(%r15,%r14,8), %xmm2
leaq 0xb143(%rip), %rsi      # 0x2090c
movb $0x3, %al
callq 0x4460
movl 0x8(%rbx), %eax
addq $0x18, %r13
leaq 0x1(%rbp), %rcx
cmpq %rax, %rbp
movq %rcx, %rbp
jb 0x15732
leaq 0x61b7ea2(%rip), %r14   # 0x61cd690
movq (%r14,%r12,8), %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0xb101(%rip), %rbx      # 0x2090c
movq %rbx, %rsi
movb $0x3, %al
callq 0x4460
movq (%r14,%r12,8), %rdi
movq %rbx, %rsi
movsd 0x8(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movb $0x3, %al
callq 0x4460
callq 0xb562
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq