// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlbsp/solidbsp.cpp
// Function: SolidBSP(surfchain_t const*, brush_s*, bool)
node_t*         SolidBSP(const surfchain_t* const surfhead, 
#ifdef ZHLT_DETAILBRUSH
						 brush_t *detailbrushes, 
#endif
						 bool report_progress)
{
    node_t*         headnode;

	ResetStatus(report_progress);
	double start_time = I_FloatTime();
	if(report_progress)
	{
		Log("SolidBSP [hull %d] ",g_hullnum);
	}
	else
	{
	    Verbose("----- SolidBSP -----\n");
	}

    headnode = AllocNode();
    headnode->surfaces = surfhead->surfaces;
#ifdef ZHLT_DETAILBRUSH
	headnode->detailbrushes = detailbrushes;
	headnode->isdetail = false;
#ifdef HLBSP_DETAILBRUSH_CULL
	vec3_t brushmins, brushmaxs;
	VectorAddVec (surfhead->mins, -SIDESPACE, brushmins);
	VectorAddVec (surfhead->maxs, SIDESPACE, brushmaxs);
	headnode->boundsbrush = BrushFromBox (brushmins, brushmaxs);
#endif
#endif

#ifndef HLCSG_HLBSP_ALLOWEMPTYENTITY
    if (!surfhead->surfaces)
    {
        // nothing at all to build
#ifdef ZHLT_DETAILBRUSH
		headnode->isportalleaf = true;
		headnode->iscontentsdetail = (headnode->detailbrushes != NULL);
		FreeLeafBrushes (headnode->detailbrushes);
#endif
        headnode->planenum = -1;
        headnode->contents = CONTENTS_EMPTY;
        return headnode;
    }
#endif

    // generate six portals that enclose the entire world
    MakeHeadnodePortals(headnode, surfhead->mins, surfhead->maxs);

    // recursively partition everything
    BuildBspTree_r(headnode);

	double end_time = I_FloatTime();
	if(report_progress)
	{
		Log("%d (%.2f seconds)\n",++g_numProcessed,(end_time - start_time));
	}

    return headnode;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, %r14
movb %bl, 0x32bb6dd(%rip)    # 0x32d3a54
xorl %eax, %eax
movl %eax, 0x32bb6d9(%rip)   # 0x32d3a58
movl %eax, 0x32bb6cb(%rip)   # 0x32d3a50
callq 0x81b0
movsd %xmm0, 0x8(%rsp)
testl %ebx, %ebx
je 0x183ad
leaq 0x20b6655(%rip), %rax   # 0x20ce9f0
movl (%rax), %esi
leaq 0xa4fd(%rip), %rdi      # 0x228a1
xorl %eax, %eax
callq 0x9bae
jmp 0x183bb
leaq 0xa501(%rip), %rdi      # 0x228b5
xorl %eax, %eax
callq 0xa2ef
callq 0x154b7
movq %rax, %r15
movq 0x30(%r14), %rax
movq %rax, (%r15)
movq %r12, 0x8(%r15)
movb $0x0, 0x48(%r15)
movupd (%r14), %xmm0
addpd 0xa360(%rip), %xmm0     # 0x22740
leaq 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
movsd 0x10(%r14), %xmm0
addsd 0x8ee1(%rip), %xmm0     # 0x212d8
movsd %xmm0, 0x10(%rdi)
leaq 0x18(%r14), %r12
movupd 0x18(%r14), %xmm0
addpd 0xa342(%rip), %xmm0     # 0x22750
leaq 0x10(%rsp), %rsi
movapd %xmm0, (%rsi)
movsd 0x28(%r14), %xmm0
addsd 0x8ebb(%rip), %xmm0     # 0x212e0
movsd %xmm0, 0x10(%rsi)
callq 0x152a0
movq %rax, 0x10(%r15)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x13c0e
movq %r15, %rdi
callq 0x18483
callq 0x81b0
testb %bl, %bl
je 0x18474
movl 0x32bb5f8(%rip), %esi   # 0x32d3a50
incl %esi
movl %esi, 0x32bb5f0(%rip)   # 0x32d3a50
subsd 0x8(%rsp), %xmm0
leaq 0xa45e(%rip), %rdi      # 0x228cb
movb $0x1, %al
callq 0x9bae
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq