// File: /workspace/github_cpp_makefile_star2_O1/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, 0x32bc396(%rip)    # 0x32d4a64
xorl %eax, %eax
movl %eax, 0x32bc392(%rip)   # 0x32d4a68
movl %eax, 0x32bc384(%rip)   # 0x32d4a60
callq 0x827c
movsd %xmm0, 0x8(%rsp)
testl %ebx, %ebx
je 0x18704
leaq 0x20b730e(%rip), %rax   # 0x20cfa00
movl (%rax), %esi
leaq 0xb1de(%rip), %rdi      # 0x238d9
xorl %eax, %eax
callq 0x9c96
jmp 0x18712
leaq 0xb1e2(%rip), %rdi      # 0x238ed
xorl %eax, %eax
callq 0xa3d7
callq 0x157b5
movq %rax, %r15
movq 0x30(%r14), %rax
movq %rax, (%r15)
movq %r12, 0x8(%r15)
movb $0x0, 0x48(%r15)
movupd (%r14), %xmm0
addpd 0xb039(%rip), %xmm0     # 0x23770
leaq 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
movsd 0x10(%r14), %xmm0
addsd 0x9b92(%rip), %xmm0     # 0x222e0
movsd %xmm0, 0x10(%rdi)
leaq 0x18(%r14), %r12
movupd 0x18(%r14), %xmm0
addpd 0xb01b(%rip), %xmm0     # 0x23780
leaq 0x10(%rsp), %rsi
movapd %xmm0, (%rsi)
movsd 0x28(%r14), %xmm0
addsd 0x9b6c(%rip), %xmm0     # 0x222e8
movsd %xmm0, 0x10(%rsi)
callq 0x1558c
movq %rax, 0x10(%r15)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x13e2a
movq %r15, %rdi
callq 0x187da
callq 0x827c
testb %bl, %bl
je 0x187cb
movl 0x32bc2b1(%rip), %esi   # 0x32d4a60
incl %esi
movl %esi, 0x32bc2a9(%rip)   # 0x32d4a60
subsd 0x8(%rsp), %xmm0
leaq 0xb13f(%rip), %rdi      # 0x23903
movb $0x1, %al
callq 0x9c96
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq