// File: /workspace/github_cpp_makefile_star2_O2/Baobaobear[P]sort/./grailsort.hpp
// Function: void Mrrl::grail_MergeBuffersLeft<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, baobao::TestClass*, baobao::TestClass*, int, int, bool, int, int, std::less<baobao::TestClass>)
void grail_MergeBuffersLeft(RandomAccessIterator keys, RandomAccessIterator midkey, RandomAccessIterator arr, int nblock, int lblock, bool havebuf, int nblock2, int llast, Comp compare) {
    RandomAccessIterator prest, pidx;
    int lrest, frest;

    if (nblock == 0) {
        int l = nblock2*lblock;
        if (havebuf) grail_MergeLeft(arr, arr + l, arr + l + llast, arr - lblock, compare);
        else grail_MergeWithoutBuffer(arr, arr + l, arr + l + llast, compare);
        return;
    }

    lrest = lblock;
    frest = compare(*keys, *midkey) ? 0 : 1;
    pidx = arr + lblock;
    for (int cidx = 1; cidx < nblock; cidx++, pidx += lblock) {
        prest = pidx - lrest;
        int fnext = compare(*(keys + cidx), *midkey) ? 0 : 1;
        if (fnext == frest) {
            if (havebuf) grail_swapN(prest - lblock, prest, lrest);
            prest = pidx;
            lrest = lblock;
        }
        else {
            if (havebuf) {
                grail_SmartMergeWithBuffer(prest, &lrest, &frest, prest + lrest + lblock, prest - lblock, compare);
            }
            else {
                grail_SmartMergeWithoutBuffer(prest, &lrest, &frest, prest + lrest + lblock, compare);
            }

        }
    }
    prest = pidx - lrest;
    if (llast) {
        if (frest) {
            if (havebuf) grail_swapN(prest - lblock, prest, lrest);
            prest = pidx;
            lrest = lblock*nblock2;
            frest = 0;
        }
        else {
            lrest += lblock*nblock2;
        }
        if (havebuf) grail_MergeLeft(prest, prest + lrest, prest + lrest + llast, prest - lblock, compare);
        else grail_MergeWithoutBuffer(prest, prest + lrest, prest + lrest + llast, compare);
    }
    else {
        if (havebuf) grail_swapN(prest, prest - lblock, lrest);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
movl 0x78(%rsp), %eax
movl 0x70(%rsp), %edx
testl %ecx, %ecx
je 0xa60e
movq %rdi, %r15
movl %edx, 0x14(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x4(%rsp), %rax
movl %r8d, (%rax)
movl (%rdi), %eax
xorl %edx, %edx
cmpl (%rsi), %eax
setge %dl
leaq 0x8(%rsp), %rax
movl %edx, (%rax)
movl %r8d, 0x10(%rsp)
movslq %r8d, %rdx
movq %rdx, %rax
negq %rax
movq %rax, 0x28(%rsp)
movslq %ecx, %rbx
addq $0x20, %r15
movq %rdx, %rbp
shlq $0x5, %rbp
leaq (%r14,%rbp), %r12
shlq $0x6, %rdx
movq %rdx, 0x30(%rsp)
pushq $0x1
popq %r13
movl %r9d, 0xc(%rsp)
movq %rsi, 0x18(%rsp)
movslq 0x4(%rsp), %rdx
movq %rdx, %rax
shlq $0x5, %rax
movq %r12, %r10
subq %rax, %r10
cmpq %rbx, %r13
jge 0xa5cf
movl (%r15), %ecx
xorl %edi, %edi
cmpl (%rsi), %ecx
setge %dil
cmpl %edi, 0x8(%rsp)
jne 0xa57a
testb %r9b, %r9b
je 0xa570
movq %r14, %rdi
subq %rax, %rdi
movq %r10, %rsi
callq 0xa23a
movq 0x18(%rsp), %rsi
movl 0xc(%rsp), %r9d
movl 0x10(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0xa5bd
movq 0x30(%rsp), %rcx
addq %r14, %rcx
testb %r9b, %r9b
je 0xa5a1
movq %r14, %r8
subq %rax, %r8
movq %r10, %rdi
leaq 0x4(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0xa7ac
jmp 0xa5b3
movq %r10, %rdi
leaq 0x4(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0xa887
movl 0xc(%rsp), %r9d
movq 0x18(%rsp), %rsi
incq %r13
addq $0x20, %r15
addq %rbp, %r12
addq %rbp, %r14
jmp 0xa527
movl 0x24(%rsp), %ebx
testl %ebx, %ebx
je 0xa64e
cmpl $0x0, 0x8(%rsp)
je 0xa679
testb %r9b, %r9b
movl 0x14(%rsp), %ebp
je 0xa5fe
subq %rax, %r14
movq %r14, %rdi
movq %r10, %rsi
callq 0xa23a
movl 0xc(%rsp), %r9d
imull 0x10(%rsp), %ebp
movl %ebp, 0x4(%rsp)
andl $0x0, 0x8(%rsp)
jmp 0xa68b
imull %r8d, %edx
movslq %edx, %rsi
shlq $0x5, %rsi
addq %r14, %rsi
movslq %eax, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
testb %r9b, %r9b
je 0xa663
movslq %r8d, %rax
shlq $0x5, %rax
movq %r14, %rcx
subq %rax, %rcx
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa147
testb %r9b, %r9b
je 0xa6c2
subq %rax, %r14
movq %r10, %rdi
movq %r14, %rsi
callq 0xa23a
jmp 0xa6c2
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9ee4
movl 0x14(%rsp), %ebp
imull 0x10(%rsp), %ebp
addl %edx, %ebp
movl %ebp, 0x4(%rsp)
movq %r10, %r12
movslq %ebp, %rsi
shlq $0x5, %rsi
addq %r12, %rsi
movslq %ebx, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
testb %r9b, %r9b
je 0xa6ba
movq 0x28(%rsp), %rcx
shlq $0x5, %rcx
addq %r12, %rcx
movq %r12, %rdi
callq 0xa147
jmp 0xa6c2
movq %r12, %rdi
callq 0x9ee4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq