// File: 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:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
movq %r8, 0x90(%rsp)
movq 0xb0(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0xe83c0
movq 0x10(%rsp), %rdi
addq $0x8, %rdi
callq 0xe8450
movq %rax, 0x88(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x80(%rsp)
movq (%rax), %rcx
movq 0x78(%rsp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq 0x90(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, %rax
jne 0xe742c
movq 0x88(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xa0(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xe84e0
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0xe8480
jmp 0xe792a
cmpq $0x1, 0xa0(%rsp)
jne 0xe7486
movq 0x80(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x90(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq 0x78(%rsp), %rdx
callq 0x15fd0
leaq 0x88(%rsp), %rdi
callq 0xe8520
movq (%rax), %rdx
movq 0x78(%rsp), %rax
movq 0x90(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0xe792a
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x64(%rsp)
movl $0x0, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movb $0x0, 0x5b(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x88(%rsp), %rdi
callq 0xe8520
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0xe5e40
testb $0x1, %al
jne 0xe74d9
jmp 0xe7540
movq 0x80(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x80(%rsp)
movq (%rax), %rcx
movq 0x78(%rsp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movl $0x0, 0x60(%rsp)
movq 0x90(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, %rax
jne 0xe753e
movb $0x1, 0x5b(%rsp)
jmp 0xe75bf
jmp 0xe75ab
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0xe8530
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xe8520
movq (%rax), %rcx
movq 0x78(%rsp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movq 0xa0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xa0(%rsp)
cmpq $0x1, %rax
jne 0xe75a9
movb $0x1, 0x5b(%rsp)
jmp 0xe75bf
jmp 0xe75ab
jmp 0xe75ad
movl 0x60(%rsp), %eax
orl 0x5c(%rsp), %eax
cmpl 0x64(%rsp), %eax
jl 0xe74a7
testb $0x1, 0x5b(%rsp)
je 0xe75cb
jmp 0xe7874
jmp 0xe75cd
movq 0x10(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xa0(%rsp), %rcx
movq 0x48(%rsp), %rdx
xorl %eax, %eax
movl %eax, %r8d
callq 0xe8570
movl %eax, 0x60(%rsp)
cmpl $0x0, 0x60(%rsp)
je 0xe76aa
movq 0x88(%rsp), %rax
movq %rax, 0x40(%rsp)
movslq 0x60(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xe84e0
movq %rax, 0x38(%rsp)
movq 0x78(%rsp), %rdx
movslq 0x60(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xe88e0
movl 0x60(%rsp), %ecx
movq 0x78(%rsp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
movslq 0x60(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xe8940
movslq 0x60(%rsp), %rcx
movq 0xa0(%rsp), %rax
subq %rcx, %rax
movq %rax, 0xa0(%rsp)
cmpq $0x1, 0xa0(%rsp)
jg 0xe76a8
movb $0x1, 0x5b(%rsp)
jmp 0xe784c
jmp 0xe76aa
movq 0x80(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x80(%rsp)
movq (%rax), %rcx
movq 0x78(%rsp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq 0x90(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, %rax
jne 0xe76fc
movb $0x1, 0x5b(%rsp)
jmp 0xe784c
leaq 0x88(%rsp), %rdi
callq 0xe8520
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq 0x80(%rsp), %rdx
movq 0x90(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0xe70c0
movl %eax, 0x5c(%rsp)
cmpl $0x0, 0x5c(%rsp)
je 0xe77c5
movq 0x80(%rsp), %rdi
movq 0x80(%rsp), %rsi
movslq 0x5c(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq 0x78(%rsp), %rdx
callq 0x15fd0
movl 0x5c(%rsp), %ecx
movq 0x78(%rsp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
movl 0x5c(%rsp), %ecx
movq 0x80(%rsp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x80(%rsp)
movslq 0x5c(%rsp), %rcx
movq 0x90(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x90(%rsp)
jne 0xe77c3
movb $0x1, 0x5b(%rsp)
jmp 0xe784c
jmp 0xe77c5
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0xe8530
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
callq 0xe8520
movq (%rax), %rcx
movq 0x78(%rsp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq 0xa0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xa0(%rsp)
cmpq $0x1, %rax
jne 0xe781b
movb $0x1, 0x5b(%rsp)
jmp 0xe784c
movl 0x64(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x64(%rsp)
cmpl $0x7, 0x60(%rsp)
setge %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x7, 0x5c(%rsp)
setge %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
cmpl $0x0, %eax
jne 0xe75cd
testb $0x1, 0x5b(%rsp)
je 0xe7855
jmp 0xe7874
cmpl $0x0, 0x64(%rsp)
jge 0xe7864
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x64(%rsp)
jmp 0xe7492
movl $0x1, 0x2c(%rsp)
leaq 0x64(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
callq 0xe8960
movq %rax, %rcx
movq 0x10(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x4(%rax)
cmpq $0x1, 0xa0(%rsp)
jne 0xe78ef
movq 0x80(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x90(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq 0x78(%rsp), %rdx
callq 0x15fd0
leaq 0x88(%rsp), %rdi
callq 0xe8520
movq (%rax), %rdx
movq 0x78(%rsp), %rax
movq 0x90(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0xe792a
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xa0(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xe84e0
movq %rax, 0x18(%rsp)
movq 0x78(%rsp), %rdx
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0xe8480
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)