// File: /workspace/github_cpp_makefile_star2_O3/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 $0x428, %rsp            # imm = 0x428
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, (%rsp)
cmpb %r8b, %r9b
seta %sil
cmpq %rcx, %rdx
setb %al
setae %dl
orb %sil, %dl
jne 0x2bf4
movzbl %r8b, %eax
movl %eax, 0xc(%rsp)
movl %r8d, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq (%rsp), %r13
movq %rcx, %rbx
subq %r12, %rbx
cmpq $0x7f, %rbx
jbe 0x2b07
shrq $0x7, %rbx
cmpb %r8b, %r9b
je 0x2b6a
incb %r9b
leaq (%r12,%rbx), %r15
movq %rbx, %rax
shlq $0x7, %rax
subq %rbx, %rax
addq %r12, %rax
incq %rax
movq %rax, 0x20(%rsp)
movl $0x7f, %r14d
movq %rbx, 0x28(%rsp)
movl %r9d, 0x10(%rsp)
movzbl %r9b, %eax
movl %eax, 0x14(%rsp)
movl 0xc(%rsp), %ebx
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %ebx, %r8d
movl 0x14(%rsp), %r9d
callq 0x2a0e
movq %r15, %r12
movq 0x28(%rsp), %rax
addq %rax, %r15
incq %r12
decq %r14
jne 0x2aad
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r12
cmpq %rcx, %r12
setb %al
jae 0x2bea
movl 0x10(%rsp), %r9d
movl 0x8(%rsp), %r8d
cmpb %r8b, %r9b
jbe 0x2a58
jmp 0x2bf4
cmpb %r8b, %r9b
jne 0x2bc2
xorl %r15d, %r15d
leaq 0x260a(%rip), %r13      # 0x5124
movzwl (%r15,%r13), %edx
cmpq %rdx, %rbx
jbe 0x2b44
movq (%rsp), %rdi
movq 0x400(%rdi), %rax
bswapq %rax
movq %rax, 0x30(%rsp,%r15,4)
addq %r12, %rdx
movq %rbp, %rsi
callq 0x2c9a
jmp 0x2b4d
movq $-0x1, 0x30(%rsp,%r15,4)
addq $0x2, %r15
cmpq $0xfe, %r15
jne 0x2b1a
leaq 0x30(%rsp), %rsi
movl $0x3f8, %edx            # imm = 0x3F8
movq (%rsp), %rdi
jmp 0x2bbb
xorl %r15d, %r15d
leaq 0x25b0(%rip), %r14      # 0x5124
movq (%rsp), %r13
movzwl (%r15,%r14), %edx
movq 0x400(%r13), %rax
bswapq %rax
movq %rax, 0x30(%rsp,%r15,4)
incq %rdx
imulq %rbx, %rdx
addq %r12, %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2c9a
addq $0x2, %r15
cmpq $0xfe, %r15
jne 0x2b78
leaq 0x30(%rsp), %rsi
movl $0x3f8, %edx            # imm = 0x3F8
movq %r13, %rdi
callq 0x2200
jmp 0x2bfc
incb %r9b
movw $0x80, %bx
movzbl %r9b, %ebp
movq (%rsp), %r14
movl 0xc(%rsp), %r15d
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x2c2c
decw %bx
jne 0x2bd6
jmp 0x2bfc
movl 0x10(%rsp), %r9d
movl 0x8(%rsp), %r8d
testb %al, %al
movq (%rsp), %rdi
je 0x2c0e
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %r8b, %esi
movzbl %r9b, %edx
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c2c