// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/core/qsort_r.c
// Function: gt_qsort_r
void
gt_qsort_r(void *a, size_t n, size_t es, void *data, GtCompareWithData cmp)
{
  char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
  int swaptype, swap_cnt;
  long d, r;

  while (1)
  {
    SWAPINIT(a, es);
    swap_cnt = 0;
    if (n < 7) {
      for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
        for (pl = pm;
             pl > (char *)a && cmp(pl - es, pl, data) > 0;
             pl -= es)
          swap(pl, pl - es);
      return;
    }
    pm = (char *)a + (n / 2) * es;
    if (n > 7) {
      pl = a;
      pn = (char *)a + (n - 1) * es;
      if (n > 40) {
        d = (n / 8) * es;
        pl = med3(pl, pl + d, pl + 2 * d, cmp, data);
        pm = med3(pm - d, pm, pm + d, cmp, data);
        pn = med3(pn - 2 * d, pn - d, pn, cmp, data);
      }
      pm = med3(pl, pm, pn, cmp, data);
    }
    swap(a, pm);
    pa = pb = (char *)a + es;

    pc = pd = (char *)a + (n - 1) * es;
    for (;;) {
      while (pb <= pc && (r = cmp(pb, a, data)) <= 0) {
        if (r == 0) {
          swap_cnt = 1;
          swap(pa, pb);
          pa += es;
        }
        pb += es;
      }
      while (pb <= pc && (r = cmp(pc, a, data)) >= 0) {
        if (r == 0) {
          swap_cnt = 1;
          swap(pc, pd);
          pd -= es;
        }
        pc -= es;
      }
      if (pb > pc)
        break;
      swap(pb, pc);
      swap_cnt = 1;
      pb += es;
      pc -= es;
    }
    if (swap_cnt == 0) {  /* Switch to insertion sort */
      for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
        for (pl = pm;
             pl > (char *)a && cmp(pl - es, pl, data) > 0;
             pl -= es)
          swap(pl, pl - es);
      return;
    }

    pn = (char *)a + n * es;
    r = GT_MIN(pa - (char *)a, pb - pa);
    vecswap(a, pb - r, r);
    r = GT_MIN(pd - pc, pn - pd - es);
    vecswap(pb, pn - r, r);
    if ((r = pb - pa) > es)
      gt_qsort_r(a, r / es, es, data, cmp);
    if ((r = pd - pc) > es) {
      /* Iterate rather than recurse to save stack space */
      a = pn - r;
      n = r / es;
    }
    else
      break;
  }
/*            qsort(pn - r, r / es, es, cmp);*/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r14
movq %rcx, 0x28(%rsp)
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r12
movq %rdx, %rax
negq %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
cmpq $0x8, %rdx
setne %al
movl %eax, 0x54(%rsp)
movq %r8, 0x10(%rsp)
movl %r12d, %eax
orl %r15d, %eax
testb $0x7, %al
pushq $0x2
popq %rcx
cmovel 0x54(%rsp), %ecx
cmpq $0x6, %r13
movq %r12, 0x30(%rsp)
movl %ecx, 0xc(%rsp)
jbe 0x5ae77
movq %r13, %rbx
shrq %rbx
imulq %r15, %rbx
addq %r12, %rbx
cmpq $0x7, %r13
movq %r13, 0x18(%rsp)
je 0x5ac47
leaq -0x1(%r13), %rbp
imulq %r15, %rbp
addq %r12, %rbp
cmpq $0x29, %r13
jb 0x5ac22
movq 0x18(%rsp), %r13
shrq $0x3, %r13
imulq %r15, %r13
leaq (%r12,%r13), %rsi
leaq (,%r13,2), %r14
leaq (%r12,%r13,2), %rdx
movq %r12, %rdi
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %r12
movq %r12, %r8
callq 0x5afc8
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
subq %r13, %rdi
leaq (%rbx,%r13), %rdx
movq %rbx, %rsi
movq 0x10(%rsp), %rcx
movq %r12, %r8
callq 0x5afc8
movq %rax, %rbx
movq %rbp, %rdi
subq %r14, %rdi
movq 0x10(%rsp), %r14
movq %rbp, %rsi
subq %r13, %rsi
movq 0x18(%rsp), %r13
movq %rbp, %rdx
movq %r14, %rcx
movq %r12, %r8
callq 0x5afc8
movq 0x20(%rsp), %rdi
movq %rax, %rbp
jmp 0x5ac2a
movq %r12, %rdi
movq 0x28(%rsp), %r12
movq %rbx, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r12, %r8
callq 0x5afc8
movq %rax, %rbx
movq 0x30(%rsp), %r12
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
je 0x5ac5b
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x5af78
jmp 0x5ac69
movq (%r12), %rax
movq (%rbx), %rcx
movq %rcx, (%r12)
movq %rax, (%rbx)
leaq (%r12,%r15), %rax
decq %r13
imulq %r15, %r13
addq %r12, %r13
xorl %ebp, %ebp
movq %r13, 0x20(%rsp)
movq %rax, %rbx
movq %rax, 0x48(%rsp)
movq %rax, 0x40(%rsp)
movq %rax, %r12
cmpq %r13, %r12
ja 0x5acee
movq %r12, %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq *%r14
testl %eax, %eax
jg 0x5acee
jne 0x5ace6
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
je 0x5acc6
movq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x5af78
jmp 0x5acdb
movq 0x40(%rsp), %rbp
movq (%rbp), %rax
movq (%r12), %rcx
movq %rcx, (%rbp)
movq %rax, (%r12)
addq %r15, %rbp
movq %rbp, 0x40(%rsp)
pushq $0x1
popq %rbp
addq %r15, %r12
addq %r15, %rbx
jmp 0x5ac8e
movl %ebp, %r14d
movq %r13, %rbp
negq %rbp
cmpq %r13, %r12
ja 0x5adaa
movq %r13, %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq *0x10(%rsp)
testl %eax, %eax
js 0x5ad67
je 0x5ad1e
movq 0x38(%rsp), %rax
jmp 0x5ad5f
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
je 0x5ad3b
movq %r13, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rsi
movl %r15d, %edx
callq 0x5af78
jmp 0x5ad4e
movq (%r13), %rax
movq 0x20(%rsp), %r14
movq (%r14), %rcx
movq %rcx, (%r13)
movq %rax, (%r14)
movq 0x38(%rsp), %rax
addq %rax, %r14
movq %r14, 0x20(%rsp)
pushq $0x1
popq %r14
addq %rax, %r13
addq %r15, %rbp
jmp 0x5acf7
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
je 0x5ad7f
movq %r12, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x5af78
jmp 0x5ad8f
movq (%r12), %rax
movq (%r13), %rcx
movq %rcx, (%r12)
movq %rax, (%r13)
movq 0x10(%rsp), %r14
movq 0x38(%rsp), %rax
addq %r15, %r12
addq %rax, %r13
pushq $0x1
popq %rbp
movq %r12, %rbx
jmp 0x5ac8e
movq 0x18(%rsp), %r13
imulq %r15, %r13
movq 0x30(%rsp), %rdi
addq %rdi, %r13
testl %r14d, %r14d
je 0x5aeed
movq 0x40(%rsp), %rax
subq %rax, %rbx
subq %rdi, %rax
cmpq %rbx, %rax
movq %rbx, %rdx
cmovlq %rax, %rdx
testq %rdx, %rdx
jle 0x5adf4
cmpq %rbx, %rax
cmovgeq %rbx, %rax
movq %r12, %rsi
subq %rax, %rsi
movl 0xc(%rsp), %ecx
callq 0x5af78
movq 0x20(%rsp), %rax
leaq (%rax,%rbp), %r14
addq %r15, %rax
movq %r13, %rdx
subq %rax, %rdx
cmpq %rdx, %r14
cmovbq %r14, %rdx
testq %rdx, %rdx
jle 0x5ae24
movq %r13, %rsi
subq %rdx, %rsi
movq %r12, %rdi
movl 0xc(%rsp), %ecx
callq 0x5af78
cmpq %r15, %rbx
jbe 0x5ae4b
movq %rbx, %rax
xorl %edx, %edx
divq %r15
movq 0x30(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq 0x28(%rsp), %rcx
movq 0x10(%rsp), %r8
callq 0x5ab10
cmpq %r15, %r14
movq %r14, %rax
movq 0x20(%rsp), %r14
jbe 0x5af69
subq %r14, %r13
movq %r13, %r12
subq %rbp, %r12
xorl %edx, %edx
divq %r15
movq %rax, %r13
movq 0x10(%rsp), %r14
jmp 0x5ab4c
imulq %r15, %r13
addq %r12, %r13
movq %r12, %rbx
movq %r13, 0x18(%rsp)
movq 0x28(%rsp), %rbp
leaq (%rbx,%r15), %r12
cmpq %r13, %r12
jae 0x5af69
movq 0x10(%rsp), %r13
leaq (%rbx,%r15), %r14
cmpq 0x30(%rsp), %r14
jbe 0x5aee3
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq *%r13
testl %eax, %eax
jle 0x5aee3
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
je 0x5aed0
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x5af78
jmp 0x5aedc
movq (%r14), %rax
movq (%rbx), %rcx
movq %rcx, (%r14)
movq %rax, (%rbx)
addq 0x38(%rsp), %rbx
jmp 0x5ae9d
movq %r12, %rbx
movq 0x18(%rsp), %r13
jmp 0x5ae8b
movq %rdi, %r12
movq 0x48(%rsp), %rax
movq %r13, 0x18(%rsp)
movq 0x28(%rsp), %rbp
cmpq %r13, %rax
jae 0x5af69
movq %rax, 0x48(%rsp)
movq %r12, %rbx
movq 0x10(%rsp), %r13
leaq (%rbx,%r15), %r14
cmpq 0x30(%rsp), %r14
jbe 0x5af57
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq *%r13
testl %eax, %eax
movl 0xc(%rsp), %ecx
jle 0x5af57
testl %ecx, %ecx
je 0x5af44
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x5af78
jmp 0x5af50
movq (%r14), %rax
movq (%rbx), %rcx
movq %rcx, (%r14)
movq %rax, (%rbx)
addq 0x38(%rsp), %rbx
jmp 0x5af11
movq 0x48(%rsp), %rax
addq %r15, %rax
addq %r15, %r12
movq 0x18(%rsp), %r13
jmp 0x5aeff
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq