// File: /workspace/github_cpp_makefile_star2_O1/wichtounet[P]articles/plf_colony_alpha/plf_timsort.h
// Function: plf::TimSort<Trivial<8>**, plf::colony<Trivial<8>, std::allocator<Trivial<8>>, unsigned short>::sort_dereferencer<plf::colony<Trivial<8>, std::allocator<Trivial<8>>, unsigned short>::less>>::mergeHi(Trivial<8>**, long, Trivial<8>**, long)
void mergeHi(iter_t const base1, diff_t len1, iter_t const base2, diff_t len2)
	{
		assert(len1 > 0 && len2 > 0 && base1 + len1 == base2);

		copy_to_tmp(base2, len2);

		iter_t cursor1 = base1 + (len1 - 1);
		tmp_iter_t cursor2 = tmp_.begin() + (len2 - 1);
		iter_t dest = base2 + (len2 - 1);

		*(dest--) = PLF_TIMSORT_MOVE(*(cursor1--));
		if (--len1 == 0)
		{
			PLF_TIMSORT_MOVE_RANGE(tmp_.begin(), tmp_.begin() + len2, dest - (len2 - 1));
			return;
		}
		if (len2 == 1)
		{
			dest -= len1;
			cursor1 -= len1;
			PLF_TIMSORT_MOVE_BACKWARD(cursor1 + 1, cursor1 + (1 + len1), dest + (1 + len1));
			*dest = PLF_TIMSORT_MOVE(*cursor2);
			return;
		}

		int minGallop(minGallop_);

		// outer:
		while (true)
		{
			int count1 = 0;
			int count2 = 0;
			bool break_outer = false;

			do
			{
				assert(len1 > 0 && len2 > 1);

				if (comp_.lt(*cursor2, *cursor1))
				{
					*(dest--) = PLF_TIMSORT_MOVE(*(cursor1--));
					++count1;
					count2 = 0;
					if (--len1 == 0)
					{
						break_outer = true;
						break;
					}
				}
				else
				{
					*(dest--) = PLF_TIMSORT_MOVE(*(cursor2--));
					++count2;
					count1 = 0;
					if (--len2 == 1)
					{
						break_outer = true;
						break;
					}
				}
			} while ((count1 | count2) < minGallop);
			
			
			if (break_outer)
			{
				break;
			}

			do
			{
				assert(len1 > 0 && len2 > 1);

				count1 = len1 - gallopRight(*cursor2, base1, len1, len1 - 1);

				if (count1 != 0)
				{
					dest -= count1;
					cursor1 -= count1;
					len1 -= count1;
					PLF_TIMSORT_MOVE_BACKWARD(cursor1 + 1, cursor1 + (1 + count1), dest + (1 + count1));

					if (len1 == 0)
					{
						break_outer = true;
						break;
					}
				}

				*(dest--) = PLF_TIMSORT_MOVE(*(cursor2--));

				if (--len2 == 1)
				{
					break_outer = true;
					break;
				}

				count2 = len2 - gallopLeft(*cursor1, tmp_.begin(), len2, len2 - 1);

				if (count2 != 0)
				{
					dest -= count2;
					cursor2 -= count2;
					len2 -= count2;
					PLF_TIMSORT_MOVE_RANGE(cursor2 + 1, cursor2 + (1 + count2), dest + 1);
					if (len2 <= 1)
					{
						break_outer = true;
						break;
					}
				}

				*(dest--) = PLF_TIMSORT_MOVE(*(cursor1--));

				if (--len1 == 0)
				{
					break_outer = true;
					break;
				}

				minGallop--;
			} while ((count1 >= MIN_GALLOP) | (count2 >= MIN_GALLOP));
			
			
			if (break_outer)
			{
				break;
			}

			if (minGallop < 0)
			{
				minGallop = 0;
			}
			
			minGallop += 2;
		} 

		minGallop_ = std::min(minGallop, 1);

		if (len2 == 1)
		{
			assert(len1 > 0);
			dest -= len1;
			PLF_TIMSORT_MOVE_BACKWARD(cursor1 + (1 - len1), cursor1 + 1, dest + (1 + len1));
			*dest = PLF_TIMSORT_MOVE(*cursor2);
		}
		else
		{
			assert(len2 != 0 && "Comparison function violates its general contract");
			assert(len1 == 0);
			assert(len2 > 1);
			PLF_TIMSORT_MOVE_RANGE(tmp_.begin(), tmp_.begin() + len2, dest - (len2 - 1));
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r14
movq %rcx, %rsi
movq %r8, %rdx
callq 0x6ed68
movq %rbx, %r9
leaq -0x8(,%rbx,8), %rbx
movq %r14, (%rsp)
addq 0x8(%r14), %rbx
movq -0x8(%r15,%rbp,8), %rax
leaq -0x10(%r12,%r9,8), %r14
movq %rax, 0x8(%r14)
movq %rbp, %r13
decq %r13
je 0x6eab5
movq %r15, %rax
leaq -0x10(%r15,%rbp,8), %r15
cmpq $0x1, %r9
jne 0x6eac3
movq %r12, %rcx
leaq -0x8(%rax,%rbp,8), %rdx
movl $0x1, %r12d
subq %rbp, %r12
leaq 0x8(%r15,%r12,8), %rsi
subq %rsi, %rdx
je 0x6ed24
leaq -0x8(%rcx,%r9,8), %rdi
subq %rdx, %rdi
jmp 0x6ed1f
testq %r9, %r9
jne 0x6ed3a
jmp 0x6ed2b
movq %rax, 0x18(%rsp)
movq (%rsp), %rax
movl 0x4(%rax), %r8d
addq $-0x8, %r14
movq %r14, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
movq %rdx, %r14
movq (%rbx), %rdx
movq (%r15), %rsi
movq (%rdx), %rdi
cmpq (%rsi), %rdi
jae 0x6eaff
addq $-0x8, %r15
movq %rsi, 0x8(%r14)
xorl %eax, %eax
decq %r13
je 0x6eb2f
incl %ecx
jmp 0x6eb14
addq $-0x8, %rbx
movq %rdx, 0x8(%r14)
decq %r9
cmpq $0x1, %r9
je 0x6eb25
incl %eax
xorl %ecx, %ecx
movl %eax, %esi
orl %ecx, %esi
leaq -0x8(%r14), %rdx
cmpl %r8d, %esi
jl 0x6eadb
xorl %eax, %eax
jmp 0x6eb34
movl $0x1, %r9d
movb $0x1, %al
jmp 0x6eb34
movb $0x1, %al
xorl %r13d, %r13d
testb %al, %al
jne 0x6ecbe
movl %eax, 0x14(%rsp)
movl %r8d, 0x10(%rsp)
movq %r9, 0x8(%rsp)
leaq -0x1(%r13), %r8
movq (%rsp), %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
callq 0x6e5ae
movq %r13, %rcx
subq %rax, %rcx
testl %ecx, %ecx
je 0x6ebbd
movq %rcx, %rdx
shlq $0x20, %rdx
movslq %ecx, %r12
leaq (,%r12,8), %rax
subq %rax, %r14
subq %rax, %r15
testq %rdx, %rdx
je 0x6ebb4
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdx
sarq $0x1d, %rdx
leaq 0x8(%r15), %rsi
leaq (%r14,%rdx), %rdi
addq $-0x8, %rdx
subq %rdx, %rdi
movq %rcx, %rbp
callq 0x42a0
movq %rbp, %rcx
subq %r12, %r13
je 0x6eca4
movq 0x8(%rsp), %r8
movq (%rbx), %rax
addq $-0x8, %rbx
movq %rax, (%r14)
addq $-0x8, %r14
leaq -0x1(%r8), %rbp
movb $0x1, %al
cmpq $0x1, %rbp
je 0x6ec94
movq %rcx, 0x20(%rsp)
movq (%rsp), %rdi
movq 0x8(%rdi), %rdx
addq $-0x2, %r8
movq %r15, %rsi
movq %rbp, %rcx
callq 0x6f080
movq %rbp, %r12
subq %rax, %r12
testl %r12d, %r12d
je 0x6ec59
movq %r12, %rdx
shlq $0x20, %rdx
movslq %r12d, %rcx
leaq (,%rcx,8), %rax
subq %rax, %r14
subq %rax, %rbx
testq %rdx, %rdx
je 0x6ec50
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdx
sarq $0x1d, %rdx
leaq 0x8(%rbx), %rsi
addq $-0x8, %rdx
leaq 0x8(%r14), %rdi
movq %rcx, 0x8(%rsp)
callq 0x42a0
movq 0x8(%rsp), %rcx
subq %rcx, %rbp
cmpq $0x2, %rbp
jl 0x6ecb0
movq (%r15), %rax
addq $-0x8, %r15
movq %rax, (%r14)
addq $-0x8, %r14
decq %r13
je 0x6ec9c
decl 0x10(%rsp)
movq %rbp, %r9
cmpl $0x6, 0x20(%rsp)
jg 0x6eb45
movq %rbp, %r9
cmpl $0x6, %r12d
jg 0x6eb45
movl 0x14(%rsp), %eax
movq %rbp, %r9
jmp 0x6ecb5
movl $0x1, %r9d
jmp 0x6ecb5
movq %rbp, %r9
xorl %r13d, %r13d
jmp 0x6ecb3
movb $0x1, %al
xorl %r13d, %r13d
movq 0x8(%rsp), %r9
jmp 0x6ecb5
movq %rbp, %r9
movb $0x1, %al
testb %al, %al
movl 0x10(%rsp), %r8d
je 0x6ecc2
xorl %eax, %eax
jmp 0x6ecd3
movl %r8d, %eax
sarl $0x1f, %eax
andnl %r8d, %eax, %r8d
addl $0x2, %r8d
movb $0x1, %al
testb %al, %al
jne 0x6ead0
testl %r8d, %r8d
movl $0x1, %eax
cmovlel %r8d, %eax
movq (%rsp), %rcx
movl %eax, 0x4(%rcx)
testq %r9, %r9
je 0x6ed2b
cmpq $0x1, %r9
jne 0x6ed3a
movq %r13, %r12
negq %r12
shlq $0x3, %r13
testq %r13, %r13
je 0x6ed24
subq %r13, %r15
addq $0x8, %r15
movq %r14, %rdi
subq %r13, %rdi
addq $0x8, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x42a0
movq (%rbx), %rax
movq %rax, (%r14,%r12,8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movq 0x8(%rax), %rsi
movl $0x1, %eax
subq %r9, %rax
shlq $0x3, %r9
leaq (%r14,%rax,8), %rdi
movq %r9, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0