// 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>>::mergeLo(Trivial<8>**, long, Trivial<8>**, long)
void mergeLo(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(base1, len1);

		tmp_iter_t cursor1 = tmp_.begin();
		iter_t cursor2 = base2;
		iter_t dest = base1;

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

		int minGallop(minGallop_);

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

			bool break_outer = false;
			do
			{
				assert(len1 > 1 && len2 > 0);

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

			do
			{
				assert(len1 > 1 && len2 > 0);
				count1 = gallopRight(*cursor2, cursor1, len1, 0);

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

					if (len1 <= 1)
					{
						break_outer = true;
						break;
					}
				}

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

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

				count2 = gallopLeft(*cursor1, cursor2, len2, 0);

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

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

				if (--len1 == 1)
				{
					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 (len1 == 1)
		{
			assert(len2 > 0);
			PLF_TIMSORT_MOVE_RANGE(cursor2, cursor2 + len2, dest);
			*(dest + len2) = PLF_TIMSORT_MOVE(*cursor1);
		}
		else
		{
			assert(len1 != 0 && "Comparison function violates its general contract");
			assert(len2 == 0);
			assert(len1 > 1);
			PLF_TIMSORT_MOVE_RANGE(cursor1, cursor1 + len1, dest);
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, %rbx
callq 0x5355e
movq %rbx, 0x8(%rsp)
movq 0x8(%rbx), %rbx
movq (%r15), %rax
movq %r14, %rcx
movq %rcx, %r12
leaq 0x8(%r13), %r14
decq %r12
movq %rax, (%r13)
je 0x52fe7
addq $0x8, %r15
cmpq $0x1, %rbp
jne 0x52ff5
leaq (,%rcx,8), %rdx
cmpq $0x8, %rdx
je 0x52fda
addq $-0x8, %rdx
movq %r14, %rdi
movq %r15, %rsi
movq %rcx, %r14
callq 0x4290
movq %r14, %rcx
movq (%rbx), %rax
movq %rax, (%r13,%rcx,8)
jmp 0x531be
testq %rbp, %rbp
jne 0x531cd
jmp 0x531be
movq 0x8(%rsp), %r13
movl 0x4(%r13), %r8d
xorl %eax, %eax
xorl %ecx, %ecx
movq (%r15), %rdx
movq (%rbx), %rsi
movq (%rdx), %rdi
cmpq (%rsi), %rdi
jae 0x53026
addq $0x8, %r15
decq %r12
movq %rdx, (%r14)
je 0x5315b
incl %ecx
xorl %eax, %eax
jmp 0x5303e
addq $0x8, %rbx
decq %rbp
movq %rsi, (%r14)
cmpq $0x1, %rbp
je 0x53155
incl %eax
xorl %ecx, %ecx
movl %ecx, %edx
addq $0x8, %r14
orl %eax, %edx
cmpl %r8d, %edx
jl 0x53002
movl %r8d, 0x4(%rsp)
movq %r15, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x5359a
testl %eax, %eax
je 0x530a8
movq %rax, %rdx
shlq $0x20, %rdx
je 0x53090
sarq $0x1d, %rdx
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %r13
callq 0x4290
movq %r13, %rax
movq 0x8(%rsp), %r13
movslq %eax, %rcx
leaq (%rbx,%rcx,8), %rbx
leaq (%r14,%rcx,8), %r14
subq %rcx, %rbp
cmpq $0x2, %rbp
jl 0x53181
movq (%r15), %rcx
addq $0x8, %r15
movq %rcx, (%r14)
addq $0x8, %r14
decq %r12
je 0x5317e
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x52eb8
movq %rax, %r13
testl %r13d, %r13d
je 0x53108
movq %r13, %rdx
shlq $0x20, %rdx
je 0x530f8
sarq $0x1d, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4290
movslq %r13d, %rax
leaq (%r15,%rax,8), %r15
leaq (%r14,%rax,8), %r14
subq %rax, %r12
je 0x53179
movq (%rbx), %rax
movl 0x4(%rsp), %r8d
addq $0x8, %rbx
decq %rbp
movq %rax, (%r14)
addq $0x8, %r14
cmpq $0x1, %rbp
je 0x53164
decl %r8d
cmpl $0x6, 0x10(%rsp)
jg 0x5304b
cmpl $0x6, %r13d
jg 0x5304b
movq 0x8(%rsp), %r13
movl %r8d, %eax
sarl $0x1f, %eax
andnl %r8d, %eax, %r8d
addl $0x2, %r8d
jmp 0x52ffe
addq $0x8, %r14
jmp 0x53169
addq $0x8, %r14
xorl %r12d, %r12d
jmp 0x53186
movq 0x8(%rsp), %r13
testl %r8d, %r8d
pushq $0x1
popq %rax
cmovlel %r8d, %eax
movl %eax, 0x4(%r13)
jmp 0x5319f
movq 0x8(%rsp), %r13
xorl %r12d, %r12d
movl 0x4(%rsp), %r8d
testl %r8d, %r8d
pushq $0x1
popq %rax
cmovlel %r8d, %eax
movl %eax, 0x4(%r13)
testq %rbp, %rbp
je 0x531be
cmpq $0x1, %rbp
jne 0x531cd
testq %r12, %r12
je 0x531b7
leaq (,%r12,8), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4290
movq (%rbx), %rax
movq %rax, (%r14,%r12,8)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shlq $0x3, %rbp
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4290
nop