// 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>>::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 $0x28, %rsp
movq %r8, %r12
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbx
callq 0x6ed68
movq %r12, %rcx
movq %rbx, 0x10(%rsp)
movq 0x8(%rbx), %rbx
movq (%r14), %rax
leaq 0x8(%r13), %r12
movq %rax, (%r13)
movq %rcx, %rbp
decq %rbp
je 0x6e7f9
addq $0x8, %r14
cmpq $0x1, %r15
jne 0x6e807
leaq (,%rcx,8), %rdx
cmpq $0x8, %rdx
je 0x6e7ec
addq $-0x8, %rdx
movq %r12, %rdi
movq %r14, %rsi
movq %rcx, %r14
callq 0x42a0
movq %r14, %rcx
movq (%rbx), %rax
movq %rax, (%r13,%rcx,8)
jmp 0x6e9fb
testq %r15, %r15
jne 0x6ea0a
jmp 0x6e9fb
movq 0x10(%rsp), %rax
movl 0x4(%rax), %r8d
addq $0x8, %r12
movq %r12, %rdx
xorl %eax, %eax
xorl %ecx, %ecx
movq %rdx, %r12
movq (%r14), %rdx
movq (%rbx), %rsi
movq (%rdx), %rdi
cmpq (%rsi), %rdi
jae 0x6e840
addq $0x8, %r14
movq %rdx, -0x8(%r12)
xorl %eax, %eax
decq %rbp
je 0x6e872
incl %ecx
jmp 0x6e856
addq $0x8, %rbx
movq %rsi, -0x8(%r12)
decq %r15
cmpq $0x1, %r15
je 0x6e868
incl %eax
xorl %ecx, %ecx
movl %ecx, %esi
orl %eax, %esi
leaq 0x8(%r12), %rdx
cmpl %r8d, %esi
jl 0x6e81b
xorl %eax, %eax
jmp 0x6e876
movl $0x1, %r15d
movb $0x1, %al
jmp 0x6e876
movb $0x1, %al
xorl %ebp, %ebp
testb %al, %al
jne 0x6e9a0
movl %eax, 0x1c(%rsp)
movl %r8d, 0xc(%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x6eda4
testl %eax, %eax
movq %rax, 0x20(%rsp)
je 0x6e8d9
movq %rax, %rdx
shlq $0x20, %rdx
movslq %eax, %r13
leaq (%r12,%r13,8), %r12
je 0x6e8c8
sarq $0x1d, %rdx
movq %r12, %rdi
subq %rdx, %rdi
movq %rbx, %rsi
callq 0x42a0
leaq (%rbx,%r13,8), %rbx
subq %r13, %r15
cmpq $0x2, %r15
jl 0x6e98a
movl 0xc(%rsp), %r8d
movq (%r14), %rcx
addq $0x8, %r14
movq %rcx, (%r12)
addq $0x8, %r12
decq %rbp
movb $0x1, %cl
je 0x6e97e
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x6e694
movq %rax, %r13
testl %r13d, %r13d
je 0x6e93e
movq %r13, %rdx
shlq $0x20, %rdx
je 0x6e92e
sarq $0x1d, %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x42a0
movslq %r13d, %rax
leaq (%r14,%rax,8), %r14
leaq (%r12,%rax,8), %r12
subq %rax, %rbp
je 0x6e993
movl 0xc(%rsp), %r8d
movq (%rbx), %rax
addq $0x8, %rbx
movq %rax, (%r12)
addq $0x8, %r12
decq %r15
cmpq $0x1, %r15
movq 0x20(%rsp), %rax
je 0x6e982
decl %r8d
cmpl $0x6, %eax
jg 0x6e882
cmpl $0x6, %r13d
jg 0x6e882
movl 0x1c(%rsp), %eax
movl %eax, %ecx
jmp 0x6e99c
xorl %ebp, %ebp
jmp 0x6e99c
movl $0x1, %r15d
jmp 0x6e99a
movb $0x1, %cl
movl 0xc(%rsp), %r8d
jmp 0x6e99c
xorl %ebp, %ebp
movl 0xc(%rsp), %r8d
movb $0x1, %cl
testb %cl, %cl
je 0x6e9a4
xorl %eax, %eax
jmp 0x6e9b5
movl %r8d, %eax
sarl $0x1f, %eax
andnl %r8d, %eax, %r8d
addl $0x2, %r8d
movb $0x1, %al
testb %al, %al
jne 0x6e810
testl %r8d, %r8d
movl $0x1, %eax
cmovlel %r8d, %eax
movq 0x10(%rsp), %rcx
movl %eax, 0x4(%rcx)
testq %r15, %r15
je 0x6e9fb
cmpq $0x1, %r15
jne 0x6ea0a
testq %rbp, %rbp
je 0x6e9f4
leaq (,%rbp,8), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x42a0
movq (%rbx), %rax
movq %rax, (%r12,%rbp,8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shlq $0x3, %r15
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0