// File: /workspace/github_cpp_makefile_star2_O2/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 0xeb59
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r15d
movq %rdi, %r14
movl %ecx, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
movq 0x30(%rdi), %rax
movq (%rax), %rax
movl %esi, 0x4(%rsp)
movslq %esi, %r13
shlq $0x6, %r13
addq 0x1a534(%rip), %r13     # 0x28fa8
xorl %ebx, %ebx
movq %rax, %rbp
movq %rdi, 0x10(%rsp)
movq (%rbp), %rbp
cmpq %rax, %rbp
je 0xeb5c
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, %r12
movq (%r12), %r12
cmpq %rax, %r12
je 0xeb48
pushq $0x2
popq %rax
movl %eax, %r14d
subl $0x1, %r14d
jb 0xeb3c
movq 0x10(%r12), %rdi
xorl %esi, %esi
cmpl $0x2, %eax
setne %sil
callq 0xcd13
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm0
mulsd 0x8(%r13), %xmm0
mulsd (%r13), %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rax), %xmm0
mulsd 0x10(%r13), %xmm0
addsd %xmm1, %xmm0
subsd 0x30(%r13), %xmm0
testb %r15b, %r15b
je 0xeb16
movsd 0xf900(%rip), %xmm1     # 0x1e400
ucomisd %xmm0, %xmm1
ja 0xeba9
ucomisd 0xf8ce(%rip), %xmm0     # 0x1e3e0
ja 0xeb32
jmp 0xeb34
ucomisd 0xf8c2(%rip), %xmm0     # 0x1e3e0
ja 0xeba9
movsd 0xf8d4(%rip), %xmm1     # 0x1e400
ucomisd %xmm0, %xmm1
jbe 0xeb34
movb $0x1, %bl
movl %r14d, %eax
jmp 0xeaa8
movq 0x10(%rbp), %rax
movq (%rax), %rax
jmp 0xea95
movq 0x10(%rsp), %r14
movq 0x30(%r14), %rax
movq (%rax), %rax
jmp 0xea7e
xorl %eax, %eax
retq
testb $0x1, %bl
je 0xeba9
pushq $0x18
popq %rdi
callq 0x4410
movq %rax, %r13
xorl %edi, %edi
testq %rax, %rax
setne %dil
pushq $0x1
popq %rsi
callq 0x92bb
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 0xebab
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq