// File: /workspace/github_cpp_makefile_star2_O1/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
jl 0x1249c
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 %rsi, %r14
movq %r12, %rsi
movq %rbx, %rdx
callq 0x12ffa
movq %r14, -0x30(%rbp)
addq $-0x18, %r14
movq %r15, %rdi
testb %al, %al
je 0x12252
movq %r14, %rsi
movq %r12, %rdx
callq 0x12ffa
testb %al, %al
je 0x12289
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 0x12356
movq %r12, %rsi
movq %r14, %rdx
callq 0x12ffa
testb %al, %al
je 0x122bf
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 0x1235a
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12ffa
testb %al, %al
je 0x12306
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 0x1235a
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x12ffa
testb %al, %al
je 0x12317
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 0x1235a
movq 0x10(%rbx), %rax
movq %rax, -0x40(%rbp)
movups (%rbx), %xmm0
movaps %xmm0, -0x50(%rbp)
jmp 0x1235a
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
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 0x12ffa
testb %al, %al
je 0x1239f
addq $0x18, %rbx
cmpq %r14, %rbx
jb 0x12382
jmp 0x123fe
addq $-0x18, %r14
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x12ffa
testb %al, %al
je 0x123c3
leaq -0x18(%r14), %rax
cmpq %r14, %rbx
movq %rax, %r14
jb 0x123a3
jmp 0x123fe
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 0x1237f
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 0x1245e
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq -0x78(%rbp), %rdi
movq %rbx, %rsi
callq 0x12193
movq %r14, %r12
movq -0x30(%rbp), %rsi
jmp 0x12485
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x12193
movq %rbx, %rsi
movq -0x78(%rbp), %r12
movq %r12, %r14
movq %rsi, %rax
subq %r14, %rax
movq %rsi, %rdx
cmpq $0xf0, %rax
jg 0x121c7
jmp 0x1249f
movq %r12, %r14
movq 0x10(%r15), %rax
movq %rax, -0x40(%rbp)
movups (%r15), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq 0x18(%r14), %rax
movq %rsi, -0x30(%rbp)
cmpq %rsi, %rax
jae 0x12560
movq %r14, %rbx
leaq -0x50(%rbp), %r14
movq %rbx, %r12
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x12ffa
testb %al, %al
je 0x1254f
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 0x1253b
leaq -0x18(%r12), %r13
movq %r14, %rdi
leaq -0x70(%rbp), %rsi
movq %r13, %rdx
callq 0x12ffa
testb %al, %al
je 0x1253b
movq 0x10(%r13), %rax
movq %rax, 0x10(%r12)
movups (%r13), %xmm0
movups %xmm0, (%r12)
movq %r13, %r12
cmpq %rbx, %r13
ja 0x12506
jmp 0x1253e
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 0x124ca
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop