// File: /workspace/github_cpp_makefile_star2_O1/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 $0x438, %rsp            # imm = 0x438
movq %rcx, 0x28(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, 0x10(%rsp)
movzbl %r8b, %eax
movl %eax, 0xc(%rsp)
movl %r8d, 0x1c(%rsp)
movq %rsi, 0x30(%rsp)
movl 0xc(%rsp), %r12d
movq 0x28(%rsp), %rbx
subq %r13, %rbx
jbe 0x2af4
cmpb %r8b, %r9b
ja 0x2af4
cmpq $0x7f, %rbx
jbe 0x2b22
shrq $0x7, %rbx
cmpb %r8b, %r9b
je 0x2b88
incb %r9b
leaq (%rbx,%r13), %r15
movq %rbx, %rax
shlq $0x7, %rax
subq %rbx, %rax
addq %r13, %rax
incq %rax
movq %rax, 0x38(%rsp)
movl $0x7f, %r14d
movl %r9d, 0x20(%rsp)
movzbl %r9b, %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq 0x30(%rsp), %rsi
movq %r13, %rdx
movq %r15, %rcx
movl %r12d, %r8d
movl 0x24(%rsp), %r9d
callq 0x2a18
movq %r15, %r13
addq %rbx, %r15
incq %r13
decq %r14
jne 0x2ab2
movq 0x38(%rsp), %r13
movq 0x30(%rsp), %rbp
movl 0x20(%rsp), %r9d
movl 0x1c(%rsp), %r8d
jmp 0x2a50
cmpq %r13, 0x28(%rsp)
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %esi
ja 0x2c08
movzbl %r9b, %edx
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c1a
cmpb %r8b, %r9b
jne 0x2be2
xorl %r15d, %r15d
leaq 0x25ef(%rip), %r12      # 0x5124
movq 0x10(%rsp), %r14
movzwl (%r15,%r12), %edx
cmpq %rdx, %rbx
jbe 0x2b63
movq 0x400(%r14), %rax
bswapq %rax
movq %rax, 0x40(%rsp,%r15,4)
addq %r13, %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2c88
jmp 0x2b6c
movq $-0x1, 0x40(%rsp,%r15,4)
addq $0x2, %r15
cmpq $0xfe, %r15
jne 0x2b3a
leaq 0x40(%rsp), %rsi
movl $0x3f8, %edx            # imm = 0x3F8
movq %r14, %rdi
jmp 0x2bdb
xorl %r15d, %r15d
leaq 0x2592(%rip), %r14      # 0x5124
movq 0x10(%rsp), %r12
movzwl (%r15,%r14), %edx
movq 0x400(%r12), %rax
bswapq %rax
movq %rax, 0x40(%rsp,%r15,4)
incq %rdx
imulq %rbx, %rdx
addq %r13, %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2c88
addq $0x2, %r15
cmpq $0xfe, %r15
jne 0x2b97
leaq 0x40(%rsp), %rsi
movl $0x3f8, %edx            # imm = 0x3F8
movq %r12, %rdi
callq 0x2200
jmp 0x2c08
incb %r9b
movw $0x80, %bx
movzbl %r9b, %r14d
movq 0x10(%rsp), %r15
movl 0xc(%rsp), %ebp
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2c1a
decw %bx
jne 0x2bf6
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq