// File: /workspace/github_cpp_makefile_star2_O3/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, %r10
movq %r8, %r9
movq %rcx, %r8
movq %rdx, %rcx
movl %esi, %edx
movq 0x80(%rsp), %r11
cmpb $0x1, (%rdi)
jne 0x11523
movq 0x28(%rdi), %rsi
pushq %r11
pushq %r10
callq 0x1137b
addq $0x58, %rsp
jmp 0x1168b
movq %rcx, 0x38(%rsp)
movq (%r10), %rax
movq %rax, 0x10(%rsp)
addq $0x8, %rax
movq %rax, 0x30(%rsp)
movq %rax, (%r10)
movl 0x4(%rdi), %eax
movq %rax, 0x40(%rsp)
movl %eax, (%rsp)
movb $0x1, %r15b
xorl %r14d, %r14d
movq %r10, 0x8(%rsp)
movq %r8, 0x18(%rsp)
movq %rdi, %rbp
movq 0x10(%rdi,%r14,8), %rdi
subq $0x8, %rsp
movl %edx, %r12d
movl %edx, %esi
leaq 0x28(%rsp), %rdx
movq %r8, %rcx
movq %r9, %rbx
movq %r9, %r8
movq %r10, %r9
movq %r11, %r13
pushq %r11
callq 0x114e4
addq $0x10, %rsp
testb %al, %al
je 0x11642
movzwl 0x20(%rsp), %eax
movw %ax, 0x4(%rsp,%r14,2)
movl $0x1, %r14d
testb $0x1, %r15b
movl $0x0, %r15d
movq 0x8(%rsp), %r10
movq %r13, %r11
movq 0x18(%rsp), %r8
movq %rbx, %r9
movl %r12d, %edx
movq %rbp, %rdi
jne 0x11557
movswq 0x4(%rsp), %r15
movswl 0x6(%rsp), %r14d
shlq $0x20, %r15
movq 0x40(%rsp), %rax
orq %r15, %rax
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movl %r14d, 0x8(%rsi)
movq %r11, %rdi
callq 0x12222
movq %r13, %rdi
movq %rax, %r13
leaq 0x20c2406(%rip), %rax   # 0x20d3a01
leaq 0x8(%rdi), %rcx
cmpq %rcx, %r13
sete %cl
orb (%rax), %cl
cmpb $0x1, %cl
jne 0x11646
movq 0x10(%rsp), %r12
cmpq %rbx, %r12
jae 0x11642
movq (%rsp), %rax
movq %rax, (%r12)
subq 0x18(%rsp), %r12
shrq $0x3, %r12
movl %eax, %eax
orq %rax, %r15
leaq 0x20(%rsp), %rsi
movq %r15, (%rsi)
movl %r14d, 0x8(%rsi)
callq 0x118fa
movl %r12d, (%rax)
jmp 0x1167d
xorl %eax, %eax
jmp 0x11687
leaq 0x4a3e523(%rip), %rax   # 0x4a4fb70
incl (%rax)
movq 0x8(%rsp), %rcx
movq 0x30(%rsp), %rax
cmpq %rax, (%rcx)
je 0x11671
leaq 0xf781(%rip), %rdi      # 0x20de6
xorl %eax, %eax
callq 0x9e9c
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
movl 0x2c(%r13), %r12d
movq 0x38(%rsp), %rax
movl %r12d, (%rax)
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq