// File: /workspace/github_c_makefile_star2_O1/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 %rsi, 0x40(%rsp)
movq %rdi, 0x60(%rsp)
movq (%rdi), %rdx
testq %rdx, %rdx
je 0x2a7e0
movq %rdx, %rbx
movq %rdx, 0x48(%rsp)
movsbl (%rbx), %eax
cmpw $0x2, %ax
jl 0x2a41b
movzwl %ax, %r14d
movl $0x1, %r12d
xorl %r13d, %r13d
movq 0x10(%rbx,%r12,8), %rdi
movq 0x18(%rbx,%r12,8), %r15
movq %r15, %rsi
callq *0x40(%rsp)
testl %eax, %eax
jle 0x2a410
movq %r13, %rbp
movq 0x18(%rbx,%rbp,8), %rax
movq %rax, 0x20(%rbx,%rbp,8)
subq $0x1, %rbp
jb 0x2a406
movq 0x18(%rbx,%rbp,8), %rdi
movq %r15, %rsi
callq *0x40(%rsp)
testl %eax, %eax
jg 0x2a3e1
incq %rbp
jmp 0x2a408
xorl %ebp, %ebp
movslq %ebp, %rax
movq %r15, 0x18(%rbx,%rax,8)
incq %r12
incq %r13
cmpq %r14, %r12
jne 0x2a3c9
movq 0x10(%rbx), %rbx
movq 0x48(%rsp), %rdx
cmpq %rdx, %rbx
jne 0x2a3b3
movl $0x1, %ebx
testl %ebx, %ebx
movl $0x0, %edi
cmovgl %ebx, %edi
movq %rdx, %r12
movl %ebx, 0x5c(%rsp)
movl %edi, 0x58(%rsp)
movq %r12, %r15
movl %ebx, %eax
testl %ebx, %ebx
jle 0x2a45d
movq 0x10(%r15), %r15
cmpq %rdx, %r15
je 0x2a4de
decl %eax
jne 0x2a44c
xorl %r13d, %r13d
movq %r15, %rax
cmpl %r13d, %edi
je 0x2a476
movq 0x10(%rax), %rax
incl %r13d
cmpq %rdx, %rax
jne 0x2a463
jmp 0x2a479
movl %edi, %r13d
movq %rdx, 0x48(%rsp)
movq %r12, 0x50(%rsp)
movq %rax, 0x68(%rsp)
cmpb $0x0, (%r15)
jne 0x2a4a1
movq 0x10(%r15), %r15
decl %r13d
jne 0x2a488
movq %r12, 0x28(%rsp)
jmp 0x2a788
movl (%r12), %eax
shll $0x8, %eax
testw %ax, %ax
je 0x2a4c6
cwtl
shrl $0x8, %eax
movswq %ax, %rax
movq 0x10(%r12,%rax,8), %rdi
movq 0x18(%r15), %rsi
callq *0x40(%rsp)
testl %eax, %eax
jns 0x2a4f1
movq 0x10(%r12), %r12
decl %ebx
jne 0x2a4a1
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x2a788
cmpq %rdx, %r12
je 0x2a7ab
movl $0xf, %ecx
jmp 0x2a7b8
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %edx, %edx
movl %r8d, %eax
movq %rax, 0x10(%rsp)
leaq 0x18(%r12), %rax
movq %rax, 0x38(%rsp)
movslq %edx, %rax
movq 0x18(%r12,%rax,8), %rdi
leaq 0x18(%r15), %rax
movq %rax, 0x20(%rsp)
movslq %ecx, %rax
movq 0x18(%r15,%rax,8), %rsi
movq %rdi, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movl %edx, %ebp
movl %ecx, %r14d
callq *0x40(%rsp)
movq 0x10(%rsp), %rcx
leal 0x1(%rcx), %r8d
movslq %ecx, %rcx
testl %eax, %eax
jle 0x2a579
movl %ebp, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x70(%rsp,%rcx,8)
incl %r14d
movsbl (%r15), %eax
movb $0x1, %dil
cmpl %eax, %r14d
movl %r14d, %ecx
jge 0x2a5a5
movl 0x10(%rsp), %edx
jmp 0x2a77f
movl %r14d, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x70(%rsp,%rcx,8)
incl %ebp
movsbl (%r12), %eax
movb $0x1, %dil
cmpl %eax, %ebp
movl %ebp, %edx
jge 0x2a65f
movl 0x8(%rsp), %ecx
jmp 0x2a77f
movl %ecx, 0x8(%rsp)
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rax)
movq %r12, 0x10(%r15)
movq 0x8(%r12), %rax
movq %rax, 0x8(%r15)
movq %r15, 0x8(%r12)
movq 0x8(%r15), %rax
movq %r15, 0x10(%rax)
movq 0x30(%rsp), %rax
cmpq %rax, %r12
cmoveq %r15, %rax
movq %rax, 0x30(%rsp)
movsbl (%r15), %eax
movswl %ax, %r14d
movswq %r14w, %r15
leaq (,%r15,8), %rdx
movq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl %r8d, %ebp
callq 0xe1e0
subl %r14d, %ebp
leaq (%rsp,%r15,8), %rsi
addq $0x70, %rsi
movl %ebp, 0x20(%rsp)
movslq %ebp, %r14
shlq $0x3, %r14
leaq 0x70(%rsp), %rdi
movq %r14, %rdx
callq 0xe260
movq 0x18(%rsp), %rax
movq 0x8(%rax), %r15
movq 0x10(%r15), %r15
cmpl $0x1, %r13d
je 0x2a6d3
decl %r13d
cmpb $0x0, (%r15)
je 0x2a63b
xorl %ecx, %ecx
movl 0x10(%rsp), %edx
movl 0x20(%rsp), %r8d
jmp 0x2a6cb
movl %edx, 0x10(%rsp)
movslq %eax, %rcx
movq %rcx, 0x18(%rsp)
leaq (,%rcx,8), %rdx
movq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %r14
movl %r8d, %ebp
movq %r14, %rsi
movl %eax, 0x38(%rsp)
callq 0xe1e0
subl 0x38(%rsp), %ebp
movq %r14, %rdi
movq 0x18(%rsp), %rcx
leaq (%rsp,%rcx,8), %rsi
addq $0x70, %rsi
movl %ebp, %r14d
movslq %ebp, %rdx
shlq $0x3, %rdx
callq 0xe260
movl 0x8(%rsp), %ecx
movq 0x10(%r12), %r12
cmpl $0x1, %ebx
je 0x2a703
decl %ebx
cmpb $0x0, (%r12)
je 0x2a6b3
xorl %edx, %edx
movl %r14d, %r8d
movb $0x1, %dil
jmp 0x2a77f
movq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq %r14, %rdx
callq 0xe1e0
xorl %edi, %edi
xorl %r13d, %r13d
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0x8(%rsp), %ecx
movl 0x10(%rsp), %edx
movl 0x20(%rsp), %r8d
jmp 0x2a77f
movl %r14d, %ebp
cmpq %r15, %r12
je 0x2a750
movsbl (%r12), %eax
movswl %ax, %ebx
leaq 0x18(%r12), %rdi
movswq %bx, %r14
leaq (,%r14,8), %rdx
leaq 0x70(%rsp), %rsi
callq 0xe1e0
subl %ebx, %ebp
leaq (%rsp,%r14,8), %rsi
addq $0x70, %rsi
movslq %ebp, %rdx
shlq $0x3, %rdx
leaq 0x70(%rsp), %rdi
callq 0xe260
movq 0x10(%r12), %r12
jmp 0x2a706
movslq %ebp, %rdx
shlq $0x3, %rdx
movq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe1e0
xorl %edi, %edi
xorl %ebx, %ebx
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0x8(%rsp), %ecx
movl 0x10(%rsp), %edx
movl %ebp, %r8d
testb %dil, %dil
jne 0x2a502
movq 0x48(%rsp), %rdx
cmpq %rdx, 0x50(%rsp)
cmoveq 0x28(%rsp), %rdx
xorl %ecx, %ecx
movb $0x1, %al
movl 0x5c(%rsp), %ebx
movl 0x58(%rsp), %edi
movq 0x68(%rsp), %r8
jmp 0x2a7bd
movq 0x60(%rsp), %rax
movq %rdx, (%rax)
movl $0x1, %ecx
xorl %eax, %eax
movq %r12, %r8
testl %ecx, %ecx
jne 0x2a7cf
movq %r8, %r12
cmpq %rdx, %r8
jne 0x2a443
jmp 0x2a7d4
cmpl $0xf, %ecx
jne 0x2a7d8
addl %ebx, %ebx
movb $0x1, %al
testb %al, %al
jne 0x2a42e
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop