// File: /workspace/github_cpp_makefile_star2_O1/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 0xb695
testl %r15d, %r15d
jne 0x15b30
incl 0x61b7b34(%rip)         # 0x61cd664
movq 0x18(%r14), %rbx
movslq %r15d, %r12
leaq 0x61b7b32(%rip), %r13   # 0x61cd670
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 0xad63(%rip), %rsi      # 0x208c4
movl %ebp, %edx
xorl %eax, %eax
callq 0x4470
cmpl $0x0, 0x8(%rbx)
je 0x15bb2
movl $0x10, %ebp
xorl %r14d, %r14d
leaq 0xad55(%rip), %r15      # 0x208d4
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 0x4470
incq %r14
movl 0x8(%rbx), %eax
addq $0x18, %rbp
cmpq %rax, %r14
jb 0x15b7f
movq (%r13,%r12,8), %rsi
movl $0xa, %edi
callq 0x43f0
cmpb $0x1, 0x61b7a9b(%rip)   # 0x61cd663
jne 0x15d63
movb 0x61b7abc(%rip), %al    # 0x61cd690
movl %eax, %ecx
xorb $0x1, %cl
movb %cl, 0x61b7ab1(%rip)    # 0x61cd690
testb %al, %al
jne 0x15d63
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbf54
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 0x61b7a7a(%rip), %rax   # 0x61cd6a0
movq (%rax,%r12,8), %rdi
leaq 0xacb6(%rip), %rsi      # 0x208e7
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x30(%rsp)
movsd %xmm2, 0x28(%rsp)
movb $0x3, %al
callq 0x4470
movl 0x8(%rbx), %eax
testl %eax, %eax
je 0x15d15
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 0x61b7a20(%rip), %rax   # 0x61cd6a0
movq (%rax,%r12,8), %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0xac4a(%rip), %rsi      # 0x208e7
movb $0x3, %al
callq 0x4470
leaq 0x61b79f5(%rip), %rax   # 0x61cd6a0
movq (%rax,%r12,8), %rdi
movsd -0x10(%r15,%r13), %xmm0
movsd -0x8(%r15,%r13), %xmm1
movsd (%r15,%r13), %xmm2
leaq 0xac1d(%rip), %rsi      # 0x208e7
movb $0x3, %al
callq 0x4470
leaq 0x61b79c8(%rip), %rax   # 0x61cd6a0
movq (%rax,%r12,8), %rdi
movsd (%r15,%r14,8), %xmm0
movsd 0x8(%r15,%r14,8), %xmm1
movsd 0x10(%r15,%r14,8), %xmm2
leaq 0xabf0(%rip), %rsi      # 0x208e7
movb $0x3, %al
callq 0x4470
movl 0x8(%rbx), %eax
addq $0x18, %r13
leaq 0x1(%rbp), %rcx
cmpq %rax, %rbp
movq %rcx, %rbp
jb 0x15c60
leaq 0x61b7984(%rip), %r14   # 0x61cd6a0
movq (%r14,%r12,8), %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0xabae(%rip), %rbx      # 0x208e7
movq %rbx, %rsi
movb $0x3, %al
callq 0x4470
movq (%r14,%r12,8), %rdi
movq %rbx, %rsi
movsd 0x8(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movb $0x3, %al
callq 0x4470
callq 0xb6a6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq