// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, 0x32bc934(%rip)   # 0x32d2a68
movb %bl, 0x32bc92a(%rip)    # 0x32d2a64
andl $0x0, 0x32bc91f(%rip)   # 0x32d2a60
callq 0x72f8
movsd %xmm0, 0x8(%rsp)
testl %ebx, %ebx
je 0x16169
leaq 0x20b78a9(%rip), %rax   # 0x20cda00
movl (%rax), %esi
leaq 0xa6a1(%rip), %rdi      # 0x20801
xorl %eax, %eax
callq 0x8780
jmp 0x16177
leaq 0xa6a5(%rip), %rdi      # 0x20815
xorl %eax, %eax
callq 0x8f76
callq 0x1357c
movq %rax, %r15
movq 0x30(%r14), %rax
movq %rax, (%r15)
movq %r12, 0x8(%r15)
movb $0x0, 0x48(%r15)
movupd (%r14), %xmm0
addpd 0xa504(%rip), %xmm0     # 0x206a0
leaq 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
movsd 0x10(%r14), %xmm0
addsd 0x9085(%rip), %xmm0     # 0x1f238
movsd %xmm0, 0x10(%rdi)
leaq 0x18(%r14), %r12
movupd 0x18(%r14), %xmm0
addpd 0xa4e6(%rip), %xmm0     # 0x206b0
leaq 0x10(%rsp), %rsi
movapd %xmm0, (%rsi)
movsd 0x28(%r14), %xmm0
addsd 0x905f(%rip), %xmm0     # 0x1f240
movsd %xmm0, 0x10(%rsi)
callq 0x13379
movq %rax, 0x10(%r15)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x11e86
movq %r15, %rdi
callq 0x1623f
callq 0x72f8
testb %bl, %bl
je 0x16230
movl 0x32bc84c(%rip), %esi   # 0x32d2a60
incl %esi
movl %esi, 0x32bc844(%rip)   # 0x32d2a60
subsd 0x8(%rsp), %xmm0
leaq 0xa602(%rip), %rdi      # 0x2082b
movb $0x1, %al
callq 0x8780
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq