// File: /workspace/github_c_makefile_star2_O1/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/sort/sort.c
// Function: sort
void sort(int l, int r, void *args, sort_compare_function compare,
          sort_swap_function swap) {
    if (l < r) {
        int left = l;
        int right = r;
        int mid = l;

        int a = compare(args, l, r), b = compare(args, l, (l + r) / 2),
            c = compare(args, (l + r) / 2, r);
        if (a == b && b == c) {
            mid = (l + r) / 2;
        } else if (a == c) {
            mid = l;
        } else {
            mid = r;
        }

        while (left < right) {
            while (left < right && mid < right &&
                   compare(args, mid, right) < 0) {
                right--;
            }
            if (left < right && mid < right) {
                swap(args, left++, right);
                mid = right;
            }
            while (left < right && left < mid && compare(args, left, mid) < 0) {
                left++;
            }
            if (left < right && left < mid) {
                swap(args, left, right--);
                mid = left;
            }
        }
        // swap(left, mid);

        // 递归调用
        sort(l, mid - 1, args, compare, swap); // 排序mid左边
        sort(mid + 1, r, args, compare, swap); // 排序mid右边
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, %r15
movl %esi, %r14d
movl %edi, %ebp
movq %r14, 0x20(%rsp)
cmpl %r14d, %ebp
jge 0x32b0
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq 0x8(%rsp), %r12
callq *%r12
movl %eax, 0x10(%rsp)
leal (%r14,%rbp), %eax
movl %eax, %r13d
shrl $0x1f, %r13d
addl %eax, %r13d
sarl %r13d
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq *%r12
movl %eax, %ebx
movq %r15, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq *%r12
movl 0x10(%rsp), %edx
movl %edx, %ecx
xorl %ebx, %ecx
xorl %eax, %ebx
cmpl %eax, %edx
movl %r14d, %r12d
cmovel %ebp, %r12d
orl %ecx, %ebx
cmovel %r13d, %r12d
movq %rbp, 0x10(%rsp)
movl %r14d, %r13d
cmpl %r12d, %ebp
movl %r12d, %ebx
cmovgl %ebp, %ebx
cmpl %ebx, %r13d
setg %r14b
jle 0x321e
movq %r15, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq *0x8(%rsp)
testl %eax, %eax
jns 0x3205
decl %r13d
jmp 0x31e6
testb %r14b, %r14b
je 0x321e
leal 0x1(%rbp), %ebx
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq *0x18(%rsp)
movl %r13d, %r12d
movl %ebx, %ebp
cmpl %r12d, %r13d
movl %r12d, %ebx
cmovll %r13d, %ebx
cmpl %ebx, %ebp
setl %r14b
jge 0x327b
movq %r15, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq *0x8(%rsp)
testl %eax, %eax
jns 0x3260
incl %ebp
cmpl %ebp, %ebx
je 0x327b
movq %r15, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq *0x8(%rsp)
incl %ebp
testl %eax, %eax
js 0x3242
decl %ebp
cmpl %ebx, %ebp
setl %r14b
testb %r14b, %r14b
je 0x327b
leal -0x1(%r13), %ebx
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq *0x18(%rsp)
movl %ebp, %r12d
movl %ebx, %r13d
cmpl %r13d, %ebp
jl 0x31dd
leal -0x1(%r12), %esi
movq 0x10(%rsp), %rdi
movq %r15, %rdx
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %r8
callq 0x3150
incl %r12d
movl %r12d, %ebp
movq 0x20(%rsp), %r14
jmp 0x3175
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop