// File: /workspace/github_cpp_makefile_star2_O3/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 0x108cd
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x30(%rdi), %rax
movq (%rax), %rax
movq (%rax), %r13
cmpq %rax, %r13
je 0x108d0
movl %edx, %r15d
movq %rdi, 0x10(%rsp)
movl %ecx, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
movl %esi, 0x4(%rsp)
movslq %esi, %rbx
shlq $0x6, %rbx
addq 0x19803(%rip), %rbx     # 0x29fa8
xorl %ebp, %ebp
movq 0x10(%r13), %rcx
movq (%rcx), %rcx
movq (%rcx), %r12
cmpq %rcx, %r12
je 0x10869
movb $0x1, %r14b
xorl %eax, %eax
movq 0x10(%r12), %rdi
movzbl %al, %esi
andl $0x1, %esi
callq 0xe75d
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 0x1081b
movsd 0xfc9b(%rip), %xmm1     # 0x204a0
ucomisd %xmm0, %xmm1
ja 0x108d0
ucomisd 0xfc69(%rip), %xmm0     # 0x20480
ja 0x10837
jmp 0x1083a
ucomisd 0xfc5d(%rip), %xmm0     # 0x20480
ja 0x108d0
movsd 0xfc6f(%rip), %xmm1     # 0x204a0
ucomisd %xmm0, %xmm1
jbe 0x1083a
movb $0x1, %bpl
movb $0x1, %al
testb $0x1, %r14b
movl $0x0, %r14d
jne 0x107bf
movq (%r12), %r12
movq 0x10(%r13), %rax
cmpq (%rax), %r12
jne 0x107ba
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq (%r13), %r13
cmpq %rax, %r13
jne 0x107a7
testb $0x1, %bpl
je 0x108d0
movl $0x18, %edi
callq 0x4400
movq %rax, %r13
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa655
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %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(%rcx)
movb $0x1, %al
jmp 0x108d2
xorl %eax, %eax
retq
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq