// File: /workspace/github_cpp_makefile_star2_O1/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, %r11
movq %r8, %r9
movq %rcx, %r8
movq %rdx, %rcx
movl %esi, %edx
movq 0x80(%rsp), %r10
cmpb $0x1, (%rdi)
jne 0x11741
movq 0x28(%rdi), %rsi
pushq %r10
pushq %r11
callq 0x11598
addq $0x58, %rsp
jmp 0x11897
movq %rcx, 0x38(%rsp)
movq (%r11), %rax
movq %rax, 0x18(%rsp)
addq $0x8, %rax
movq %rax, 0x30(%rsp)
movq %rax, (%r11)
movl 0x4(%rdi), %eax
movq %rax, 0x40(%rsp)
movl %eax, 0x8(%rsp)
movl $0x2, %r15d
movq %r11, 0x10(%rsp)
movq %rdi, %r12
movq (%rdi,%r15,8), %rdi
subq $0x8, %rsp
movl %edx, %ebx
movl %edx, %esi
leaq 0x28(%rsp), %rdx
movq %r8, %r13
movq %r8, %rcx
movq %r9, %rbp
movq %r9, %r8
movq %r11, %r9
movq %r10, %r14
pushq %r10
callq 0x11702
addq $0x10, %rsp
testb %al, %al
je 0x11850
movzwl 0x20(%rsp), %eax
movw %ax, 0x8(%rsp,%r15,2)
incq %r15
cmpq $0x3, %r15
movq %r14, %r10
movq 0x10(%rsp), %r11
movq %r13, %r8
movq %rbp, %r9
movl %ebx, %edx
movq %r12, %rdi
je 0x11771
movswq 0xc(%rsp), %r15
movswl 0xe(%rsp), %r12d
shlq $0x20, %r15
movq 0x40(%rsp), %rax
orq %r15, %rax
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movl %r12d, 0x8(%rsi)
movq %r10, %rdi
callq 0x1242a
movq %rax, %rbx
leaq 0x20c320a(%rip), %rax   # 0x20d4a11
leaq 0x8(%r14), %rcx
cmpq %rcx, %rbx
sete %cl
orb (%rax), %cl
cmpb $0x1, %cl
jne 0x11854
movq 0x18(%rsp), %rbx
cmpq %rbp, %rbx
jae 0x11850
movq 0x8(%rsp), %rax
movq %rax, (%rbx)
subq %r13, %rbx
shrq $0x3, %rbx
movl 0x8(%rsp), %eax
orq %rax, %r15
leaq 0x20(%rsp), %rsi
movq %r15, (%rsi)
movl %r12d, 0x8(%rsi)
movq %r14, %rdi
callq 0x11b08
movl %ebx, (%rax)
jmp 0x1188a
xorl %eax, %eax
jmp 0x11893
leaq 0x4a3f325(%rip), %rax   # 0x4a50b80
incl (%rax)
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rax
cmpq %rax, (%rcx)
je 0x1187f
leaq 0x1057b(%rip), %rdi     # 0x21dee
xorl %eax, %eax
callq 0x9f84
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rax, (%rcx)
movl 0x2c(%rbx), %ebx
movq 0x38(%rsp), %rax
movl %ebx, (%rax)
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq