// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %ecx, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
cmpl %edx, %esi
jae 0x203a5
movl %edx, %r15d
movq %rdi, %rbx
movq 0x10(%rsp), %r13
movl %r13d, %ebp
movq %rbx, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0x68b9
movl %r15d, %r14d
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x203b4
movq %rbx, %rdi
testl %eax, %eax
je 0x2007b
movl $0x1, %esi
movq %rbp, %rdx
callq 0x6c8a
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0x6c8a
jmp 0x20085
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x5d4d
movl %r15d, %r12d
subl %r13d, %r12d
cmpl $0x1, %r12d
je 0x203a5
cmpl $0x64, %r12d
jb 0x200bb
cmpl $0x0, 0xc(%rsp)
je 0x200bb
movl %r12d, %ecx
shrl $0x2, %ecx
leal (%rcx,%rcx), %esi
movl 0xc(%rsp), %eax
xorl %edx, %edx
divl %esi
addl 0x10(%rsp), %ecx
addl %edx, %ecx
jmp 0x200c6
movq 0x10(%rsp), %rax
leal (%r15,%rax), %ecx
shrl %ecx
movl %ecx, %r13d
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x203b4
movq %rbx, %rdi
testl %eax, %eax
je 0x2011c
movl $0x1, %esi
movq %r13, %rdx
callq 0x6c8a
movq %rbx, %rdi
movl $0x1, %esi
movq %rbp, %rdx
jmp 0x2016b
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d4d
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x203b4
movq %rbx, %rdi
testl %eax, %eax
je 0x20396
movl $0x1, %esi
movq %r13, %rdx
callq 0x6c8a
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0x6c8a
cmpl $0x2, %r12d
je 0x203a5
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x606b
movq %r15, 0x18(%rsp)
leal -0x1(%r15), %ebp
movq %rbx, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0x68b9
movq %rbp, %r12
movq 0x10(%rsp), %r14
movq %rbp, 0x20(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x6c8a
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0x6c8a
leal 0x1(%r14), %r15d
movq %rbx, %rdi
movl $0x1, %esi
movq %r15, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x203b4
movq %r15, %r13
testl %eax, %eax
leaq 0x4856(%rip), %r12      # 0x24a65
je 0x2028c
addl $0x2, %r14d
movq 0x18(%rsp), %r15
cmpl %r14d, %r15d
jne 0x2022c
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x14a62
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d4d
movl %r14d, %r13d
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x203b4
incl %r14d
testl %eax, %eax
jne 0x2021a
decl %r14d
movl %r14d, %r15d
jmp 0x2028c
cmpl %r15d, %ebp
jae 0x2027f
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x14a62
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d4d
decl %ebp
movq %rbx, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0x68b9
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x203b4
testl %eax, %eax
jne 0x2026d
movq %rbp, %r12
movl %r15d, %r14d
cmpl %r15d, %ebp
jae 0x201bd
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d4d
movq %rbx, %rdi
movl $0x1, %esi
movq 0x20(%rsp), %rdx
callq 0x6c8a
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x6c8a
movl %r15d, %ebp
movq 0x10(%rsp), %r13
subl %r13d, %ebp
movq 0x18(%rsp), %r12
movl %r12d, %r14d
subl %r15d, %r14d
cmpl %r14d, %ebp
jae 0x2032b
leal -0x1(%r15), %edx
movq %rbx, %rdi
movl %r13d, %esi
movl 0xc(%rsp), %ecx
callq 0x1fff3
incl %r15d
movl %r15d, %r13d
movq %r12, %r15
jmp 0x20344
leal 0x1(%r15), %esi
movq %rbx, %rdi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
callq 0x1fff3
decl %r15d
movl %r14d, %ebp
movl %r15d, %eax
subl %r13d, %eax
shrl $0x7, %eax
cmpl %ebp, %eax
jbe 0x20386
callq 0x5120
movq %rax, %r14
xorl %edi, %edi
callq 0x5330
movq %r14, %xmm0
movq %rax, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
paddd %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
paddd %xmm1, %xmm0
movd %xmm0, 0xc(%rsp)
movq %r13, 0x10(%rsp)
cmpl %r13d, %r15d
ja 0x20018
jmp 0x203a5
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x5d4d
jmp 0x20170
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq