// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlbsp/brink.cpp
// Function: FixBrinks_r_r(bclipnode_s const*, bpartition_s const*, bbrinklevel_e, int&, dclipnode_t*, dclipnode_t*, dclipnode_t*&, std::map<std::pair<int, std::pair<int, int>>, int, std::less<std::pair<int, std::pair<int, int>>>, std::allocator<std::pair<std::pair<int, std::pair<int, int>> const, int>>>*)
bool FixBrinks_r_r (const bclipnode_t *clipnode, const bpartition_t *p, bbrinklevel_e level, int &headnode_out, dclipnode_t *begin, dclipnode_t *end, dclipnode_t *&current
#ifdef HLBSP_MERGECLIPNODE
					, clipnodemap_t *outputmap
#endif
					)
{
	while (p && p->type > level)
	{
		p = p->next;
	}
	if (p == NULL)
	{
		headnode_out = clipnode->content;
		return true;
	}
	dclipnode_t *cn;
#ifdef HLBSP_MERGECLIPNODE
	dclipnode_t tmpclipnode;
	cn = &tmpclipnode;
	dclipnode_t *c = current;
	current++;
#else
	if (current >= end)
	{
		return false;
	}
	cn = current;
	current++;
#endif
	cn->planenum = p->planenum;
	cn->children[p->planeside] = p->content;
	int r;
	if (!FixBrinks_r_r (clipnode, p->next, level, r, begin, end, current
#ifdef HLBSP_MERGECLIPNODE
		, outputmap
#endif
		))
	{
		return false;
	}
	cn->children[!p->planeside] = r;
#ifdef HLBSP_MERGECLIPNODE
	clipnodemap_t::iterator output;
	output = outputmap->find (MakeKey (*cn));
	if (g_noclipnodemerge || output == outputmap->end ())
	{
		if (c >= end)
		{
			return false;
		}
		*c = *cn;
		(*outputmap)[MakeKey (*cn)] = c - begin;
		headnode_out = c - begin;
	}
	else
	{
		count_mergedclipnodes++;
		if (current != c + 1)
		{
			Error ("Merge clipnodes: internal error");
		}
		current = c;
		headnode_out = output->second; // use the existing clipnode
	}
#else
	headnode_out = cn - begin;
#endif
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r12
movq %r8, %r15
movq %rcx, %r14
movq %rsi, %r13
movq 0x70(%rsp), %r11
testq %r13, %r13
je 0xf5df
cmpl %edx, 0xc(%r13)
jle 0xf5ea
movq 0x10(%r13), %r13
jmp 0xf5ce
movl 0x20(%rdi), %eax
movl %eax, (%r14)
jmp 0xf706
movq (%r11), %rbp
leaq 0x8(%rbp), %rax
movq %rax, 0x20(%rsp)
movq %rax, (%r11)
movl (%r13), %ebx
movl %ebx, 0x8(%rsp)
movzwl 0x8(%r13), %eax
movzbl 0x4(%r13), %ecx
movw %ax, 0xc(%rsp,%rcx,2)
movq 0x10(%r13), %rsi
leaq 0x14(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
pushq 0x78(%rsp)
pushq %r11
callq 0xf5af
popq %rcx
popq %rdx
testb %al, %al
je 0xf6c9
movq %r14, 0x18(%rsp)
movzwl 0x14(%rsp), %eax
movzbl 0x4(%r13), %ecx
xorl $0x1, %ecx
movw %ax, 0xc(%rsp,%rcx,2)
movswq 0xc(%rsp), %r14
movswl 0xe(%rsp), %eax
shlq $0x20, %r14
orq %r14, %rbx
leaq 0x28(%rsp), %rsi
movq %rbx, (%rsi)
movl %eax, 0x10(%rsp)
movl %eax, 0x8(%rsi)
movq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x107ac
movq %rax, %r13
leaq 0x20c338e(%rip), %rax   # 0x20d2a11
leaq 0x8(%rbx), %rcx
cmpq %rcx, %r13
sete %cl
orb (%rax), %cl
cmpb $0x1, %cl
jne 0xf6cd
cmpq %r12, %rbp
jae 0xf6c9
movq 0x8(%rsp), %rax
movq %rax, (%rbp)
subq %r15, %rbp
shrq $0x3, %rbp
movl %eax, %eax
orq %rax, %r14
leaq 0x28(%rsp), %rsi
movq %r14, (%rsi)
movl 0x10(%rsp), %eax
movl %eax, 0x8(%rsi)
movq %rbx, %rdi
callq 0xfafc
movl %ebp, (%rax)
jmp 0xf6ff
xorl %eax, %eax
jmp 0xf708
leaq 0x4a3f4ac(%rip), %rax   # 0x4a4eb80
incl (%rax)
movq 0x70(%rsp), %rax
movq 0x20(%rsp), %rcx
cmpq %rcx, (%rax)
je 0xf6f8
leaq 0xf65a(%rip), %rdi      # 0x1ed46
xorl %eax, %eax
callq 0x8b1f
movq 0x70(%rsp), %rax
movq %rbp, (%rax)
movl 0x2c(%r13), %ebp
movq 0x18(%rsp), %rax
movl %ebp, (%rax)
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq