// File: /workspace/github_c_makefile_star2_O1/cyb70289[P]tt/src/common/sort.c
// Function: tt_sort_quick
static int tt_sort_quick(struct tt_sort_input *in, struct tt_sort_stat *stat)
{
	stat->depth++;	/* Max stack depth */
	if (stat->depth > stat->space)
		stat->space = stat->depth;

	/* Buffer to hold pivot value */
	char pivot[in->num.size] _tt_align(8);

	int p = stat->head;
	int r = stat->tail;
	while (p < r) {
		/* Select pivot */
		void *vp = sort_ptr(in, p);
		void *vr = sort_ptr(in, r);
		/* Pick middle element as pivot if short array */
		void *vq = sort_ptr(in, (p + r) / 2);
		void *vm = vq;
		if (r - p >= 15) {
			/* Pick medium-3 as pivot if long array */
			if (in->num.cmp(&in->num, vp, vq) < 0) {
				vm = vp;
				if (in->num.cmp(&in->num, vp, vr) < 0) {
					vm = vr;
					if (in->num.cmp(&in->num, vq, vr) < 0)
						vm = vq;
				}
			} else {
				vm = vq;
				if (in->num.cmp(&in->num, vq, vr) < 0) {
					vm = vr;
					if (in->num.cmp(&in->num, vp, vr) < 0)
						vm = vp;
				}
			}
		}
		/* Save pivot value */
		in->num._set(&in->num, pivot, vm);

		/* Split-end partition */
		void *pa = vp, *pb = vp;
		void *pc = vr, *pd = vr;
		while (1) {
			int r;
			while (pb <= pc &&
				(r = in->num.cmp(&in->num, pb, pivot)) <= 0) {
				if (r == 0) {
					in->num.swap(&in->num, pa, pb);
					pa += in->num.size;
					stat->time++;
				}
				pb += in->num.size;
				stat->time++;
			}
			while (pc >= pb &&
				(r = in->num.cmp(&in->num, pc, pivot)) >= 0) {
				if (r == 0) {
					in->num.swap(&in->num, pc, pd);
					pd -= in->num.size;
					stat->time++;
				}
				pc -= in->num.size;
				stat->time++;
			}
			if (pb > pc)
				break;
			in->num.swap(&in->num, pb, pc);
			pb += in->num.size;
			pc -= in->num.size;
			stat->time++;
		}
		/* Current layout
		 *  +-----+---------+---------+-----+
		 *  |  =  |    <    |    >    |  =  |
		 *  +-----+---------+---------+-----+
		 *  vp    pa      pc pb       pd   rp
		 */

		int l = _tt_min(pa - vp, pb - pa);
		void *vt = pb - l;
		while (l) {
			in->num.swap(&in->num, vp, vt);
			vp += in->num.size;
			vt += in->num.size;
			l -= in->num.size;
			stat->time++;
		}
		l = _tt_min(pd - pc, vr - pd);
		vt = pb;
		vr -= (l - in->num.size);
		while (l) {
			in->num.swap(&in->num, vt, vr);
			vt += in->num.size;
			vr += in->num.size;
			l -= in->num.size;
			stat->time++;
		}
		int q1 = p + (pb - pa) / in->num.size - 1;
		int q2 = r - (pd - pc) / in->num.size + 1;
		/* Current layout
		 *  +---------+---------+----------+
		 *  |    <    |    =    |    >     |
		 *  +---------+---------+----------+
		 *  p        q1         q2         r
		 */

		/* Call upon short list recursively, leave long one iterated */
		if (q1 - p <= r - q2) {
			stat->head = p;
			stat->tail = q1;
			tt_sort_quick(in, stat);
			p = q2;
		} else {
			stat->head = q2;
			stat->tail = r;
			tt_sort_quick(in, stat);
			r = q1;
		}
	}

	stat->depth--;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
movl 0x8(%rsi), %eax
incl %eax
movl %eax, 0x8(%rsi)
cmpl 0x4(%rsi), %eax
jbe 0x3364
movl %eax, 0x4(%rsi)
movl (%r14), %eax
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movl 0xc(%rsi), %r8d
movq %rsi, -0x30(%rbp)
movl 0x10(%rsi), %r12d
cmpl %r12d, %r8d
jge 0x362c
movq 0x20(%r14), %rax
movl (%r14), %ecx
movl %ecx, %edx
leal (%r8,%r12), %esi
movl %esi, %edi
shrl $0x1f, %edi
addl %esi, %edi
sarl %edi
imull %ecx, %edi
imull %r8d, %ecx
movslq %ecx, %r13
addq %rax, %r13
imull %r12d, %edx
movslq %edx, %rcx
addq %rax, %rcx
movq %rcx, -0x40(%rbp)
movslq %edi, %r15
addq %rax, %r15
movl %r12d, %eax
movq %r8, -0x68(%rbp)
subl %r8d, %eax
cmpl $0xf, %eax
movq %r12, -0x70(%rbp)
jl 0x3404
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq *0x8(%r14)
movq 0x8(%r14), %rcx
movq %r14, %rdi
testl %eax, %eax
js 0x340a
movq %r15, %rsi
movq -0x40(%rbp), %r12
movq %r12, %rdx
callq *%rcx
movq %r13, %rbx
jmp 0x341c
movq -0x40(%rbp), %r12
jmp 0x3436
movq %r13, %rsi
movq -0x40(%rbp), %r12
movq %r12, %rdx
callq *%rcx
movq %r15, %rbx
movq %r13, %r15
testl %eax, %eax
jns 0x3436
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq *0x8(%r14)
testl %eax, %eax
cmovnsq %r12, %rbx
movq %rbx, %r15
movq %r14, %rdi
movq -0x48(%rbp), %rsi
movq %r15, %rdx
callq *0x18(%r14)
movq %r12, -0x50(%rbp)
movq %r13, -0x60(%rbp)
movq %r13, -0x38(%rbp)
movq -0x30(%rbp), %rbx
cmpq %r12, %r13
ja 0x34ce
movq %r14, %rdi
movq %r13, %rsi
movq -0x48(%rbp), %rdx
callq *0x8(%r14)
testl %eax, %eax
jg 0x34ce
jne 0x3491
movq %r14, %rdi
movq %rbx, %r15
movq -0x38(%rbp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq *0x10(%r14)
movslq (%r14), %rax
addq %rax, %rbx
movq %rbx, -0x38(%rbp)
movq %r15, %rbx
incl (%r15)
movslq (%r14), %rax
addq %rax, %r13
incl (%rbx)
jmp 0x3454
testl %eax, %eax
je 0x34a5
movq -0x30(%rbp), %rcx
jmp 0x34c6
movq %r14, %rdi
movq %r12, %rsi
movq -0x50(%rbp), %rbx
movq %rbx, %rdx
callq *0x10(%r14)
movslq (%r14), %rax
subq %rax, %rbx
movq %rbx, -0x50(%rbp)
movq -0x30(%rbp), %rcx
incl (%rcx)
movslq (%r14), %rax
incl (%rcx)
subq %rax, %r12
cmpq %r13, %r12
setb %bl
jb 0x34ec
movq %r14, %rdi
movq %r12, %rsi
movq -0x48(%rbp), %rdx
callq *0x8(%r14)
testl %eax, %eax
jns 0x349b
testb %bl, %bl
je 0x34fc
xorl %eax, %eax
movq -0x30(%rbp), %rbx
testb %al, %al
jne 0x3454
jmp 0x351c
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq *0x10(%r14)
movslq (%r14), %rax
addq %rax, %r13
subq %rax, %r12
movq -0x30(%rbp), %rbx
incl (%rbx)
movb $0x1, %al
jmp 0x34f2
movq %r13, %rcx
movq -0x38(%rbp), %rax
subq %rax, %rcx
movq -0x60(%rbp), %r15
subq %r15, %rax
cmpq %rcx, %rax
movq %rcx, -0x58(%rbp)
cmovgeq %rcx, %rax
testl %eax, %eax
movq %rbx, %rsi
je 0x357e
movq %rax, %rcx
movslq %ecx, %rax
movq %r13, %rbx
subq %rax, %rbx
movq %rcx, %rax
movq %rax, -0x38(%rbp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq *0x10(%r14)
movq -0x30(%rbp), %rsi
movslq (%r14), %rax
addq %rax, %r15
addq %rax, %rbx
incl (%rsi)
movq -0x38(%rbp), %rcx
subl %eax, %ecx
movq %rcx, -0x38(%rbp)
movq -0x38(%rbp), %rax
jne 0x354e
movq -0x40(%rbp), %r15
movq %r15, %rbx
movq -0x50(%rbp), %rax
subq %rax, %rbx
subq %r12, %rax
movq %rax, %r12
cmpq %rbx, %rax
cmovlq %rax, %rbx
testl %ebx, %ebx
je 0x35c9
movslq (%r14), %rax
movslq %ebx, %rcx
subq %rcx, %rax
addq %rax, %r15
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq *0x10(%r14)
movq -0x30(%rbp), %rsi
movslq (%r14), %rax
addq %rax, %r13
addq %rax, %r15
incl (%rsi)
subl %eax, %ebx
jne 0x35a9
movslq (%r14), %r9
movq -0x58(%rbp), %rax
cqto
idivq %r9
movq %rax, %rcx
movq -0x68(%rbp), %r8
leal (%rax,%r8), %edi
decl %edi
movq %r12, %rax
cqto
idivq %r9
movq -0x70(%rbp), %r12
movl %r12d, %ebx
subl %eax, %ebx
incl %ebx
decl %ecx
movl %r12d, %eax
subl %ebx, %eax
cmpl %eax, %ecx
movl %r8d, %eax
cmovgl %ebx, %eax
movl %edi, %ecx
cmovgl %r12d, %ecx
cmovgl %edi, %r12d
cmovgl %r8d, %ebx
movl %eax, 0xc(%rsi)
movl %ecx, 0x10(%rsi)
movq %r14, %rdi
callq 0x3340
movl %ebx, %r8d
cmpl %r12d, %ebx
jl 0x3391
movq -0x30(%rbp), %rax
decl 0x8(%rax)
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq