// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlbsp/brink.cpp
// Function: FixBrinks_r(bclipnode_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 (const bclipnode_t *clipnode, bbrinklevel_e level, int &headnode_out, dclipnode_t *begin, dclipnode_t *end, dclipnode_t *&current
#ifdef HLBSP_MERGECLIPNODE
				, clipnodemap_t *outputmap
#endif
				)
{
	if (clipnode->isleaf)
	{
		return FixBrinks_r_r (clipnode, clipnode->partitions, level, headnode_out, begin, end, current
#ifdef HLBSP_MERGECLIPNODE
							, outputmap
#endif
							);
	}
	else
	{
		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 = clipnode->planenum;
		for (int k = 0; k < 2; k++)
		{
			int r;
			if (!FixBrinks_r (clipnode->children[k], level, r, begin, end, current
#ifdef HLBSP_MERGECLIPNODE
				, outputmap
#endif
				))
			{
				return false;
			}
			cn->children[k] = 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 existing clipnode
		}
#else
		headnode_out = cn - begin;
#endif
		return true;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r14
movq %r8, %r9
movq %rcx, %r12
movq %rdx, %rcx
movl %esi, %edx
movq 0x80(%rsp), %r10
cmpb $0x1, (%rdi)
jne 0xf759
movq 0x28(%rdi), %rsi
movq %r12, %r8
pushq %r10
pushq %r14
callq 0xf5af
addq $0x58, %rsp
jmp 0xf8a5
movq %rcx, 0x30(%rsp)
movq (%r14), %rax
movq %rax, 0x10(%rsp)
addq $0x8, %rax
movq %rax, 0x28(%rsp)
movq %rax, (%r14)
movl 0x4(%rdi), %eax
movq %rax, 0x38(%rsp)
movl %eax, 0x8(%rsp)
pushq $0x4
popq %r15
movq %rdi, 0x40(%rsp)
cmpq $0x8, %r15
je 0xf7e8
movq (%rdi,%r15,4), %rdi
subq $0x8, %rsp
movl %edx, %ebx
movl %edx, %esi
leaq 0x20(%rsp), %rdx
movq %r12, %r13
movq %r12, %rcx
movq %r9, %rbp
movq %r9, %r8
movq %r14, %r12
movq %r14, %r9
movq %r10, %r14
pushq %r10
callq 0xf717
popq %rcx
popq %rdx
testb %al, %al
je 0xf868
movzwl 0x18(%rsp), %eax
movw %ax, 0x8(%rsp,%r15)
addq $0x2, %r15
movq %r14, %r10
movq %r12, %r14
movq %r13, %r12
movq %rbp, %r9
movl %ebx, %edx
movq 0x40(%rsp), %rdi
jmp 0xf787
movq %r9, %r13
movswq 0xc(%rsp), %r15
movswl 0xe(%rsp), %ebp
shlq $0x20, %r15
movq 0x38(%rsp), %rax
orq %r15, %rax
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movl %ebp, 0x8(%rsi)
movq %r10, %rdi
movq %r10, %rbx
callq 0x107ac
movq %rbx, %rdi
movq %rax, %rbx
leaq 0x20c31ec(%rip), %rax   # 0x20d2a11
leaq 0x8(%rdi), %rcx
cmpq %rcx, %rbx
sete %cl
orb (%rax), %cl
cmpb $0x1, %cl
jne 0xf86c
movq 0x10(%rsp), %rbx
cmpq %r13, %rbx
jae 0xf868
movq 0x8(%rsp), %rax
movq %rax, (%rbx)
subq %r12, %rbx
shrq $0x3, %rbx
movl %eax, %eax
orq %rax, %r15
leaq 0x18(%rsp), %rsi
movq %r15, (%rsi)
movl %ebp, 0x8(%rsi)
callq 0xfafc
movl %ebx, (%rax)
jmp 0xf898
xorl %eax, %eax
jmp 0xf8a1
leaq 0x4a3f30d(%rip), %rax   # 0x4a4eb80
incl (%rax)
movq 0x28(%rsp), %rax
cmpq %rax, (%r14)
je 0xf88d
leaq 0xf4c0(%rip), %rdi      # 0x1ed46
xorl %eax, %eax
callq 0x8b1f
movq 0x10(%rsp), %rax
movq %rax, (%r14)
movl 0x2c(%rbx), %ebx
movq 0x30(%rsp), %rax
movl %ebx, (%rax)
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq