// File: /workspace/github_cpp_makefile_star2_O3/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), %r11d
movl 0x80(%rsp), %ebp
testl %ecx, %ecx
je 0xd378
movq %rdi, %r10
movl %r8d, 0x4(%rsp)
movl (%rdi), %eax
xorl %edx, %edx
cmpl (%rsi), %eax
setge %dl
movl %edx, 0x8(%rsp)
movslq %r8d, %r14
movq %r14, %r13
shlq $0x5, %r13
addq %r13, %rbx
cmpl $0x2, %ecx
jl 0xd3bc
movl %ebp, 0x2c(%rsp)
movl %r8d, 0xc(%rsp)
movl %r11d, 0x30(%rsp)
negq %r14
movl %ecx, %eax
movq %rax, 0x38(%rsp)
leaq 0x8(%r13), %r15
movl $0x1, %r12d
shlq $0x5, %r14
movl %r9d, 0x34(%rsp)
movq %rsi, 0x40(%rsp)
movq %r10, %rbp
movslq 0x4(%rsp), %rax
movq %rax, %rcx
shlq $0x5, %rcx
movq %rbx, %rdi
subq %rcx, %rdi
movq %r12, %rcx
shlq $0x5, %rcx
movl (%r10,%rcx), %ecx
xorl %edx, %edx
cmpl (%rsi), %ecx
setge %dl
cmpl %edx, 0x8(%rsp)
jne 0xd316
testl %eax, %eax
setne %cl
andb %r9b, %cl
cmpb $0x1, %cl
jne 0xd30c
leaq (%rdi,%r14), %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 %r15, %r10
movl (%rcx,%r10), %r11d
movl %r11d, (%rcx,%r9)
addq $0x4, %r9
addq $0x4, %r10
cmpq $0x20, %r9
jne 0xd2d2
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 0xd2a0
movl 0xc(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0xd343
leaq (%rbx,%r13), %rcx
testb %r9b, %r9b
je 0xd334
leaq (%rdi,%r14), %r8
leaq 0x4(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0xd676
jmp 0xd343
leaq 0x4(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0xd84a
incq %r12
addq %r13, %rbx
cmpq 0x38(%rsp), %r12
movl 0x34(%rsp), %r9d
movq 0x40(%rsp), %rsi
movq %rbp, %r10
jne 0xd261
movl 0x4(%rsp), %ecx
movslq %ecx, %r14
movl 0x30(%rsp), %r11d
movl 0xc(%rsp), %r8d
movl 0x2c(%rsp), %ebp
jmp 0xd3bf
imull %r8d, %ebp
movslq %ebp, %rsi
shlq $0x5, %rsi
addq %rbx, %rsi
movslq %r11d, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
testb %r9b, %r9b
je 0xd4f2
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 0xcc89
movl %r8d, %ecx
movq %r14, %rdx
shlq $0x5, %rdx
movq %rbx, %rax
subq %rdx, %rax
testl %r11d, %r11d
je 0xd467
cmpl $0x0, 0x8(%rsp)
je 0xd508
testl %ecx, %ecx
setne %cl
andb %r9b, %cl
cmpb $0x1, %cl
jne 0xd452
movq %rax, %rcx
subq %r13, %rcx
movl (%rcx), %edx
movl 0x4(%rcx), %esi
movq 0x18(%rcx), %rdi
movq %rdi, 0x20(%rsp)
movups 0x8(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl (%rax), %edi
movl %edi, (%rcx)
movl 0x4(%rax), %edi
movl %edi, 0x4(%rcx)
leaq 0x8(%rax), %rdi
movl $0x2, %r15d
movl (%rax,%r15,4), %r10d
movl %r10d, (%rcx,%r15,4)
incq %r15
cmpq $0x8, %r15
jne 0xd41e
addq $0x20, %rcx
movl %edx, (%rax)
movl %esi, 0x4(%rax)
addq $0x20, %rax
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rdi)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rdi)
decq %r14
jne 0xd3f3
imull %r8d, %ebp
movl %ebp, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
jmp 0xd515
testl %ecx, %ecx
setne %cl
andb %cl, %r9b
cmpb $0x1, %r9b
jne 0xd546
movq %rax, %rdx
subq %r13, %rdx
leaq 0x8(%rax), %rcx
negq %r13
movl (%rax), %esi
movl 0x4(%rax), %edi
movq 0x18(%rax), %r8
movq %r8, 0x20(%rsp)
movups 0x8(%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movl (%rdx), %r8d
movl %r8d, (%rax)
movl 0x4(%rdx), %r8d
movl %r8d, 0x4(%rax)
leaq 0x8(%rdx), %r8
movl $0x6, %r9d
movq %rcx, %r10
movl (%r10,%r13), %r11d
movl %r11d, (%r10)
addq $0x4, %r10
decq %r9
jne 0xd4b8
addq $0x20, %rax
movl %esi, (%rdx)
movl %edi, 0x4(%rdx)
addq $0x20, %rdx
addq $0x20, %rcx
movq 0x20(%rsp), %rsi
movq %rsi, 0x10(%r8)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%r8)
decq %r14
jne 0xd486
jmp 0xd546
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc9ca
imull %r8d, %ebp
addl %ecx, %ebp
movl %ebp, 0x4(%rsp)
movq %rax, %rbx
movslq %ebp, %rsi
shlq $0x5, %rsi
addq %rbx, %rsi
movslq %r11d, %rdx
shlq $0x5, %rdx
addq %rsi, %rdx
testb %r9b, %r9b
je 0xd53e
movq %rbx, %rcx
subq %r13, %rcx
movq %rbx, %rdi
callq 0xcc89
jmp 0xd546
movq %rbx, %rdi
callq 0xc9ca
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq