// File: /workspace/github_c_makefile_star2_O2/lucvoo[P]sparse-dev/sort.c
// Function: sort_list
void sort_list(struct ptr_list **plist, int (*cmp)(const void *, const void *))
{
	struct ptr_list *head = *plist, *list = head;
	int blocks = 1;

	if (!head)
		return;

	// Sort all the sub-lists
	do {
		array_sort(list->list, list->nr, cmp);
#ifdef PARANOIA
		verify_seq_sorted (list, 1, cmp);
#endif
		list = list->next;
	} while (list != head);

	// Merge the damn things together
	while (1) {
		struct ptr_list *block1 = head;

		do {
			struct ptr_list *block2 = block1;
			struct ptr_list *next, *newhead;
			int i;

			for (i = 0; i < blocks; i++) {
				block2 = block2->next;
				if (block2 == head) {
					if (block1 == head) {
						BEEN_THERE('A');
						*plist = head;
						return;
					}
					BEEN_THERE('B');
					goto next_pass;
				}						
			}

			next = block2;
			for (i = 0; i < blocks; ) {
				next = next->next;
				i++;
				if (next == head) {
					BEEN_THERE('C');
					break;
				}
				BEEN_THERE('D');
			}

			newhead = merge_block_seqs (block1, blocks,
						    block2, i,
						    cmp);
#ifdef PARANOIA
			verify_seq_sorted (newhead, blocks + i, cmp);
#endif
			if (block1 == head) {
				BEEN_THERE('E');
				head = newhead;
			}
			block1 = next;
		} while (block1 != head);
	next_pass:
		blocks <<= 1;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x68(%rsp)
movq (%rdi), %r13
testq %r13, %r13
je 0x25bca
movq %rsi, %r14
movq %r13, %r12
movq %r13, 0x38(%rsp)
movsbq (%r12), %rax
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
pushq $0x1
popq %r13
cmpq 0x8(%rsp), %r13
jge 0x25862
movq 0x10(%r12,%r13,8), %rdi
movq 0x18(%r12,%r13,8), %r15
movq %r15, %rsi
callq *%r14
testl %eax, %eax
jle 0x25859
movq %rbx, %rcx
movq %rcx, %rbp
movq 0x18(%r12,%rcx), %rax
movq %rax, 0x20(%r12,%rcx)
testq %rcx, %rcx
je 0x25854
movq 0x10(%r12,%rbp), %rdi
movq %r15, %rsi
callq *%r14
leaq -0x8(%rbp), %rcx
testl %eax, %eax
jg 0x2582f
movq %r15, 0x18(%r12,%rbp)
incq %r13
addq $0x8, %rbx
jmp 0x25811
movq 0x10(%r12), %r12
movq 0x38(%rsp), %r13
cmpq %r13, %r12
jne 0x25801
pushq $0x1
popq %r15
movq %r13, %rcx
testl %r15d, %r15d
movl $0x0, %edx
cmovgl %r15d, %edx
leal 0x1(%rdx), %esi
movq %r13, %rbx
movl %esi, %eax
movq %r13, %r12
decl %eax
je 0x258a2
movq 0x10(%r12), %r12
cmpq %rcx, %r12
jne 0x2588f
jmp 0x25bb2
xorl %ebp, %ebp
movq %r12, %r13
cmpl %ebp, %edx
je 0x258b8
movq 0x10(%r13), %r13
incl %ebp
cmpq %rcx, %r13
jne 0x258a7
jmp 0x258ba
movl %edx, %ebp
cmpb $0x0, (%r12)
jne 0x258d2
movq 0x10(%r12), %r12
decl %ebp
jne 0x258ba
movq %rbx, %rax
jmp 0x25b8f
movl %esi, 0x18(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movl %r15d, 0x1c(%rsp)
movq %rbx, 0x30(%rsp)
movl (%rbx), %eax
shll $0x8, %eax
testw %ax, %ax
je 0x2590d
cwtl
shrl $0x8, %eax
movswq %ax, %rax
movq 0x10(%rbx,%rax,8), %rdi
movq 0x18(%r12), %rsi
callq *%r14
testl %eax, %eax
jns 0x25936
movq 0x10(%rbx), %rbx
decl %r15d
jne 0x258ea
movq 0x30(%rsp), %rbx
movq %rbx, %rax
movl 0x1c(%rsp), %r15d
movq 0x48(%rsp), %rcx
movq 0x40(%rsp), %rdx
movl 0x18(%rsp), %esi
jmp 0x25b8f
movq %r13, 0x38(%rsp)
xorl %edx, %edx
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
xorl %ecx, %ecx
leaq 0x18(%r12), %rax
movq %rax, 0x50(%rsp)
xorl %esi, %esi
movl %esi, 0x20(%rsp)
movl %ecx, 0x14(%rsp)
movl %edx, %r13d
leaq 0x18(%rbx), %rax
movq %rax, 0x60(%rsp)
movslq %ecx, %rax
movq 0x18(%rbx,%rax,8), %rdi
movslq %esi, %rax
movq 0x50(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rdi, 0x58(%rsp)
movq %rsi, 0x8(%rsp)
callq *%r14
leal 0x1(%r13), %edx
movslq %r13d, %rcx
testl %eax, %eax
jle 0x259b7
movq 0x8(%rsp), %rax
movq %rax, 0x70(%rsp,%rcx,8)
movl 0x20(%rsp), %esi
incl %esi
movsbl (%r12), %eax
cmpl %eax, %esi
movl 0x14(%rsp), %ecx
jl 0x25955
jmp 0x25a4c
movq 0x58(%rsp), %rax
movq %rax, 0x70(%rsp,%rcx,8)
movl 0x14(%rsp), %eax
incl %eax
movsbl (%rbx), %edi
cmpl %edi, %eax
movl %eax, %ecx
movl 0x20(%rsp), %esi
jl 0x25955
movslq %edi, %rax
movq %rax, 0x8(%rsp)
movl %edx, %r13d
leaq (,%rax,8), %rdx
movl %edi, 0x14(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe1e0
subl 0x14(%rsp), %r13d
movq 0x8(%rsp), %rax
leaq (%rsp,%rax,8), %rsi
addq $0x70, %rsi
movl %r13d, 0x8(%rsp)
movslq %r13d, %rdx
shlq $0x3, %rdx
leaq 0x70(%rsp), %rdi
callq 0xe270
movq 0x38(%rsp), %r13
movq 0x10(%rbx), %rbx
cmpl $0x1, %r15d
je 0x25b55
decl %r15d
cmpb $0x0, (%rbx)
je 0x25a27
xorl %ecx, %ecx
movl 0x8(%rsp), %edx
movl 0x20(%rsp), %esi
jmp 0x25955
movq 0x8(%r12), %rax
movq 0x10(%r12), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rax)
movq %rbx, 0x10(%r12)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r12)
movq %r12, 0x8(%rbx)
movq 0x8(%r12), %rax
movq %r12, 0x10(%rax)
movq 0x28(%rsp), %rax
cmpq %rax, %rbx
cmoveq %r12, %rax
movq %rax, 0x28(%rsp)
movsbl (%r12), %eax
cwtl
movl %eax, 0x8(%rsp)
movswq %ax, %r13
movl %edx, %r12d
leaq (,%r13,8), %rdx
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe1e0
subl 0x8(%rsp), %r12d
leaq (%rsp,%r13,8), %rsi
addq $0x70, %rsi
movl %r12d, 0x8(%rsp)
movslq %r12d, %rdx
shlq $0x3, %rdx
leaq 0x70(%rsp), %rdi
movq %rdx, 0x58(%rsp)
callq 0xe270
movq 0x20(%rsp), %rax
movq 0x8(%rax), %r12
movq 0x38(%rsp), %r13
decl %ebp
je 0x25ba1
movq 0x10(%r12), %r12
cmpb $0x0, (%r12)
je 0x25aed
movl 0x8(%rsp), %edx
movl 0x14(%rsp), %ecx
jmp 0x25949
movsbl (%rbx), %eax
movswl %ax, %ebp
leaq 0x18(%rbx), %rdi
movswq %bp, %r15
leaq (,%r15,8), %rdx
leaq 0x70(%rsp), %rsi
callq 0xe1e0
movl 0x8(%rsp), %eax
subl %ebp, %eax
leaq (%rsp,%r15,8), %rsi
addq $0x70, %rsi
movl %eax, 0x8(%rsp)
movslq %eax, %rdx
shlq $0x3, %rdx
leaq 0x70(%rsp), %rdi
callq 0xe270
movq 0x10(%rbx), %rbx
cmpq %r12, %rbx
jne 0x25b0e
movslq 0x8(%rsp), %rdx
shlq $0x3, %rdx
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe1e0
movl 0x1c(%rsp), %r15d
movq 0x48(%rsp), %rcx
movq 0x40(%rsp), %rdx
movl 0x18(%rsp), %esi
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %rax
cmpq %rcx, %rbx
cmoveq %rax, %rcx
cmpq %rcx, %r13
jne 0x25887
jmp 0x25bb7
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq 0x58(%rsp), %rdx
jmp 0x25b6d
cmpq %rcx, %rbx
je 0x25bc2
addl %r15d, %r15d
movq %rcx, %r13
jmp 0x25878
movq 0x68(%rsp), %rax
movq %rcx, (%rax)
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq