// File: /workspace/github_c_makefile_star2_O0/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
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x4a4e
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movq %rsp, %rcx
movq %rcx, -0x18(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xb8(%rbp)
movq %rcx, %rsp
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x508c
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rdx
imull (%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rdx
imull (%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xc0(%rbp)
movl -0x24(%rbp), %eax
addl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movq -0x8(%rbp), %rdx
imull (%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x28(%rbp), %eax
subl -0x24(%rbp), %eax
cmpl $0xf, %eax
jl 0x4be1
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x4b8d
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x4b8b
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x4b89
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x4b8b
jmp 0x4bdf
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x4bdd
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x4bdb
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x4bdd
jmp 0x4bdf
jmp 0x4be1
movq -0xb8(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rdx
callq *%rax
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x4c1c
jmp 0x4c1e
movq -0x58(%rbp), %rcx
xorl %eax, %eax
cmpq -0x60(%rbp), %rcx
movb %al, -0xc1(%rbp)
ja 0x4c58
movq -0xb8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq *%rax
movl %eax, -0x6c(%rbp)
cmpl $0x0, %eax
setle %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x4c64
jmp 0x4cc3
cmpl $0x0, -0x6c(%rbp)
jne 0x4c9f
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq *%rax
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4c1e
jmp 0x4cc5
movq -0x60(%rbp), %rcx
xorl %eax, %eax
cmpq -0x58(%rbp), %rcx
movb %al, -0xc2(%rbp)
jb 0x4cff
movq -0xb8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq *%rax
movl %eax, -0x6c(%rbp)
cmpl $0x0, %eax
setge %al
movb %al, -0xc2(%rbp)
movb -0xc2(%rbp), %al
testb $0x1, %al
jne 0x4d0b
jmp 0x4d74
cmpl $0x0, -0x6c(%rbp)
jne 0x4d4b
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq *%rax
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x68(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4cc5
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jbe 0x4d80
jmp 0x4dd3
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq *%rax
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4c1a
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x4e08
movq -0x78(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x4e13
movq -0x80(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl %eax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movslq -0x70(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x4eaa
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x90(%rbp), %rdx
callq *%rax
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x90(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movl -0x70(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4e42
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jge 0x4eee
movq -0x98(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0x4efc
movq -0xa0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movl %eax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x70(%rbp), %ecx
movq -0x8(%rbp), %rax
subl (%rax), %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x4fa3
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq *%rax
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x90(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
movl -0x70(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4f3b
movslq -0x24(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq (%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rcx
movq -0xe8(%rbp), %rax
addq %rcx, %rax
subq $0x1, %rax
movl %eax, -0xac(%rbp)
movslq -0x28(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq (%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rcx
movq -0xe0(%rbp), %rax
subq %rcx, %rax
addq $0x1, %rax
movl %eax, -0xb0(%rbp)
movl -0xac(%rbp), %eax
subl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
subl -0xb0(%rbp), %ecx
cmpl %ecx, %eax
jg 0x505a
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0xac(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4a10
movl -0xb0(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x5087
movl -0xb0(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4a10
movl -0xac(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x4a8e
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq %rax, %rsp
xorl %eax, %eax
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)