// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movl %ecx, 0x4(%rsp)
movl %edx, %ebp
movl %esi, %r13d
movq %rdi, %rbx
movl %ebp, %r14d
subl %r13d, %r14d
jbe 0x1f522
movl %r13d, %r12d
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0x679b
movl %ebp, %r15d
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x1f531
movq %rbx, %rdi
testl %eax, %eax
je 0x1f1f5
movl $0x1, %esi
movq %r12, %rdx
callq 0x6b63
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x6b63
jmp 0x1f1ff
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x5d51
cmpl $0x1, %r14d
movq %rbp, 0x8(%rsp)
jne 0x1f211
xorl %ebp, %ebp
jmp 0x1f503
cmpl $0x64, %r14d
movl 0x4(%rsp), %eax
movq %r13, 0x10(%rsp)
jb 0x1f238
testl %eax, %eax
je 0x1f238
movl %r14d, %ecx
shrl $0x2, %ecx
leal (%rcx,%rcx), %esi
xorl %edx, %edx
divl %esi
addl %r13d, %ecx
addl %edx, %ecx
jmp 0x1f23f
leal (%rbp,%r13), %ecx
shrl %ecx
movl %ecx, %r13d
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f531
movq %rbx, %rdi
testl %eax, %eax
je 0x1f295
movl $0x1, %esi
movq %r13, %rdx
callq 0x6b63
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
jmp 0x1f2e4
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d51
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x1f531
movq %rbx, %rdi
testl %eax, %eax
je 0x1f513
movl $0x1, %esi
movq %r13, %rdx
callq 0x6b63
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x6b63
cmpl $0x2, %r14d
jne 0x1f2fb
xorl %ebp, %ebp
movq 0x10(%rsp), %r13
jmp 0x1f503
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5f5b
leal -0x1(%rbp), %r12d
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0x679b
movq %r12, %r14
movq 0x10(%rsp), %r15
movq %r12, 0x18(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x6b63
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0x6b63
leal 0x1(%r15), %ebp
movq %rbx, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x1f531
movq %rbp, %r13
testl %eax, %eax
leaq 0x4622(%rip), %r14      # 0x239ad
je 0x1f408
addl $0x2, %r15d
movq 0x8(%rsp), %rbp
cmpl %r15d, %ebp
jne 0x1f3a8
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x13f8e
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d51
movl %r15d, %r13d
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x1f531
incl %r15d
testl %eax, %eax
jne 0x1f396
decl %r15d
movl %r15d, %ebp
jmp 0x1f408
cmpl %ebp, %r12d
jae 0x1f3fb
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x13f8e
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d51
decl %r12d
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0x679b
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f531
testl %eax, %eax
jne 0x1f3e9
movq %r12, %r14
movl %ebp, %r15d
cmpl %ebp, %r12d
jae 0x1f339
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d51
movq %rbx, %rdi
movl $0x1, %esi
movq 0x18(%rsp), %rdx
callq 0x6b63
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x6b63
movl %ebp, %r14d
movq 0x10(%rsp), %r13
subl %r13d, %r14d
movq 0x8(%rsp), %r12
movl %r12d, %r15d
subl %ebp, %r15d
cmpl %r15d, %r14d
jae 0x1f4a3
leal -0x1(%rbp), %edx
movq %rbx, %rdi
movl %r13d, %esi
movl 0x4(%rsp), %ecx
callq 0x1f171
incl %ebp
movl %ebp, %r13d
jmp 0x1f4bd
leal 0x1(%rbp), %esi
movq %rbx, %rdi
movl %r12d, %edx
movl 0x4(%rsp), %ecx
callq 0x1f171
decl %ebp
movl %ebp, %r12d
movl %r15d, %r14d
movq %r12, 0x8(%rsp)
movl %r12d, %eax
subl %r13d, %eax
shrl $0x7, %eax
movb $0x1, %bpl
cmpl %r14d, %eax
jbe 0x1f503
callq 0x5130
movq %rax, %r14
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x5340
movq %r14, 0x20(%rsp)
movq %rax, 0x28(%rsp)
xorl %eax, %eax
addl 0x20(%rsp,%r15,4), %eax
incq %r15
cmpq $0x4, %r15
jne 0x1f4f1
movl %eax, 0x4(%rsp)
testb %bpl, %bpl
movq 0x8(%rsp), %rbp
jne 0x1f18b
jmp 0x1f522
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x5d51
jmp 0x1f2e9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq