// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rdx, %rbx
movl 0x88(%rsp), %eax
movl 0x80(%rsp), %edx
testl %ecx, %ecx
je 0xd602
movq %rdi, %r10
movl %edx, 0xc(%rsp)
movl %eax, 0x30(%rsp)
movl %r8d, (%rsp)
movl (%rdi), %eax
xorl %edx, %edx
cmpl (%rsi), %eax
setge %dl
movl %edx, 0x4(%rsp)
movl %r8d, 0x8(%rsp)
movslq %r8d, %rax
movq %rax, %r13
shlq $0x5, %r13
addq %r13, %rbx
cmpl $0x2, %ecx
jl 0xd54a
negq %rax
movl %ecx, %ecx
movq %rcx, 0x40(%rsp)
leaq 0x8(%r13), %r14
movl $0x1, %r15d
shlq $0x5, %rax
movq %rax, 0x38(%rsp)
movl %r9d, 0x34(%rsp)
movq %rsi, %rbp
movq %r10, %r12
movslq (%rsp), %rax
movq %rax, %rcx
shlq $0x5, %rcx
movq %rbx, %rdi
subq %rcx, %rdi
movq %r15, %rcx
shlq $0x5, %rcx
movl (%r10,%rcx), %ecx
xorl %edx, %edx
cmpl (%rsi), %ecx
setge %dl
cmpl %edx, 0x4(%rsp)
jne 0xd500
testl %eax, %eax
setne %cl
andb %r9b, %cl
cmpb $0x1, %cl
jne 0xd4f7
movq 0x38(%rsp), %rcx
addq %rdi, %rcx
movl (%rcx), %edx
movl 0x4(%rcx), %esi
movq 0x18(%rcx), %r8
movq %r8, 0x20(%rsp)
movups 0x8(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl (%rdi), %r8d
movl %r8d, (%rcx)
movl 0x4(%rdi), %r8d
movl %r8d, 0x4(%rcx)
leaq 0x8(%rdi), %r8
movl $0x8, %r9d
movq %r14, %r10
movl (%rcx,%r10), %r11d
movl %r11d, (%rcx,%r9)
addq $0x4, %r9
addq $0x4, %r10
cmpq $0x20, %r9
jne 0xd4bd
addq $0x20, %rcx
movl %edx, (%rdi)
movl %esi, 0x4(%rdi)
addq $0x20, %rdi
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%r8)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%r8)
decq %rax
jne 0xd48b
movl 0x8(%rsp), %eax
movl %eax, (%rsp)
jmp 0xd52e
leaq (%rbx,%r13), %rcx
testb %r9b, %r9b
je 0xd521
movq 0x38(%rsp), %rax
leaq (%rdi,%rax), %r8
movq %rsp, %rsi
leaq 0x4(%rsp), %rdx
callq 0xd85c
jmp 0xd52e
movq %rsp, %rsi
leaq 0x4(%rsp), %rdx
callq 0xda30
incq %r15
addq %r13, %rbx
cmpq 0x40(%rsp), %r15
movl 0x34(%rsp), %r9d
movq %rbp, %rsi
movq %r12, %r10
jne 0xd449
movslq (%rsp), %rax
movq %rax, %rdx
shlq $0x5, %rdx
movq %rbx, %rcx
subq %rdx, %rcx
movl 0x30(%rsp), %ebp
testl %ebp, %ebp
je 0xd646
cmpl $0x0, 0x4(%rsp)
je 0xd6e9
testl %eax, %eax
setne %dl
andb %r9b, %dl
cmpb $0x1, %dl
jne 0xd5e9
movq %rcx, %rdx
subq %r13, %rdx
movl (%rdx), %esi
movl 0x4(%rdx), %edi
movq 0x18(%rdx), %r8
movq %r8, 0x20(%rsp)
movups 0x8(%rdx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl (%rcx), %r8d
movl %r8d, (%rdx)
movl 0x4(%rcx), %r8d
movl %r8d, 0x4(%rdx)
leaq 0x8(%rcx), %r8
movl $0x2, %r11d
movl (%rcx,%r11,4), %r10d
movl %r10d, (%rdx,%r11,4)
incq %r11
cmpq $0x8, %r11
jne 0xd5b4
addq $0x20, %rdx
movl %esi, (%rcx)
movl %edi, 0x4(%rcx)
addq $0x20, %rcx
movq 0x20(%rsp), %rsi
movq %rsi, 0x10(%r8)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%r8)
decq %rax
jne 0xd585
movl 0xc(%rsp), %eax
imull 0x8(%rsp), %eax
movl %eax, (%rsp)
movl $0x0, 0x4(%rsp)
jmp 0xd6fa
imull %r8d, %edx
movslq %edx, %rsi
shlq $0x5, %rsi
addq %rbx, %rsi
movslq %eax, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
testb %r9b, %r9b
je 0xd6d3
movslq %r8d, %rax
shlq $0x5, %rax
movq %rbx, %rcx
subq %rax, %rcx
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xce64
testl %eax, %eax
setne %dl
andb %dl, %r9b
cmpb $0x1, %r9b
jne 0xd72c
movq %rcx, %rsi
subq %r13, %rsi
leaq 0x8(%rcx), %rdx
negq %r13
movl (%rcx), %edi
movl 0x4(%rcx), %r8d
movq 0x18(%rcx), %r9
movq %r9, 0x20(%rsp)
movups 0x8(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl (%rsi), %r9d
movl %r9d, (%rcx)
movl 0x4(%rsi), %r9d
movl %r9d, 0x4(%rcx)
leaq 0x8(%rsi), %r9
movl $0x6, %r10d
movq %rdx, %r11
movl (%r11,%r13), %ebx
movl %ebx, (%r11)
addq $0x4, %r11
decq %r10
jne 0xd698
addq $0x20, %rcx
movl %edi, (%rsi)
movl %r8d, 0x4(%rsi)
addq $0x20, %rsi
addq $0x20, %rdx
movq 0x20(%rsp), %rdi
movq %rdi, 0x10(%r9)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%r9)
decq %rax
jne 0xd665
jmp 0xd72c
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcba0
movl 0xc(%rsp), %edx
imull 0x8(%rsp), %edx
addl %eax, %edx
movl %edx, (%rsp)
movq %rcx, %rbx
movslq (%rsp), %rsi
shlq $0x5, %rsi
addq %rbx, %rsi
movslq %ebp, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
testb %r9b, %r9b
je 0xd724
movq %rbx, %rcx
subq %r13, %rcx
movq %rbx, %rdi
callq 0xce64
jmp 0xd72c
movq %rbx, %rdi
callq 0xcba0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq