// File: /workspace/github_c_makefile_star2_O2/tylerneylon[P]APIsWithLua/lua/ltablib.c
// Function: auxsort
static void auxsort (lua_State *L, IdxT lo, IdxT up,
                                   unsigned int rnd) {
  while (lo < up) {  /* loop for tail recursion */
    IdxT p;  /* Pivot index */
    IdxT n;  /* to be used later */
    /* sort elements 'lo', 'p', and 'up' */
    lua_geti(L, 1, lo);
    lua_geti(L, 1, up);
    if (sort_comp(L, -1, -2))  /* a[up] < a[lo]? */
      set2(L, lo, up);  /* swap a[lo] - a[up] */
    else
      lua_pop(L, 2);  /* remove both values */
    if (up - lo == 1)  /* only 2 elements? */
      return;  /* already sorted */
    if (up - lo < RANLIMIT || rnd == 0)  /* small interval or no randomize? */
      p = (lo + up)/2;  /* middle element is a good pivot */
    else  /* for larger intervals, it is worth a random pivot */
      p = choosePivot(lo, up, rnd);
    lua_geti(L, 1, p);
    lua_geti(L, 1, lo);
    if (sort_comp(L, -2, -1))  /* a[p] < a[lo]? */
      set2(L, p, lo);  /* swap a[p] - a[lo] */
    else {
      lua_pop(L, 1);  /* remove a[lo] */
      lua_geti(L, 1, up);
      if (sort_comp(L, -1, -2))  /* a[up] < a[p]? */
        set2(L, p, up);  /* swap a[up] - a[p] */
      else
        lua_pop(L, 2);
    }
    if (up - lo == 2)  /* only 3 elements? */
      return;  /* already sorted */
    lua_geti(L, 1, p);  /* get middle element (Pivot) */
    lua_pushvalue(L, -1);  /* push Pivot */
    lua_geti(L, 1, up - 1);  /* push a[up - 1] */
    set2(L, p, up - 1);  /* swap Pivot (a[p]) with a[up - 1] */
    p = partition(L, lo, up);
    /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */
    if (p - lo < up - p) {  /* lower interval is smaller? */
      auxsort(L, lo, p - 1, rnd);  /* call recursively for lower interval */
      n = p - lo;  /* size of smaller interval */
      lo = p + 1;  /* tail call for [p + 1 .. up] (upper interval) */
    }
    else {
      auxsort(L, p + 1, up, rnd);  /* call recursively for upper interval */
      n = up - p;  /* size of smaller interval */
      up = p - 1;  /* tail call for [lo .. p - 1]  (lower interval) */
    }
    if ((up - lo) / 128 > n) /* partition too imbalanced? */
      rnd = l_randomizePivot();  /* try a new randomization */
  }  /* tail call auxsort(L, lo, up, rnd) */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0xc(%rsp)
movl %edx, %r13d
movl %esi, %ecx
movq %rdi, %rbx
pushq $0x1
popq %r14
movq %r13, 0x10(%rsp)
movl %r13d, %ebp
subl %ecx, %ebp
pushq $-0x1
popq %r15
jbe 0x1d6bc
movl %ecx, %edx
movq %rbx, %rdi
movl %r14d, %esi
movq %rdx, 0x28(%rsp)
movl %r15d, %r12d
movq %rcx, %r15
callq 0x6518
movq 0x10(%rsp), %r13
movl %r13d, %edx
movq %rbx, %rdi
movl %r14d, %esi
movq %rdx, 0x20(%rsp)
callq 0x6518
movq %rbx, %rdi
movl %r12d, %esi
pushq $-0x2
popq %rdx
callq 0x1d6cb
testl %eax, %eax
movq %r15, 0x18(%rsp)
movq %rbx, %rdi
je 0x1d400
movl %r15d, %esi
movl %r13d, %edx
callq 0x1d762
jmp 0x1d408
pushq $-0x3
popq %rsi
callq 0x5b31
cmpl $0x1, %ebp
movq 0x18(%rsp), %rdi
pushq $-0x1
popq %r15
je 0x1d6bc
cmpl $0x64, %ebp
movl 0xc(%rsp), %eax
jb 0x1d439
testl %eax, %eax
je 0x1d439
movl %ebp, %ecx
shrl $0x2, %ecx
leal (%rcx,%rcx), %esi
xorl %edx, %edx
divl %esi
addl %edi, %ecx
addl %edx, %ecx
jmp 0x1d443
movq 0x10(%rsp), %rax
leal (%rax,%rdi), %ecx
shrl %ecx
movl %ecx, %r13d
movq %rbx, %rdi
movl %r14d, %esi
movq %r13, %rdx
callq 0x6518
movq %rbx, %rdi
movl %r14d, %esi
movq 0x28(%rsp), %rdx
callq 0x6518
movq %rbx, %rdi
pushq $-0x2
popq %r12
movl %r12d, %esi
movl %r15d, %edx
callq 0x1d6cb
movq %rbx, %rdi
testl %eax, %eax
je 0x1d487
movl %r13d, %esi
movq 0x18(%rsp), %rdx
jmp 0x1d4c0
movl %r12d, %esi
callq 0x5b31
movq %rbx, %rdi
movl %r14d, %esi
movq 0x20(%rsp), %rdx
callq 0x6518
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1d6cb
movq %rbx, %rdi
testl %eax, %eax
je 0x1d6a0
movl %r13d, %esi
movq 0x10(%rsp), %rdx
callq 0x1d762
cmpl $0x2, %ebp
movq 0x18(%rsp), %rax
je 0x1d6bc
movq %rbx, %rdi
movl %r14d, %esi
movq %r13, %rdx
movq %rax, %rbp
callq 0x6518
movq %rbx, %rdi
movl %r15d, %esi
callq 0x5cee
movq 0x10(%rsp), %r12
movl %r14d, %esi
leal -0x1(%r12), %r14d
movq %rbx, %rdi
movl %esi, %r15d
movq %r14, %rdx
callq 0x6518
movq %rbx, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x1d762
leal -0x2(%r12), %eax
movl %eax, 0x28(%rsp)
movq %r14, 0x20(%rsp)
movl %r14d, %r13d
movl %ebp, %r12d
pushq $-0x2
popq %r14
leal 0x1(%r12), %ebp
movq %rbx, %rdi
movl %r15d, %esi
movq %rbp, %rdx
callq 0x6518
movq %rbx, %rdi
pushq $-0x1
popq %rsi
movl %r14d, %edx
callq 0x1d6cb
testl %eax, %eax
je 0x1d581
cmpl %r12d, 0x28(%rsp)
jne 0x1d56d
movq %rbx, %rdi
leaq 0x4567(%rip), %rsi      # 0x21acd
xorl %eax, %eax
callq 0x12bd6
movq %rbx, %rdi
pushq $-0x2
popq %r14
movl %r14d, %esi
callq 0x5b31
movl %ebp, %r12d
jmp 0x1d530
leal 0x1(%r12), %ebp
decl %r13d
pushq $-0x3
popq %r14
movl %r13d, %edx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x6518
movq %rbx, %rdi
movl %r14d, %esi
pushq $-0x1
popq %rdx
callq 0x1d6cb
testl %eax, %eax
je 0x1d5d3
cmpl %ebp, %r13d
jae 0x1d5c3
movq %rbx, %rdi
leaq 0x4511(%rip), %rsi      # 0x21acd
xorl %eax, %eax
callq 0x12bd6
movq %rbx, %rdi
pushq $-0x2
popq %rsi
callq 0x5b31
decl %r13d
jmp 0x1d58d
movq %rbx, %rdi
cmpl %ebp, %r13d
jb 0x1d5ea
movl %ebp, %esi
movl %r13d, %edx
callq 0x1d762
jmp 0x1d529
pushq $-0x2
popq %rsi
callq 0x5b31
leal 0x1(%r12), %edx
movq %rbx, %rdi
movq 0x20(%rsp), %r14
movl %r14d, %esi
callq 0x1d762
movl %r12d, %ebp
movq 0x18(%rsp), %rsi
subl %esi, %ebp
incl %ebp
subl %r12d, %r14d
cmpl %r14d, %ebp
jae 0x1d63b
movq %rbx, %rdi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
callq 0x1d377
addl $0x2, %r12d
movl %r12d, %ecx
movl %r15d, %r14d
movq 0x10(%rsp), %r13
jmp 0x1d65f
leal 0x2(%r12), %esi
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movl 0xc(%rsp), %ecx
callq 0x1d377
movq 0x18(%rsp), %rcx
movl %r12d, %r13d
movl %r14d, %ebp
movl %r15d, %r14d
movl %r13d, %eax
subl %ecx, %eax
shrl $0x7, %eax
cmpl %ebp, %eax
jbe 0x1d395
movq %rcx, %rbp
callq 0x5120
movq %rax, %r12
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x5320
movq %r12, 0x30(%rsp)
movq %rax, 0x38(%rsp)
xorl %eax, %eax
cmpq $0x4, %r14
je 0x1d6ad
addl 0x30(%rsp,%r14,4), %eax
incq %r14
jmp 0x1d690
pushq $-0x3
popq %rsi
callq 0x5b31
jmp 0x1d4c5
movl %eax, 0xc(%rsp)
movl %r15d, %r14d
movq %rbp, %rcx
jmp 0x1d395
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq