// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq %rcx, %rbx
testq %rsi, %rsi
je 0x113ae
movq %r9, %r12
movq %r8, %r15
movq %rsi, %r13
movq 0x60(%rsp), %r11
cmpl %edx, 0xc(%r13)
jle 0x113c4
movq 0x10(%r13), %r13
testq %r13, %r13
jne 0x1139f
movl 0x20(%rdi), %eax
movl %eax, (%rbx)
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r11), %rbp
leaq 0x8(%rbp), %rax
movq %rax, 0x10(%rsp)
movq %rax, (%r11)
movl (%r13), %r14d
movl %r14d, (%rsp)
movzwl 0x8(%r13), %eax
movzbl 0x4(%r13), %ecx
movw %ax, 0x4(%rsp,%rcx,2)
movq 0x10(%r13), %rsi
leaq 0xc(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
pushq 0x68(%rsp)
pushq %r11
callq 0x1137b
addq $0x10, %rsp
testb %al, %al
je 0x1149f
movzwl 0xc(%rsp), %eax
movzbl 0x4(%r13), %ecx
xorl $0x1, %ecx
movw %ax, 0x4(%rsp,%rcx,2)
movswq 0x4(%rsp), %r13
movswl 0x6(%rsp), %eax
shlq $0x20, %r13
orq %r13, %r14
leaq 0x18(%rsp), %rsi
movq %r14, (%rsi)
movl %eax, 0x8(%rsp)
movl %eax, 0x8(%rsi)
movq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x12222
movq %rax, %rdx
leaq 0x20c25a7(%rip), %rax   # 0x20d3a01
leaq 0x8(%r14), %rcx
cmpq %rcx, %rdx
sete %cl
orb (%rax), %cl
cmpb $0x1, %cl
jne 0x114a6
cmpq %r12, %rbp
jae 0x1149f
movq (%rsp), %rax
movq %rax, (%rbp)
subq %r15, %rbp
shrq $0x3, %rbp
movl %eax, %eax
orq %rax, %r13
leaq 0x18(%rsp), %rsi
movq %r13, (%rsi)
movl 0x8(%rsp), %eax
movl %eax, 0x8(%rsi)
movq %r14, %rdi
callq 0x118fa
movl %ebp, (%rax)
jmp 0x114dd
xorl %eax, %eax
jmp 0x113b5
leaq 0x4a3e6c3(%rip), %rax   # 0x4a4fb70
incl (%rax)
movq 0x60(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpq %rcx, (%rax)
je 0x114d7
leaq 0xf921(%rip), %rdi      # 0x20de6
xorl %eax, %eax
movq %rdx, %r14
callq 0x9e9c
movq %r14, %rdx
movq 0x60(%rsp), %rax
movq %rbp, (%rax)
movl 0x2c(%rdx), %ebp
movl %ebp, (%rbx)
jmp 0x113b3