// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, %rbp
movq %rsi, %rbx
movq %r8, %r13
movq %rcx, %r15
movq %rdi, %r14
movq %rcx, %rsi
movq %r8, %rdx
callq 0x5355e
movq %rbx, %rdx
leaq -0x8(,%r13,8), %rbx
addq 0x8(%r14), %rbx
movq -0x8(%rdx,%rbp,8), %rax
movq %r15, %rcx
leaq -0x10(%r15,%r13,8), %r15
movq %rbp, %r12
decq %r12
movq %r14, 0x8(%rsp)
movq %rax, 0x8(%r15)
je 0x5327d
leaq -0x10(%rdx,%rbp,8), %r14
cmpq $0x1, %r13
jne 0x532a5
leaq -0x8(%rdx,%rbp,8), %rdx
pushq $0x1
popq %r12
subq %rbp, %r12
leaq 0x8(%r14,%r12,8), %rsi
subq %rsi, %rdx
je 0x53271
leaq -0x8(%rcx,%r13,8), %rdi
subq %rdx, %rdi
callq 0x4290
movq (%rbx), %rax
movq %rax, (%r15,%r12,8)
jmp 0x534e0
testq %r13, %r13
je 0x534e0
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
pushq $0x1
popq %rax
subq %r13, %rax
shlq $0x3, %r13
leaq (%r15,%rax,8), %rdi
movq %r13, %rdx
jmp 0x53509
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %r8d
xorl %eax, %eax
xorl %ecx, %ecx
movq %r13, %rbp
movq (%rbx), %r9
movq (%r14), %rsi
movq (%r9), %rdi
cmpq (%rsi), %rdi
jae 0x532e1
addq $-0x8, %r14
decq %r12
movq %rsi, (%r15)
je 0x53467
incl %eax
xorl %ecx, %ecx
jmp 0x532f9
addq $-0x8, %rbx
decq %rbp
movq %r9, (%r15)
cmpq $0x1, %rbp
je 0x53461
incl %ecx
xorl %eax, %eax
movl %ecx, %esi
addq $-0x8, %r15
orl %eax, %esi
cmpl %r8d, %esi
jl 0x532bd
movq %rdx, 0x18(%rsp)
movq 0x8(%rsp), %rdi
leaq -0x1(%r12), %r8
movq %rbx, %rsi
movq %r12, %rcx
callq 0x52e0e
movq %r12, %rcx
subq %rax, %rcx
movq %rcx, 0x20(%rsp)
testl %ecx, %ecx
je 0x5337a
movslq %ecx, %r13
movq %rcx, %rdx
shlq $0x20, %rdx
leaq (,%r13,8), %rax
subq %rax, %r15
subq %rax, %r14
testq %rdx, %rdx
je 0x53371
movabsq $0x100000000, %rax      # imm = 0x100000000
leaq 0x8(%r14), %rsi
addq %rax, %rdx
sarq $0x1d, %rdx
leaq (%r15,%rdx), %rdi
addq $-0x8, %rdx
subq %rdx, %rdi
callq 0x4290
subq %r13, %r12
je 0x53489
movq (%rbx), %rax
addq $-0x8, %rbx
leaq -0x1(%rbp), %r13
movq %rax, (%r15)
addq $-0x8, %r15
cmpq $0x1, %r13
je 0x5346d
movq 0x8(%rsp), %rdi
addq $-0x2, %rbp
movq %r14, %rsi
movq %r13, %rcx
movq %rbp, %r8
movq 0x8(%rdi), %rdx
callq 0x5386a
movq %r13, %rcx
subq %rax, %rcx
testl %ecx, %ecx
je 0x53411
movslq %ecx, %rbp
movq %rcx, %rdx
shlq $0x20, %rdx
leaq (,%rbp,8), %rax
subq %rax, %r15
subq %rax, %rbx
testq %rdx, %rdx
je 0x53404
movabsq $0x100000000, %rax      # imm = 0x100000000
leaq 0x8(%rbx), %rsi
leaq 0x8(%r15), %rdi
movq %rcx, 0x10(%rsp)
addq %rax, %rdx
sarq $0x1d, %rdx
addq $-0x8, %rdx
callq 0x4290
movq 0x10(%rsp), %rcx
subq %rbp, %r13
cmpq $0x2, %r13
jl 0x5351c
movq (%r14), %rax
addq $-0x8, %r14
movq %rax, (%r15)
addq $-0x8, %r15
decq %r12
je 0x53486
decl 0x4(%rsp)
movq %r13, %rbp
cmpl $0x6, 0x20(%rsp)
movq 0x18(%rsp), %rdx
jg 0x5330b
movq %r13, %rbp
cmpl $0x6, %ecx
jg 0x5330b
movl 0x4(%rsp), %ecx
movl %ecx, %eax
sarl $0x1f, %eax
andnl %ecx, %eax, %ecx
addl $0x2, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x532b1
addq $-0x8, %r15
jmp 0x53472
addq $-0x8, %r15
jmp 0x5348e
movl 0x4(%rsp), %r8d
testl %r8d, %r8d
pushq $0x1
popq %rax
movq 0x8(%rsp), %rcx
cmovlel %r8d, %eax
movl %eax, 0x4(%rcx)
jmp 0x534ae
movq %r13, %rbp
movl 0x4(%rsp), %r8d
xorl %r12d, %r12d
testl %r8d, %r8d
pushq $0x1
popq %rax
movq 0x8(%rsp), %rcx
cmovlel %r8d, %eax
movl %eax, 0x4(%rcx)
testq %rbp, %rbp
je 0x534e0
cmpq $0x1, %rbp
jne 0x534ef
movq %r12, %r13
negq %r13
shlq $0x3, %r12
testq %r12, %r12
je 0x534d9
subq %r12, %r14
movq %r15, %rdi
subq %r12, %rdi
movq %r12, %rdx
addq $0x8, %r14
addq $0x8, %rdi
movq %r14, %rsi
callq 0x4290
movq (%rbx), %rax
movq %rax, (%r15,%r13,8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
pushq $0x1
popq %rax
subq %rbp, %rax
shlq $0x3, %rbp
leaq (%r15,%rax,8), %rdi
movq %rbp, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4290
movl 0x4(%rsp), %r8d
movq %r13, %rbp
jmp 0x53491