// File: Baobaobear[P]sort/./grailsort.hpp
// Function: void Mrrl::grail_SmartMergeWithoutBuffer<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, int*, int*, baobao::TestClass*, std::less<baobao::TestClass>)
void grail_SmartMergeWithoutBuffer(RandomAccessIterator beg, int *alen1, int *atype, RandomAccessIterator end, Comp compare) {
    int ftype;

    if (beg == end) return;
    RandomAccessIterator mid = beg + *alen1;
    ftype = !*atype;
    if ((mid - beg) && grail_cmp(*(mid - 1), *mid, compare) - ftype >= 0) {
        while (mid - beg) {
            RandomAccessIterator p = (ftype ? grail_BinSearchLeft(mid, end, beg, compare) : grail_BinSearchRight(mid, end, beg, compare));
            if (p > mid) {
                grail_rotate(beg, mid, p);
                beg += p - mid;
                mid = p;
            }
            if (mid == end) {
                *alen1 = (int)(mid - beg);
                return;
            }
            do {
                beg++;
            } while ((mid - beg) && grail_cmp(*beg, *mid, compare) - ftype < 0);
        }
    }
    *alen1 = (int)(end - beg); *atype = ftype;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq 0x58(%rsp), %rax
cmpq 0x40(%rsp), %rax
jne 0x17b99
jmp 0x17d54
movq 0x58(%rsp), %rax
movq 0x50(%rsp), %rcx
movslq (%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rax
cmpl $0x0, (%rax)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x3c(%rsp)
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x0, %rax
je 0x17d2f
movq 0x30(%rsp), %rdi
addq $-0x20, %rdi
movq 0x30(%rsp), %rsi
callq 0x17970
subl 0x3c(%rsp), %eax
cmpl $0x0, %eax
jl 0x17d2f
jmp 0x17c05
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
cmpq $0x0, %rax
je 0x17d2d
cmpl $0x0, 0x3c(%rsp)
je 0x17c42
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x169f0
movq %rax, 0x10(%rsp)
jmp 0x17c5b
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x17d60
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x30(%rsp), %rax
jbe 0x17cae
movq 0x58(%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 0x58(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x40(%rsp), %rax
jne 0x17cd6
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
movl %eax, %ecx
movq 0x50(%rsp), %rax
movl %ecx, (%rax)
jmp 0x17d54
jmp 0x17cd8
movq 0x58(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x58(%rsp)
movq 0x30(%rsp), %rcx
movq 0x58(%rsp), %rax
subq %rax, %rcx
sarq $0x5, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0xf(%rsp)
je 0x17d20
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x17970
subl 0x3c(%rsp), %eax
cmpl $0x0, %eax
setl %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x17cd8
jmp 0x17c05
jmp 0x17d2f
movq 0x40(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
sarq $0x5, %rax
movl %eax, %ecx
movq 0x50(%rsp), %rax
movl %ecx, (%rax)
movl 0x3c(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, (%rax)
addq $0x68, %rsp
retq
nopl (%rax)