// File: Baobaobear[P]sort/./grailsort.hpp
// Function: void Mrrl::grail_MergeWithoutBuffer<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>)
void grail_MergeWithoutBuffer(RandomAccessIterator beg, RandomAccessIterator mid, RandomAccessIterator end, Comp compare) {
    if (mid - beg < end - mid) {
        while (mid - beg) {
            RandomAccessIterator p = grail_BinSearchLeft(mid, end, beg, compare);
            if (p != mid) {
                grail_rotate(beg, mid, p);
                beg += p - mid;
                mid = p;
            }
            if (mid == end) break;
            do {
                ++beg;
            } while ((mid - beg) && grail_lesseq(*beg, *mid, compare));
        }
    }
    else {
        while (end - mid) {
            RandomAccessIterator p = grail_BinSearchRight(beg, mid, end - 1, compare);
            if (p != mid) {
                grail_rotate(p, mid, end);
                end -= mid - p;
                mid = p;
            }
            if (beg == mid) break;
            do {
                --end;
            } while ((end - mid) && grail_lesseq(*(mid - 1), *(end - 1), compare));
        }
    }
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rdx
subq %rdx, %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
jge 0x168ed
jmp 0x16810
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x0, %rax
je 0x168e8
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x169f0
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x1688d
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x16af0
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
shlq $0x5, %rax
addq 0x38(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x28(%rsp), %rax
jne 0x1689b
jmp 0x168e8
jmp 0x1689d
movq 0x38(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x38(%rsp)
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
subq %rax, %rcx
sarq $0x5, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0xd(%rsp)
je 0x168db
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x17050
movb %al, 0xd(%rsp)
movb 0xd(%rsp), %al
testb $0x1, %al
jne 0x1689d
jmp 0x16810
jmp 0x169dd
jmp 0x168ef
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x0, %rax
je 0x169db
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq $-0x20, %rdx
callq 0x17d60
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x16978
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x16af0
movq 0x30(%rsp), %rdx
movq 0x10(%rsp), %rax
subq %rax, %rdx
sarq $0x5, %rdx
movq 0x28(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
jne 0x16986
jmp 0x169db
jmp 0x16988
movq 0x28(%rsp), %rax
addq $-0x20, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
subq %rax, %rcx
sarq $0x5, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0xc(%rsp)
je 0x169ce
movq 0x30(%rsp), %rdi
addq $-0x20, %rdi
movq 0x28(%rsp), %rsi
addq $-0x20, %rsi
callq 0x17050
movb %al, 0xc(%rsp)
movb 0xc(%rsp), %al
testb $0x1, %al
jne 0x16988
jmp 0x168ef
jmp 0x169dd
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)