// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlbsp/brink.cpp
// Function: AddPartition(bclipnode_s*, int, bool, int, bbrinklevel_e)
bool AddPartition (bclipnode_t *clipnode, int planenum, bool planeside, int content, bbrinklevel_e brinktype)
{
	// make sure we won't do any harm
	btreeface_l::iterator fi;
	btreeedge_l::iterator ei;
	int side;
	if (!clipnode->isleaf)
	{
		return false;
	}
	bool onback = false;
	for (fi = clipnode->treeleaf->faces->begin (); fi != clipnode->treeleaf->faces->end (); fi++)
	{
		for (ei = fi->f->edges->begin (); ei != fi->f->edges->end (); ei++)
		{
			for (side = 0; side < 2; side++)
			{
				btreepoint_t *tp = GetPointFromEdge (ei->e, side);
				const dplane_t *plane = &g_dplanes[planenum];
				vec_t dist = DotProduct (tp->v, plane->normal) - plane->dist;
				if (planeside? dist < -ON_EPSILON: dist > ON_EPSILON)
				{
					return false;
				}
				if (planeside? dist > ON_EPSILON: dist < -ON_EPSILON)
				{
					onback = true;
				}
			}
		}
	}
	if (!onback)
	{
		return false; // the whole leaf is on the plane, or the leaf doesn't consist of any vertex
	}
	bpartition_t *p = (bpartition_t *)malloc (sizeof (bpartition_t));
	hlassume (p != NULL, assume_NoMemory);
	p->next = clipnode->partitions;
	p->planenum = planenum;
	p->planeside = planeside;
	p->content = content;
	p->type = brinktype;
	clipnode->partitions = p;
	return true;
}

// Assembly:
cmpb $0x1, (%rdi)
jne 0x10ae9
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq 0x30(%rdi), %rax
movq (%rax), %rax
movq (%rax), %r13
cmpq %rax, %r13
je 0x10aec
movl %edx, %r15d
movl %ecx, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
movl %esi, 0x4(%rsp)
movslq %esi, %rbx
shlq $0x6, %rbx
addq 0x1a5ed(%rip), %rbx     # 0x2afa8
xorl %ebp, %ebp
movq %r14, 0x10(%rsp)
movq 0x10(%r13), %rax
movq (%rax), %rax
movq (%rax), %r12
cmpq %rax, %r12
je 0x10a81
movl $0x1, %r14d
movq 0x10(%r12), %rdi
xorl %esi, %esi
cmpl $0x1, %r14d
setne %sil
callq 0xe974
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm0
mulsd 0x8(%rbx), %xmm0
mulsd (%rbx), %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rax), %xmm0
mulsd 0x10(%rbx), %xmm0
addsd %xmm1, %xmm0
subsd 0x30(%rbx), %xmm0
testb %r15b, %r15b
je 0x10a2f
movsd 0x10a83(%rip), %xmm1    # 0x214a8
ucomisd %xmm0, %xmm1
jbe 0x10a39
xorl %eax, %eax
jmp 0x10a5f
ucomisd 0x10a59(%rip), %xmm0    # 0x21490
ja 0x10a2b
movb $0x1, %al
testb %r15b, %r15b
je 0x10a4c
ucomisd 0x10a48(%rip), %xmm0    # 0x21490
ja 0x10a5a
jmp 0x10a5f
movsd 0x10a54(%rip), %xmm1    # 0x214a8
ucomisd %xmm0, %xmm1
jbe 0x10a5f
movb $0x1, %bpl
movb $0x1, %al
testb %al, %al
je 0x10aec
decl %r14d
je 0x109db
movq (%r12), %r12
movq 0x10(%r13), %rax
cmpq (%rax), %r12
jne 0x109d5
movq (%r13), %r13
movq 0x10(%rsp), %r14
movq 0x30(%r14), %rax
cmpq (%rax), %r13
jne 0x109c2
testb $0x1, %bpl
je 0x10aec
movl $0x18, %edi
callq 0x4400
movq %rax, %r13
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa731
movq 0x28(%r14), %rax
movq %rax, 0x10(%r13)
movl 0x4(%rsp), %eax
movl %eax, (%r13)
movb %r15b, 0x4(%r13)
movl 0x8(%rsp), %eax
movl %eax, 0x8(%r13)
movl 0xc(%rsp), %eax
movl %eax, 0xc(%r13)
movq %r13, 0x28(%r14)
movb $0x1, %al
jmp 0x10aee
xorl %eax, %eax
retq
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq