// File: FreeSlave[P]vhlt/hlbsp/brink.cpp
// Function: BuildBaseCell(int&, bclipnode_s*, double, btreeleaf_s*)
btreeleaf_t *BuildBaseCell (int &numobjects, bclipnode_t *clipnode, vec_t range, btreeleaf_t *leaf_outside)
{
	btreepoint_t *tp[8];
	for (int i = 0; i < 8; i++)
	{
		tp[i] = AllocTreepoint (numobjects, true);
		if (i & 1)
			tp[i]->v[0] = range;
		else
			tp[i]->v[0] = -range;
		if (i & 2)
			tp[i]->v[1] = range;
		else
			tp[i]->v[1] = -range;
		if (i & 4)
			tp[i]->v[2] = range;
		else
			tp[i]->v[2] = -range;
	}
	btreeedge_t *te[12];
	for (int i = 0; i < 12; i++)
	{
		te[i] = AllocTreeedge (numobjects, true);
	}
	SetEdgePoints (te[0], tp[1], tp[0]);
	SetEdgePoints (te[1], tp[3], tp[2]);
	SetEdgePoints (te[2], tp[5], tp[4]);
	SetEdgePoints (te[3], tp[7], tp[6]);
	SetEdgePoints (te[4], tp[2], tp[0]);
	SetEdgePoints (te[5], tp[3], tp[1]);
	SetEdgePoints (te[6], tp[6], tp[4]);
	SetEdgePoints (te[7], tp[7], tp[5]);
	SetEdgePoints (te[8], tp[4], tp[0]);
	SetEdgePoints (te[9], tp[5], tp[1]);
	SetEdgePoints (te[10], tp[6], tp[2]);
	SetEdgePoints (te[11], tp[7], tp[3]);
	btreeface_t *tf[6];
	for (int i = 0; i < 6; i++)
	{
		tf[i] = AllocTreeface (numobjects, true);
	}
	AttachEdgeToFace (tf[0], te[4], true);
	AttachEdgeToFace (tf[0], te[6], false);
	AttachEdgeToFace (tf[0], te[8], false);
	AttachEdgeToFace (tf[0], te[10], true);
	AttachEdgeToFace (tf[1], te[5], false);
	AttachEdgeToFace (tf[1], te[7], true);
	AttachEdgeToFace (tf[1], te[9], true);
	AttachEdgeToFace (tf[1], te[11], false);
	AttachEdgeToFace (tf[2], te[0], false);
	AttachEdgeToFace (tf[2], te[2], true);
	AttachEdgeToFace (tf[2], te[8], true);
	AttachEdgeToFace (tf[2], te[9], false);
	AttachEdgeToFace (tf[3], te[1], true);
	AttachEdgeToFace (tf[3], te[3], false);
	AttachEdgeToFace (tf[3], te[10], false);
	AttachEdgeToFace (tf[3], te[11], true);
	AttachEdgeToFace (tf[4], te[0], true);
	AttachEdgeToFace (tf[4], te[1], false);
	AttachEdgeToFace (tf[4], te[4], false);
	AttachEdgeToFace (tf[4], te[5], true);
	AttachEdgeToFace (tf[5], te[2], false);
	AttachEdgeToFace (tf[5], te[3], true);
	AttachEdgeToFace (tf[5], te[6], true);
	AttachEdgeToFace (tf[5], te[7], false);
	btreeleaf_t *tl;
	tl = AllocTreeleaf (numobjects, false);
	for (int i = 0; i < 6; i++)
	{
		SetFaceLeafs (tf[i], tl, leaf_outside);
	}
	tl->clipnode = clipnode;
	return tl;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movsd %xmm0, 0x120(%rsp)
movq %rdx, 0x118(%rsp)
movl $0x0, 0xcc(%rsp)
cmpl $0x8, 0xcc(%rsp)
jge 0x12dc8
movq 0x130(%rsp), %rdi
movl $0x1, %esi
callq 0x12680
movq %rax, %rcx
movslq 0xcc(%rsp), %rax
movq %rcx, 0xd0(%rsp,%rax,8)
movl 0xcc(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x12cb4
movsd 0x120(%rsp), %xmm0
movslq 0xcc(%rsp), %rax
movq 0xd0(%rsp,%rax,8), %rax
movsd %xmm0, (%rax)
jmp 0x12ce8
movsd 0x120(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movslq 0xcc(%rsp), %rax
movq 0xd0(%rsp,%rax,8), %rax
movsd %xmm0, (%rax)
movl 0xcc(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x12d17
movsd 0x120(%rsp), %xmm0
movslq 0xcc(%rsp), %rax
movq 0xd0(%rsp,%rax,8), %rax
movsd %xmm0, 0x8(%rax)
jmp 0x12d4c
movsd 0x120(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movslq 0xcc(%rsp), %rax
movq 0xd0(%rsp,%rax,8), %rax
movsd %xmm0, 0x8(%rax)
movl 0xcc(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x12d7b
movsd 0x120(%rsp), %xmm0
movslq 0xcc(%rsp), %rax
movq 0xd0(%rsp,%rax,8), %rax
movsd %xmm0, 0x10(%rax)
jmp 0x12db0
movsd 0x120(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movslq 0xcc(%rsp), %rax
movq 0xd0(%rsp,%rax,8), %rax
movsd %xmm0, 0x10(%rax)
jmp 0x12db2
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x12c53
movl $0x0, 0x5c(%rsp)
cmpl $0xc, 0x5c(%rsp)
jge 0x12e03
movq 0x130(%rsp), %rdi
movl $0x1, %esi
callq 0x12720
movq %rax, %rcx
movslq 0x5c(%rsp), %rax
movq %rcx, 0x60(%rsp,%rax,8)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x12dd0
movq 0x60(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
callq 0x128a0
movq 0x68(%rsp), %rdi
movq 0xe8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
callq 0x128a0
movq 0x70(%rsp), %rdi
movq 0xf8(%rsp), %rsi
movq 0xf0(%rsp), %rdx
callq 0x128a0
movq 0x78(%rsp), %rdi
movq 0x108(%rsp), %rsi
movq 0x100(%rsp), %rdx
callq 0x128a0
movq 0x80(%rsp), %rdi
movq 0xe0(%rsp), %rsi
movq 0xd0(%rsp), %rdx
callq 0x128a0
movq 0x88(%rsp), %rdi
movq 0xe8(%rsp), %rsi
movq 0xd8(%rsp), %rdx
callq 0x128a0
movq 0x90(%rsp), %rdi
movq 0x100(%rsp), %rsi
movq 0xf0(%rsp), %rdx
callq 0x128a0
movq 0x98(%rsp), %rdi
movq 0x108(%rsp), %rsi
movq 0xf8(%rsp), %rdx
callq 0x128a0
movq 0xa0(%rsp), %rdi
movq 0xf0(%rsp), %rsi
movq 0xd0(%rsp), %rdx
callq 0x128a0
movq 0xa8(%rsp), %rdi
movq 0xf8(%rsp), %rsi
movq 0xd8(%rsp), %rdx
callq 0x128a0
movq 0xb0(%rsp), %rdi
movq 0x100(%rsp), %rsi
movq 0xe0(%rsp), %rdx
callq 0x128a0
movq 0xb8(%rsp), %rdi
movq 0x108(%rsp), %rsi
movq 0xe8(%rsp), %rdx
callq 0x128a0
movl $0x0, 0x1c(%rsp)
cmpl $0x6, 0x1c(%rsp)
jge 0x12f8e
movq 0x130(%rsp), %rdi
movl $0x1, %esi
callq 0x128e0
movq %rax, %rcx
movslq 0x1c(%rsp), %rax
movq %rcx, 0x20(%rsp,%rax,8)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x12f5b
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x20(%rsp), %rdi
movq 0x90(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x20(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x28(%rsp), %rdi
movq 0x88(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x28(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x28(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x28(%rsp), %rdi
movq 0xb8(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x30(%rsp), %rdi
movq 0x60(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x30(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x30(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x30(%rsp), %rdi
movq 0xa8(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x38(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x38(%rsp), %rdi
movq 0x78(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x38(%rsp), %rdi
movq 0xb0(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x38(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x40(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x40(%rsp), %rdi
movq 0x68(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x40(%rsp), %rdi
movq 0x80(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x40(%rsp), %rdi
movq 0x88(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x48(%rsp), %rdi
movq 0x70(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x48(%rsp), %rdi
movq 0x78(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x48(%rsp), %rdi
movq 0x90(%rsp), %rsi
movl $0x1, %edx
callq 0x129a0
movq 0x48(%rsp), %rdi
movq 0x98(%rsp), %rsi
xorl %edx, %edx
callq 0x129a0
movq 0x130(%rsp), %rdi
xorl %esi, %esi
callq 0x12b40
movq %rax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x6, 0xc(%rsp)
jge 0x131c6
movslq 0xc(%rsp), %rax
movq 0x20(%rsp,%rax,8), %rdi
movq 0x10(%rsp), %rsi
movq 0x118(%rsp), %rdx
callq 0x12b00
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x13196
movq 0x128(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
retq
nopw %cs:(%rax,%rax)