// File: nmmmnu[P]HM3/hm3/btreeindex/btreeindexbuilder_impl.h
// Function: hm3::btreeindex::BTreeIndexBuilder<hm3::DiskTable>::reorder(hm3::DiskTable const&, unsigned long, unsigned long, unsigned char, unsigned char)
void BTreeIndexBuilder<LIST>::reorder(const LIST &list,
				size_type const begin, size_type const end,
				level_type const level, level_type const this_level){

	// can't happen, but is good safeguard.
	if (this_level > level || begin >= end){
		if (begin >= end)
			injectEmptyNode_(level, this_level);

		return;
	}

	const auto &ll = llHolder_.value;

	using size_type = typename LIST::size_type;

	size_type const size = end - begin;

	if (size <= VALUES){
		// IMPORTANT: BECAUSE WE SUBSTRACT LEAF LEVEL,
		// CODE WILL GO HERE ONLY IF FIRST LEVEL IS LEAF

		//printf("We are in leaf level!!!\n");

		// leaf node - just flush everything into the node...
		if (this_level == level){
			Node node;

			for(branch_type j = 0; j < VALUES; ++j){
				branch_type const i = ll[j];

				if (i >= size){
					node.values[j] = Node::NIL;
					continue;
				}

				node.values[j] = htobe64( current_ );

				size_type const index = begin + i;

				injectValue_(list, index);
				// and current_ is increased here...
			}

			// push the node
			file_indx_.write( (const char *) & node, sizeof node );

		}else{ // if (this_level < level){
			// there are no children here.
			for(branch_type i = 0; i < BRANCHES; ++i)
				injectEmptyNode_( level, level_type(this_level + 1) );
		}

		//return;
	}else{
		size_type const distance = size / BRANCHES;

		if (this_level == level){
			Node node;

			for(branch_type j = 0; j < VALUES; ++j){
				branch_type const i = ll[j];

				node.values[j] = htobe64( current_ );

				size_type const index = begin + distance * (i + 1);

				injectValue_(list, index);
				// and current_ is increased here...
			}

			// push the node
			file_indx_.write( (const char *) & node, sizeof node );

		}else{ // if (this_level < level){
			// add the children

			size_type b = begin;
			for(branch_type i = 0; i < VALUES; ++i){
				size_type e = begin + distance * (i + 1);

				reorder(list, b, e, level, level_type(this_level + 1) );

				b = e + 1;
			}

			// last right child
			reorder(list, b, end, level, level_type(this_level + 1) );
		}

		//return;
	}
}

// Assembly:
subq $0x898, %rsp            # imm = 0x898
movl %r8d, 0x4(%rsp)
movq %rcx, %rax
movl 0x4(%rsp), %ecx
movq %rax, 0x8(%rsp)
movq %rdx, %rax
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%rsp)
movq %rsi, %rax
movq 0x10(%rsp), %rsi
movq %rax, 0x18(%rsp)
movq %rdi, %r8
movq 0x18(%rsp), %rdi
movb %r9b, %al
movq %r8, 0x890(%rsp)
movq %rdi, 0x888(%rsp)
movq %rsi, 0x880(%rsp)
movq %rdx, 0x878(%rsp)
movb %cl, 0x877(%rsp)
movb %al, 0x876(%rsp)
movq 0x890(%rsp), %rax
movq %rax, 0x20(%rsp)
movzbl 0x876(%rsp), %eax
movzbl 0x877(%rsp), %ecx
cmpl %ecx, %eax
jg 0x302e
movq 0x880(%rsp), %rax
cmpq 0x878(%rsp), %rax
jb 0x3061
movq 0x880(%rsp), %rax
cmpq 0x878(%rsp), %rax
jb 0x305c
movq 0x20(%rsp), %rdi
movb 0x877(%rsp), %al
movzbl %al, %esi
movzbl 0x876(%rsp), %edx
callq 0x3620
jmp 0x33ab
leaq 0x60c0(%rip), %rax      # 0x9128
movq %rax, 0x868(%rsp)
movq 0x878(%rsp), %rax
subq 0x880(%rsp), %rax
movq %rax, 0x860(%rsp)
cmpq $0x7f, 0x860(%rsp)
ja 0x31f2
movzbl 0x876(%rsp), %eax
movzbl 0x877(%rsp), %ecx
cmpl %ecx, %eax
jne 0x319a
movw $0x0, 0x466(%rsp)
movzwl 0x466(%rsp), %eax
cmpl $0x7f, %eax
jge 0x3181
movzwl 0x466(%rsp), %eax
movl %eax, %ecx
leaq 0x604d(%rip), %rax      # 0x9128
movw (%rax,%rcx,2), %ax
movw %ax, 0x464(%rsp)
movzwl 0x464(%rsp), %eax
cmpq 0x860(%rsp), %rax
jb 0x310f
movzwl 0x466(%rsp), %eax
movq $-0x1, 0x468(%rsp,%rax,8)
jmp 0x3168
movq 0x20(%rsp), %rax
movq 0x400(%rax), %rdi
callq 0x2720
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movzwl 0x466(%rsp), %eax
movq %rcx, 0x468(%rsp,%rax,8)
movq 0x880(%rsp), %rax
movzwl 0x464(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x458(%rsp)
movq 0x888(%rsp), %rsi
movq 0x458(%rsp), %rdx
callq 0x3700
movw 0x466(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x466(%rsp)
jmp 0x30b9
movq 0x20(%rsp), %rdi
leaq 0x468(%rsp), %rsi
movl $0x3f8, %edx            # imm = 0x3F8
callq 0x2240
jmp 0x31ed
movw $0x0, 0x456(%rsp)
movzwl 0x456(%rsp), %eax
cmpl $0x80, %eax
jge 0x31eb
movq 0x20(%rsp), %rdi
movb 0x877(%rsp), %cl
movzbl 0x876(%rsp), %eax
addl $0x1, %eax
movzbl %cl, %esi
movzbl %al, %edx
callq 0x3620
movw 0x456(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x456(%rsp)
jmp 0x31a4
jmp 0x31ed
jmp 0x33ab
movq 0x860(%rsp), %rax
shrq $0x7, %rax
movq %rax, 0x448(%rsp)
movzbl 0x876(%rsp), %eax
movzbl 0x877(%rsp), %ecx
cmpl %ecx, %eax
jne 0x32d2
movw $0x0, 0x4e(%rsp)
movzwl 0x4e(%rsp), %eax
cmpl $0x7f, %eax
jge 0x32b9
movq 0x20(%rsp), %rax
movzwl 0x4e(%rsp), %ecx
movl %ecx, %edx
leaq 0x5ee2(%rip), %rcx      # 0x9128
movw (%rcx,%rdx,2), %cx
movw %cx, 0x4c(%rsp)
movq 0x400(%rax), %rdi
callq 0x2720
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movzwl 0x4e(%rsp), %eax
movq %rcx, 0x50(%rsp,%rax,8)
movq 0x880(%rsp), %rax
movq 0x448(%rsp), %rcx
movzwl 0x4c(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x40(%rsp)
movq 0x888(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x3700
movw 0x4e(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x4e(%rsp)
jmp 0x3225
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x3f8, %edx            # imm = 0x3F8
callq 0x2240
jmp 0x33a9
movq 0x880(%rsp), %rax
movq %rax, 0x38(%rsp)
movw $0x0, 0x36(%rsp)
movzwl 0x36(%rsp), %eax
cmpl $0x7f, %eax
jge 0x336f
movq 0x20(%rsp), %rdi
movq 0x880(%rsp), %rax
movq 0x448(%rsp), %rcx
movzwl 0x36(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x888(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x28(%rsp), %rcx
movb 0x877(%rsp), %r8b
movzbl 0x876(%rsp), %eax
addl $0x1, %eax
movzbl %r8b, %r8d
movzbl %al, %r9d
callq 0x2f90
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
movw 0x36(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x36(%rsp)
jmp 0x32e6
movq 0x20(%rsp), %rdi
movq 0x888(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x878(%rsp), %rcx
movb 0x877(%rsp), %r8b
movzbl 0x876(%rsp), %eax
addl $0x1, %eax
movzbl %r8b, %r8d
movzbl %al, %r9d
callq 0x2f90
jmp 0x33ab
addq $0x898, %rsp            # imm = 0x898
retq
nopw %cs:(%rax,%rax)
nopl (%rax)