// File: /workspace/github_c_makefile_star2_O2/bhk[P]tooltree/lua/../opensource/lua-5.2.3/src/ltablib.c
// Function: auxsort
static void auxsort (lua_State *L, int l, int u) {
  while (l < u) {  /* for tail recursion */
    int i, j;
    /* sort elements a[l], a[(l+u)/2] and a[u] */
    lua_rawgeti(L, 1, l);
    lua_rawgeti(L, 1, u);
    if (sort_comp(L, -1, -2))  /* a[u] < a[l]? */
      set2(L, l, u);  /* swap a[l] - a[u] */
    else
      lua_pop(L, 2);
    if (u-l == 1) break;  /* only 2 elements */
    i = (l+u)/2;
    lua_rawgeti(L, 1, i);
    lua_rawgeti(L, 1, l);
    if (sort_comp(L, -2, -1))  /* a[i]<a[l]? */
      set2(L, i, l);
    else {
      lua_pop(L, 1);  /* remove a[l] */
      lua_rawgeti(L, 1, u);
      if (sort_comp(L, -1, -2))  /* a[u]<a[i]? */
        set2(L, i, u);
      else
        lua_pop(L, 2);
    }
    if (u-l == 2) break;  /* only 3 elements */
    lua_rawgeti(L, 1, i);  /* Pivot */
    lua_pushvalue(L, -1);
    lua_rawgeti(L, 1, u-1);
    set2(L, i, u-1);
    /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
    i = l; j = u-1;
    for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */
      /* repeat ++i until a[i] >= P */
      while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
        if (i>=u) luaL_error(L, "invalid order function for sorting");
        lua_pop(L, 1);  /* remove a[i] */
      }
      /* repeat --j until a[j] <= P */
      while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
        if (j<=l) luaL_error(L, "invalid order function for sorting");
        lua_pop(L, 1);  /* remove a[j] */
      }
      if (j<i) {
        lua_pop(L, 3);  /* pop pivot, a[i], a[j] */
        break;
      }
      set2(L, i, j);
    }
    lua_rawgeti(L, 1, u-1);
    lua_rawgeti(L, 1, i);
    set2(L, u-1, i);  /* swap pivot (a[u-1]) with a[i] */
    /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
    /* adjust so that smaller half is in [j..i] and larger one in [l..u] */
    if (i-l < u-i) {
      j=l; i=i-1; l=i+2;
    }
    else {
      j=i+1; i=u; u=j-2;
    }
    auxsort(L, j, i);  /* call recursively the smaller one */
  }  /* repeat the routine for the larger one */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movl %esi, %r13d
movq %rdi, %rbx
pushq $-0x1
popq %r15
pushq $-0x2
popq %r14
movl %ebp, %eax
subl %r13d, %eax
movl %eax, 0x1c(%rsp)
jle 0x16832
movq %rbx, %rdi
pushq $0x1
popq %r12
movl %r12d, %esi
movl %r13d, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %r12d, %esi
movl %r15d, %r12d
movl %ebp, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x16841
testl %eax, %eax
movq %r13, 0x20(%rsp)
movq %rbp, 0x10(%rsp)
movq %rbx, %rdi
je 0x165fb
movl %r13d, %esi
movl %ebp, %edx
callq 0x168d8
jmp 0x16603
pushq $-0x3
popq %rsi
callq 0x7437
cmpl $0x1, 0x1c(%rsp)
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %rax
je 0x16832
addl %r13d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movq %rbx, %rdi
movl %r12d, %ebp
pushq $0x1
popq %r12
movl %r12d, %esi
movl %eax, 0xc(%rsp)
movl %eax, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %r14d, %esi
movl %ebp, %r12d
movl %ebp, %edx
callq 0x16841
testl %eax, %eax
jne 0x1668f
movq %rbx, %rdi
movl %r14d, %esi
callq 0x7437
movq %rbx, %rdi
pushq $0x1
popq %rsi
movq 0x10(%rsp), %r13
movl %r13d, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0x16841
testl %eax, %eax
je 0x16822
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
callq 0x168d8
cmpl $0x2, 0x1c(%rsp)
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %r12
je 0x16832
movq %rbx, %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
movl 0xc(%rsp), %edx
callq 0x7e9f
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0x7604
decl %r12d
movq %rbx, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x7e9f
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movl %r12d, %edx
callq 0x168d8
movl %r12d, 0xc(%rsp)
incl %r13d
movq %rbx, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x16841
testl %eax, %eax
je 0x1675f
cmpl %r13d, 0x10(%rsp)
jg 0x1672d
movq %rbx, %rdi
leaq 0x94c6(%rip), %rsi      # 0x1fbec
xorl %eax, %eax
callq 0x8d68
movq %rbx, %rdi
movl %r14d, %esi
callq 0x7437
jmp 0x166f3
cmpl 0x20(%rsp), %ebp
jg 0x16751
movq %rbx, %rdi
leaq 0x94a2(%rip), %rsi      # 0x1fbec
xorl %eax, %eax
callq 0x8d68
movq %rbx, %rdi
movl %r14d, %esi
callq 0x7437
movl %ebp, %r12d
leal -0x1(%r12), %ebp
movq %rbx, %rdi
pushq $0x1
popq %rsi
movl %ebp, %edx
callq 0x7e9f
movq %rbx, %rdi
pushq $-0x3
popq %rsi
movl %r15d, %edx
callq 0x16841
testl %eax, %eax
jne 0x1673a
cmpl %r13d, %r12d
jle 0x167a1
decl %r12d
movq %rbx, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x168d8
pushq $0x1
popq %rbp
jmp 0x166f3
movq %rbx, %rdi
pushq $-0x4
popq %rsi
callq 0x7437
movq %rbx, %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
movl 0xc(%rsp), %r12d
movl %r12d, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x7e9f
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x168d8
movl %r13d, %eax
movq 0x20(%rsp), %rdx
subl %edx, %eax
movq 0x10(%rsp), %rdi
movl %edi, %ecx
subl %r13d, %ecx
leal 0x1(%r13), %esi
decl %r13d
cmpl %ecx, %eax
movl %edx, %ebp
cmovll %esi, %ebp
movl %r13d, %r12d
cmovll %edi, %r12d
cmovgel %edi, %r13d
cmovll %edx, %esi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x16581
movl %ebp, %r13d
movl %r12d, %ebp
jmp 0x1659f
movq %rbx, %rdi
pushq $-0x3
popq %rsi
callq 0x7437
jmp 0x1669e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq