// File: /workspace/github_cpp_makefile_star2_O3/Fohlen[P]cubescript-standalone/./tools.h
// Function: void quicksort<sortitem, sortfun>(sortitem*, sortitem*, sortfun)
static inline void quicksort(T *start, T *end, F fun)
{
    while(end-start > 10)
    {
        T *mid = &start[(end-start)/2], *i = start+1, *j = end-2, pivot;
        if(fun(*start, *mid)) /* start < mid */
        {
            if(fun(end[-1], *start)) { pivot = *start; *start = end[-1]; end[-1] = *mid; } /* end < start < mid */
            else if(fun(end[-1], *mid)) { pivot = end[-1]; end[-1] = *mid; } /* start <= end < mid */
            else { pivot = *mid; } /* start < mid <= end */
        }
        else if(fun(*start, end[-1])) { pivot = *start; *start = *mid; } /*mid <= start < end */
        else if(fun(*mid, end[-1])) { pivot = end[-1]; end[-1] = *start; *start = *mid; } /* mid < end <= start */
        else { pivot = *mid; swap(*start, end[-1]); }  /* end <= mid <= start */
        *mid = end[-2];
        do
        {
            while(fun(*i, pivot)) if(++i >= j) goto partitioned;
            while(fun(pivot, *--j)) if(i >= j) goto partitioned;
            swap(*i, *j);
        }
        while(++i < j);
    partitioned:
        end[-2] = *i;
        *i = pivot;

        if(i-start < end-(i+1))
        {
            quicksort(start, i, fun);
            start = i+1;
        }
        else
        {
            quicksort(i+1, end, fun);
            end = i;
        }
    }

    insertionsort(start, end, fun);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r12
leaq 0x10(%rbp), %r15
movq %rsi, %rax
subq %rdi, %rax
cmpq $0xf1, %rax
movq %rsi, -0x30(%rbp)
jl 0x129d8
leaq -0x50(%rbp), %r13
movq %r12, %r14
movq %rsi, %rdx
movq %rdx, -0x80(%rbp)
movq %r14, -0x88(%rbp)
shrq $0x3, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rax
shrq %rax
leaq (%rax,%rax,2), %rax
leaq (%r12,%rax,8), %rbx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x13546
movq -0x30(%rbp), %rcx
leaq -0x18(%rcx), %r14
movq %r15, %rdi
testb %al, %al
je 0x12789
movq %r14, %rsi
movq %r12, %rdx
callq 0x13546
testb %al, %al
je 0x127c0
movq 0x10(%r12), %rax
movq %rax, -0x40(%rbp)
movups (%r12), %xmm0
movaps %xmm0, -0x50(%rbp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%r12)
movups (%r14), %xmm0
movups %xmm0, (%r12)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r14)
movups (%rbx), %xmm0
jmp 0x1288d
movq %r12, %rsi
movq %r14, %rdx
callq 0x13546
testb %al, %al
je 0x127f6
movq 0x10(%r12), %rax
movq %rax, -0x40(%rbp)
movups (%r12), %xmm0
movaps %xmm0, -0x50(%rbp)
movups (%rbx), %xmm0
movups %xmm0, (%r12)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r12)
jmp 0x12891
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x13546
testb %al, %al
je 0x1283d
movq 0x10(%r14), %rax
movq %rax, -0x40(%rbp)
movups (%r14), %xmm0
movaps %xmm0, -0x50(%rbp)
movups (%rbx), %xmm0
movups %xmm0, (%r14)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r14)
jmp 0x12891
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x13546
testb %al, %al
je 0x1284e
movq 0x10(%r14), %rax
movq %rax, -0x40(%rbp)
movups (%r14), %xmm0
movaps %xmm0, -0x50(%rbp)
movq 0x10(%r12), %rax
movq %rax, 0x10(%r14)
movups (%r12), %xmm0
movups %xmm0, (%r14)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r12)
movups (%rbx), %xmm0
movups %xmm0, (%r12)
jmp 0x12891
movq 0x10(%rbx), %rax
movq %rax, -0x40(%rbp)
movups (%rbx), %xmm0
movaps %xmm0, -0x50(%rbp)
jmp 0x12891
movq 0x10(%rbx), %rax
movq %rax, -0x40(%rbp)
movups (%rbx), %xmm0
movaps %xmm0, -0x50(%rbp)
movq 0x10(%r12), %rax
movq %rax, -0x60(%rbp)
movups (%r12), %xmm0
movaps %xmm0, -0x70(%rbp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%r12)
movups (%r14), %xmm0
movups %xmm0, (%r12)
movq -0x60(%rbp), %rax
movq %rax, 0x10(%r14)
movaps -0x70(%rbp), %xmm0
movups %xmm0, (%r14)
movq -0x30(%rbp), %rcx
movq %r12, -0x78(%rbp)
leaq 0x18(%r12), %rax
movq %rcx, -0x30(%rbp)
leaq -0x30(%rcx), %r12
movq 0x10(%r12), %rcx
movq %rcx, 0x10(%rbx)
movups (%r12), %xmm0
movups %xmm0, (%rbx)
movq %r12, %r14
movq %rax, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x13546
testb %al, %al
je 0x128da
addq $0x18, %rbx
cmpq %r14, %rbx
jb 0x128bd
jmp 0x12939
addq $-0x18, %r14
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x13546
testb %al, %al
je 0x128fe
leaq -0x18(%r14), %rax
cmpq %r14, %rbx
movq %rax, %r14
jb 0x128de
jmp 0x12939
movq 0x10(%rbx), %rax
movq %rax, -0x60(%rbp)
movups (%rbx), %xmm0
movaps %xmm0, -0x70(%rbp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rbx)
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movq -0x60(%rbp), %rax
movq %rax, 0x10(%r14)
movaps -0x70(%rbp), %xmm0
movups %xmm0, (%r14)
leaq 0x18(%rbx), %rax
cmpq %r14, %rax
jb 0x128ba
addq $0x18, %rbx
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r12)
movups (%rbx), %xmm0
movups %xmm0, (%r12)
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rbx)
movq -0x40(%rbp), %rax
movq %rax, 0x10(%rbx)
movq %rbx, %rax
subq -0x88(%rbp), %rax
leaq 0x18(%rbx), %r14
movq -0x80(%rbp), %rcx
subq %r14, %rcx
cmpq %rcx, %rax
jge 0x12999
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq -0x78(%rbp), %rdi
movq %rbx, %rsi
callq 0x126c9
movq -0x30(%rbp), %rdx
movq %r14, %r12
jmp 0x129c4
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x126c9
movq -0x78(%rbp), %r12
movq %r12, %r14
movq %rbx, %rdx
movq %rbx, -0x30(%rbp)
movq %rdx, %rax
subq %r14, %rax
cmpq $0xf0, %rax
jg 0x12701
jmp 0x129db
movq %r12, %r14
movq 0x10(%r15), %rax
movq %rax, -0x40(%rbp)
movups (%r15), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq 0x18(%r14), %rax
cmpq -0x30(%rbp), %rax
jae 0x12a99
movq %r14, %rbx
leaq -0x50(%rbp), %r14
movq %rbx, %r12
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x13546
testb %al, %al
je 0x12a88
movq 0x10(%r15), %rax
movq %rax, -0x60(%rbp)
movups (%r15), %xmm0
movaps %xmm0, -0x70(%rbp)
movups (%r12), %xmm0
movups %xmm0, (%r15)
movq 0x10(%r12), %rax
movq %rax, 0x10(%r15)
cmpq %rbx, %r12
jbe 0x12a74
leaq -0x18(%r12), %r13
movq %r14, %rdi
leaq -0x70(%rbp), %rsi
movq %r13, %rdx
callq 0x13546
testb %al, %al
je 0x12a74
movq 0x10(%r13), %rax
movq %rax, 0x10(%r12)
movups (%r13), %xmm0
movups %xmm0, (%r12)
movq %r13, %r12
cmpq %rbx, %r13
ja 0x12a3f
jmp 0x12a77
movq %r12, %r13
movq -0x60(%rbp), %rax
movq %rax, 0x10(%r13)
movaps -0x70(%rbp), %xmm0
movups %xmm0, (%r13)
leaq 0x18(%r15), %rax
movq %r15, %r12
cmpq -0x30(%rbp), %rax
jb 0x12a03
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq