// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rcx, 0x18(%rsp)
movq %rdx, %r12
movq %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
movzbl %r8b, %ebp
movl %r8d, 0x10(%rsp)
movq 0x18(%rsp), %rbx
subq %r12, %rbx
jbe 0x2932
cmpb %r8b, %r9b
ja 0x2932
cmpq $0x7f, %rbx
jbe 0x295d
shrq $0x7, %rbx
cmpb %r8b, %r9b
je 0x29b1
incb %r9b
leaq (%r12,%rbx), %r15
movl %r9d, 0x14(%rsp)
movzbl %r9b, %r13d
pushq $0x7f
popq %r14
subq $0x1, %r14
jb 0x2926
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %ebp, %r8d
movl %r13d, %r9d
callq 0x2896
movq %r15, %r12
addq %rbx, %r15
incq %r12
jmp 0x28fb
movl 0x14(%rsp), %r9d
movl 0x10(%rsp), %r8d
jmp 0x28c1
cmpq %r12, 0x18(%rsp)
ja 0x2a09
movzbl %r9b, %edx
movq (%rsp), %rdi
movl %ebp, %esi
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ad6
cmpb %r8b, %r9b
jne 0x2a1b
xorl %r15d, %r15d
leaq 0x27b4(%rip), %r13      # 0x5124
cmpq $0xfe, %r15
je 0x29f6
movzwl (%r15,%r13), %edx
cmpq %rdx, %rbx
jbe 0x29a5
movq (%rsp), %rdi
movq 0x400(%rdi), %rax
bswapq %rax
movq %rax, 0x20(%rsp,%r15,4)
addq %r12, %rdx
movq 0x8(%rsp), %rsi
callq 0x2b46
jmp 0x29ab
orq $-0x1, 0x20(%rsp,%r15,4)
addq $0x2, %r15
jmp 0x2970
xorl %r15d, %r15d
leaq 0x2769(%rip), %r13      # 0x5124
cmpq $0xfe, %r15
je 0x29f6
movzwl (%r15,%r13), %edx
movq (%rsp), %rdi
movq 0x400(%rdi), %rax
bswapq %rax
movq %rax, 0x20(%rsp,%r15,4)
incq %rdx
imulq %rbx, %rdx
addq %r12, %rdx
movq 0x8(%rsp), %rsi
callq 0x2b46
addq $0x2, %r15
jmp 0x29bb
leaq 0x20(%rsp), %rsi
movl $0x3f8, %edx            # imm = 0x3F8
movq (%rsp), %rdi
callq 0x21e0
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incb %r9b
movw $0x80, %bx
movzbl %r9b, %r14d
subw $0x1, %bx
jb 0x2a09
movq (%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2ad6
jmp 0x2a26