// File: 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:
subq $0x88, %rsp
movb %dl, %al
movq %rdi, 0x78(%rsp)
movl %esi, 0x74(%rsp)
andb $0x1, %al
movb %al, 0x73(%rsp)
movl %ecx, 0x6c(%rsp)
movl %r8d, 0x68(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x19ef0
leaq 0x58(%rsp), %rdi
callq 0x19d60
movq 0x78(%rsp), %rax
testb $0x1, (%rax)
jne 0x1796c
movb $0x0, 0x87(%rsp)
jmp 0x17bf8
movb $0x0, 0x53(%rsp)
movq 0x78(%rsp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
callq 0x19f10
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x78(%rsp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
callq 0x19f60
movq %rax, 0x40(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x19f40
testb $0x1, %al
jne 0x179bf
jmp 0x17b6d
leaq 0x60(%rsp), %rdi
callq 0x19f90
movq (%rax), %rax
movq (%rax), %rdi
callq 0x19d80
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x19f90
movq (%rax), %rax
movq (%rax), %rdi
callq 0x19dd0
movq %rax, 0x30(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x19db0
testb $0x1, %al
jne 0x17a15
jmp 0x17b55
movl $0x0, 0x54(%rsp)
cmpl $0x2, 0x54(%rsp)
jge 0x17b3d
leaq 0x58(%rsp), %rdi
callq 0x19e00
movq (%rax), %rdi
cmpl $0x0, 0x54(%rsp)
setne %al
movzbl %al, %esi
andl $0x1, %esi
callq 0x131f0
movq %rax, 0x28(%rsp)
movslq 0x74(%rsp), %rcx
leaq 0x20d7fd7(%rip), %rax   # 0x20efa30
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movsd (%rax), %xmm1
movq 0x20(%rsp), %rax
movsd (%rax), %xmm2
movq 0x28(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x20(%rsp), %rax
mulsd 0x8(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x28(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq 0x20(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x20(%rsp), %rax
subsd 0x30(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
testb $0x1, 0x73(%rsp)
je 0x17ad8
movsd 0x21b4a(%rip), %xmm0    # 0x39618
ucomisd 0x18(%rsp), %xmm0
ja 0x17aec
jmp 0x17af9
movsd 0x18(%rsp), %xmm0
movsd 0x21b1a(%rip), %xmm1    # 0x39600
ucomisd %xmm1, %xmm0
jbe 0x17af9
movb $0x0, 0x87(%rsp)
jmp 0x17bf8
testb $0x1, 0x73(%rsp)
je 0x17b16
movsd 0x18(%rsp), %xmm0
movsd 0x21af2(%rip), %xmm1    # 0x39600
ucomisd %xmm1, %xmm0
ja 0x17b26
jmp 0x17b2b
movsd 0x21afa(%rip), %xmm0    # 0x39618
ucomisd 0x18(%rsp), %xmm0
jbe 0x17b2b
movb $0x1, 0x53(%rsp)
jmp 0x17b2d
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x17a1d
jmp 0x17b3f
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0x19e90
movq %rax, 0x10(%rsp)
jmp 0x179e3
jmp 0x17b57
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x1a020
movq %rax, 0x8(%rsp)
jmp 0x17991
testb $0x1, 0x53(%rsp)
jne 0x17b7e
movb $0x0, 0x87(%rsp)
jmp 0x17bf8
movl $0x18, %edi
callq 0x43e0
movq %rax, (%rsp)
cmpq $0x0, (%rsp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbe90
movq 0x78(%rsp), %rax
movq 0x28(%rax), %rcx
movq (%rsp), %rax
movq %rcx, 0x10(%rax)
movl 0x74(%rsp), %ecx
movq (%rsp), %rax
movl %ecx, (%rax)
movb 0x73(%rsp), %cl
movq (%rsp), %rax
andb $0x1, %cl
movb %cl, 0x4(%rax)
movl 0x6c(%rsp), %ecx
movq (%rsp), %rax
movl %ecx, 0x8(%rax)
movl 0x68(%rsp), %ecx
movq (%rsp), %rax
movl %ecx, 0xc(%rax)
movq (%rsp), %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x28(%rax)
movb $0x1, 0x87(%rsp)
movb 0x87(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
retq
nopl (%rax)