// File: 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:
subq $0x78, %rsp
movl %edi, 0x74(%rsp)
movq %rsi, 0x68(%rsp)
movl %edx, 0x64(%rsp)
callq 0xd720
cmpl $0x0, 0x74(%rsp)
jne 0x1fe9c
movl 0x61bb861(%rip), %eax   # 0x61db6f4
addl $0x1, %eax
movl %eax, 0x61bb858(%rip)   # 0x61db6f4
movq 0x68(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x58(%rsp)
movslq 0x74(%rsp), %rcx
leaq 0x61bb84a(%rip), %rax   # 0x61db700
movq (%rax,%rcx,8), %rdi
movl 0x64(%rsp), %edx
movq 0x68(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0x68(%rsp), %rax
movl 0x20(%rax), %r8d
movq 0x68(%rsp), %rax
movl 0x28(%rax), %r9d
movq 0x58(%rsp), %rax
movl 0x8(%rax), %eax
leaq 0xeaa5(%rip), %rsi      # 0x2e98c
movl %eax, (%rsp)
movb $0x0, %al
callq 0x4550
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x1ff7f
movslq 0x74(%rsp), %rcx
leaq 0x61bb7ed(%rip), %rax   # 0x61db700
movq (%rax,%rcx,8), %rdi
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x60(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x60(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x60(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm2
leaq 0xea34(%rip), %rsi      # 0x2e99c
movb $0x3, %al
callq 0x4550
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x1fef9
movslq 0x74(%rsp), %rcx
leaq 0x61bb775(%rip), %rax   # 0x61db700
movq (%rax,%rcx,8), %rdi
leaq 0xbda2(%rip), %rsi      # 0x2bd38
movb $0x0, %al
callq 0x4550
testb $0x1, 0x61bb74f(%rip)   # 0x61db6f3
je 0x201d0
movb 0x61bb770(%rip), %al    # 0x61db720
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x61bb766(%rip)    # 0x61db720
testb $0x1, 0x61bb75f(%rip)   # 0x61db720
je 0x201ce
movq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xe5c0
movsd 0x40(%rsp), %xmm0
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
addsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x50(%rsp), %xmm0
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0x74(%rsp), %rcx
leaq 0x61bb701(%rip), %rax   # 0x61db730
movq (%rax,%rcx,8), %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
leaq 0xe963(%rip), %rsi      # 0x2e9af
movb $0x3, %al
callq 0x4550
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x2016e
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x60(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x60(%rsp), %eax
addl $0x1, %eax
movq 0x58(%rsp), %rcx
xorl %edx, %edx
divl 0x8(%rcx)
movq 0x8(%rsp), %rax
movl %edx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movslq 0x74(%rsp), %rcx
leaq 0x61bb66c(%rip), %rax   # 0x61db730
movq (%rax,%rcx,8), %rdi
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
leaq 0xe8ce(%rip), %rsi      # 0x2e9af
movb $0x3, %al
callq 0x4550
movslq 0x74(%rsp), %rcx
leaq 0x61bb63c(%rip), %rax   # 0x61db730
movq (%rax,%rcx,8), %rdi
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
movq 0x18(%rsp), %rax
movsd 0x8(%rax), %xmm1
movq 0x18(%rsp), %rax
movsd 0x10(%rax), %xmm2
leaq 0xe893(%rip), %rsi      # 0x2e9af
movb $0x3, %al
callq 0x4550
movslq 0x74(%rsp), %rcx
leaq 0x61bb601(%rip), %rax   # 0x61db730
movq (%rax,%rcx,8), %rdi
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq 0x10(%rsp), %rax
movsd 0x8(%rax), %xmm1
movq 0x10(%rsp), %rax
movsd 0x10(%rax), %xmm2
leaq 0xe858(%rip), %rsi      # 0x2e9af
movb $0x3, %al
callq 0x4550
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x2005b
movslq 0x74(%rsp), %rcx
leaq 0x61bb5b6(%rip), %rax   # 0x61db730
movq (%rax,%rcx,8), %rdi
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
leaq 0xe818(%rip), %rsi      # 0x2e9af
movb $0x3, %al
callq 0x4550
movslq 0x74(%rsp), %rcx
leaq 0x61bb586(%rip), %rax   # 0x61db730
movq (%rax,%rcx,8), %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
leaq 0xe7e8(%rip), %rsi      # 0x2e9af
movb $0x3, %al
callq 0x4550
jmp 0x201d0
callq 0xd740
addq $0x78, %rsp
retq
nopw (%rax,%rax)