// File: /workspace/github_cpp_makefile_star2_O3/Baobaobear[P]sort/./grailsort.hpp
// Function: void Mrrl::grail_SmartMergeWithBuffer<baobao::TestClass*, std::less<baobao::TestClass>>(baobao::TestClass*, int*, int*, baobao::TestClass*, baobao::TestClass*, std::less<baobao::TestClass>)
void grail_SmartMergeWithBuffer(RandomAccessIterator beg, int *alen1, int *atype, RandomAccessIterator end, RandomAccessIterator lkeys, Comp compare) {
    RandomAccessIterator p0 = lkeys, p1 = beg, p2 = beg + *alen1, q1 = p2, q2 = end;
    int ftype = !*atype;  // 1 if inverted
    while (p1 < q1 && p2 < q2) {
        if (grail_cmp(*p1, *p2, compare) - ftype < 0)
            grail_swap1(p0++, p1++);
        else grail_swap1(p0++, p2++);
    }
    if (p1 < q1) {
        *alen1 = (int)(q1 - p1);
        while (p1 < q1) grail_swap1(--q1, --q2);
    } else {
        *alen1 = (int)(q2 - p2);
        *atype = ftype;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl (%rsi), %eax
movslq %eax, %rbx
movq %rbx, %rax
shlq $0x5, %rax
addq %rdi, %rax
movl (%rdx), %r11d
xorl %r9d, %r9d
testl %r11d, %r11d
sete %r10b
testl %ebx, %ebx
setg %bpl
cmpq %rcx, %rax
setb %bl
andb %bpl, %bl
cmpb $0x1, %bl
jne 0xd79d
movq %rax, %rbx
testl %r11d, %r11d
sete %bpl
movl (%rdi), %r12d
movl (%rbx), %r13d
cmpl %r12d, %r13d
setge %r14b
leaq 0x8(%r8), %r15
cmpl %r13d, %r12d
jl 0xd727
andb %r14b, %bpl
jne 0xd727
movl (%r8), %ebp
movl 0x4(%r8), %r14d
movq 0x10(%r15), %r12
movq %r12, -0x8(%rsp)
movups (%r15), %xmm0
movaps %xmm0, -0x18(%rsp)
movl (%rbx), %r15d
movl %r15d, (%r8)
movl 0x4(%rbx), %r15d
movl %r15d, 0x4(%r8)
leaq 0x8(%rbx), %r15
movl $0x2, %r12d
movl (%rbx,%r12,4), %r13d
movl %r13d, (%r8,%r12,4)
incq %r12
cmpq $0x8, %r12
jne 0xd70a
movl %ebp, (%rbx)
movl %r14d, 0x4(%rbx)
addq $0x20, %rbx
jmp 0xd773
movl (%r8), %ebp
movl 0x4(%r8), %r14d
movq 0x10(%r15), %r12
movq %r12, -0x8(%rsp)
movups (%r15), %xmm0
movaps %xmm0, -0x18(%rsp)
movl (%rdi), %r15d
movl %r15d, (%r8)
movl 0x4(%rdi), %r15d
movl %r15d, 0x4(%r8)
leaq 0x8(%rdi), %r15
movl $0x2, %r12d
movl (%rdi,%r12,4), %r13d
movl %r13d, (%r8,%r12,4)
incq %r12
cmpq $0x8, %r12
jne 0xd758
movl %ebp, (%rdi)
movl %r14d, 0x4(%rdi)
addq $0x20, %rdi
movq -0x8(%rsp), %r14
movq %r14, 0x10(%r15)
movaps -0x18(%rsp), %xmm0
movups %xmm0, (%r15)
cmpq %rax, %rdi
setb %bpl
jae 0xd7a0
addq $0x20, %r8
cmpq %rcx, %rbx
jb 0xd6b7
jmp 0xd7a0
movq %rax, %rbx
testb %bpl, %bpl
je 0xd830
movq %rax, %rdx
subq %rdi, %rdx
shrq $0x5, %rdx
movl %edx, (%rsi)
cmpq %rdi, %rax
jbe 0xd83f
leaq -0x20(%rax), %rdx
leaq -0x20(%rcx), %rsi
movl -0x20(%rax), %r8d
movl -0x1c(%rax), %r9d
movq -0x8(%rax), %r10
movq %r10, -0x8(%rsp)
movups -0x18(%rax), %xmm0
movaps %xmm0, -0x18(%rsp)
movl -0x20(%rcx), %r10d
movl %r10d, -0x20(%rax)
movl -0x1c(%rcx), %r10d
movl %r10d, -0x1c(%rax)
leaq -0x18(%rcx), %r10
movq $-0x18, %r11
movl (%rcx,%r11), %ebx
movl %ebx, (%rax,%r11)
addq $0x4, %r11
jne 0xd7fb
movl %r8d, -0x20(%rcx)
movl %r9d, -0x1c(%rcx)
movq -0x8(%rsp), %rax
movq %rax, 0x10(%r10)
movaps -0x18(%rsp), %xmm0
movups %xmm0, (%r10)
movq %rsi, %rcx
movq %rdx, %rax
cmpq %rdx, %rdi
jb 0xd7be
jmp 0xd83f
movb %r10b, %r9b
subq %rbx, %rcx
shrq $0x5, %rcx
movl %ecx, (%rsi)
movl %r9d, (%rdx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq