// File: /workspace/github_c_makefile_star2_O3/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), %rbp
testq %rbp, %rbp
je 0x2a334
movq %rdi, 0x68(%rsp)
movq %rbp, %rbx
movsbl (%rbx), %eax
cmpw $0x2, %ax
jl 0x29fd5
movzwl %ax, %eax
movq %rax, 0x8(%rsp)
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 0x29fc7
movq %r13, %rcx
movq %rcx, %r14
movq 0x18(%rbx,%rcx), %rax
movq %rax, 0x20(%rbx,%rcx)
testq %rcx, %rcx
je 0x29fc2
movq 0x10(%rbx,%r14), %rdi
movq %r15, %rsi
callq *0x40(%rsp)
leaq -0x8(%r14), %rcx
testl %eax, %eax
jg 0x29f9c
movq %r15, 0x18(%rbx,%r14)
incq %r12
addq $0x8, %r13
cmpq 0x8(%rsp), %r12
jne 0x29f84
movq 0x10(%rbx), %rbx
cmpq %rbp, %rbx
jne 0x29f6a
movl $0x1, %r13d
movq %rbp, %rcx
testl %r13d, %r13d
movl $0x0, %edx
cmovgl %r13d, %edx
movl %edx, 0x14(%rsp)
movq %rbp, %r15
movq %rbp, %r12
movl %r13d, %eax
testl %r13d, %r13d
jle 0x2a017
movq 0x10(%r12), %r12
cmpq %rcx, %r12
je 0x2a31c
decl %eax
jne 0x2a005
xorl %ebx, %ebx
movq %r12, %rbp
cmpl %ebx, %edx
je 0x2a02d
movq 0x10(%rbp), %rbp
incl %ebx
cmpq %rcx, %rbp
jne 0x2a01c
jmp 0x2a02f
movl %edx, %ebx
cmpb $0x0, (%r12)
jne 0x2a047
movq 0x10(%r12), %r12
decl %ebx
jne 0x2a02f
movq %r15, %rax
jmp 0x2a2de
movq %rcx, 0x48(%rsp)
movl %r13d, %r14d
movq %r15, 0x38(%rsp)
movl (%r15), %eax
shll $0x8, %eax
testw %ax, %ax
je 0x2a079
cwtl
shrl $0x8, %eax
movswq %ax, %rax
movq 0x10(%r15,%rax,8), %rdi
movq 0x18(%r12), %rsi
callq *0x40(%rsp)
testl %eax, %eax
jns 0x2a098
movq 0x10(%r15), %r15
decl %r14d
jne 0x2a054
movq 0x38(%rsp), %r15
movq %r15, %rax
movq 0x48(%rsp), %rcx
movl 0x14(%rsp), %edx
jmp 0x2a2de
movl %r13d, 0x2c(%rsp)
xorl %edx, %edx
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movq %rbp, 0x58(%rsp)
leaq 0x18(%r12), %rcx
movq %rcx, 0x50(%rsp)
xorl %ebp, %ebp
movl %edx, %r13d
leaq 0x18(%r15), %rcx
movq %rcx, 0x60(%rsp)
movl %eax, 0x8(%rsp)
cltq
movq 0x18(%r15,%rax,8), %rdi
movslq %ebp, %rax
movq 0x50(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
callq *0x40(%rsp)
leal 0x1(%r13), %edx
movslq %r13d, %rcx
testl %eax, %eax
jle 0x2a116
movq 0x18(%rsp), %rax
movq %rax, 0x70(%rsp,%rcx,8)
incl %ebp
movsbl (%r12), %eax
cmpl %eax, %ebp
movl 0x8(%rsp), %eax
jl 0x2a0bc
jmp 0x2a1a2
movq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp,%rcx,8)
movl 0x8(%rsp), %eax
incl %eax
movsbl (%r15), %r13d
cmpl %r13d, %eax
jl 0x2a0bc
movl %ebp, 0x20(%rsp)
movslq %r13d, %rax
movq %rax, 0x8(%rsp)
movl %edx, %ebp
leaq (,%rax,8), %rdx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe1e0
subl %r13d, %ebp
movq 0x8(%rsp), %rax
leaq (%rsp,%rax,8), %rsi
addq $0x70, %rsi
movl %ebp, 0x18(%rsp)
movslq %ebp, %r13
shlq $0x3, %r13
leaq 0x70(%rsp), %rdi
movq %r13, %rdx
callq 0xe260
movq 0x10(%r15), %r15
cmpl $0x1, %r14d
je 0x2a25d
decl %r14d
cmpb $0x0, (%r15)
je 0x2a17c
xorl %eax, %eax
movl 0x18(%rsp), %edx
movl 0x20(%rsp), %ebp
jmp 0x2a0bc
movq 0x8(%r12), %rax
movq 0x10(%r12), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rax)
movq %r15, 0x10(%r12)
movq 0x8(%r15), %rax
movq %rax, 0x8(%r12)
movq %r12, 0x8(%r15)
movq 0x8(%r12), %rax
movq %r12, 0x10(%rax)
movq 0x30(%rsp), %rax
cmpq %rax, %r15
cmoveq %r12, %rax
movq %rax, 0x30(%rsp)
movsbl (%r12), %eax
movswl %ax, %r12d
movswq %r12w, %r13
movl %edx, %ebp
leaq (,%r13,8), %rdx
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xe1e0
subl %r12d, %ebp
leaq (%rsp,%r13,8), %rsi
addq $0x70, %rsi
movl %ebp, 0x18(%rsp)
movslq %ebp, %r13
movq 0x58(%rsp), %rbp
shlq $0x3, %r13
leaq 0x70(%rsp), %rdi
movq %r13, %rdx
callq 0xe260
movq 0x20(%rsp), %rax
movq 0x8(%rax), %r12
decl %ebx
je 0x2a2f0
movq 0x10(%r12), %r12
cmpb $0x0, (%r12)
je 0x2a23c
movl 0x18(%rsp), %edx
movl 0x8(%rsp), %eax
jmp 0x2a0b0
cmpq %r12, %r15
leaq 0x70(%rsp), %rbx
movl 0x18(%rsp), %ebp
je 0x2a2b1
movsbl (%r15), %eax
movswl %ax, %r13d
leaq 0x18(%r15), %rdi
movswq %r13w, %r14
leaq (,%r14,8), %rdx
movq %rbx, %rsi
callq 0xe1e0
subl %r13d, %ebp
leaq (%rsp,%r14,8), %rsi
addq $0x70, %rsi
movslq %ebp, %r13
shlq $0x3, %r13
movq %rbx, %rdi
movq %r13, %rdx
callq 0xe260
movq 0x10(%r15), %r15
cmpq %r12, %r15
jne 0x2a26b
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0xe1e0
movl 0x2c(%rsp), %r13d
movq 0x48(%rsp), %rcx
movl 0x14(%rsp), %edx
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rbp
cmpq %rcx, %r15
cmoveq %rax, %rcx
cmpq %rcx, %rbp
jne 0x29ff7
jmp 0x2a321
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq %r13, %rdx
callq 0xe1e0
movl 0x2c(%rsp), %r13d
movq 0x48(%rsp), %rcx
movl 0x14(%rsp), %edx
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %rax
jmp 0x2a2de
cmpq %rcx, %r15
je 0x2a32c
addl %r13d, %r13d
movq %rcx, %rbp
jmp 0x29fe7
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
nop