// File: jeffchan[P]blockchain-parser/BlockChain.cpp
// Function: QuickSortPointers::qsort(void**, int)
void QuickSortPointers::qsort(void **b,int32_t num)
{
	char *lo,*hi;
	char *mid;
	char *bottom, *top;
	int32_t size;
	char *lostk[30], *histk[30];
	int32_t stkptr;
	char **base = (char **)b;

	if (num < 2 ) return;

	stkptr = 0;

	lo = (char *)base;
	hi = (char *)base + sizeof(char **) * (num-1);

nextone:

	size = (int32_t)(hi - lo) / sizeof(char**) + 1;

	mid = lo + (size / 2) * sizeof(char **);
	swap((char **)mid,(char **)lo);
	bottom = lo;
	top = hi + sizeof(char **);

	for (;;)
	{
		do
		{
			bottom += sizeof(char **);
		} while (bottom <= hi && compare((void **)bottom,(void **)lo) <= 0);

		do
		{
			top -= sizeof(char **);
		} while (top > lo && compare((void **)top,(void **)lo) >= 0);

		if (top < bottom) break;

		swap((char **)bottom,(char **)top);

	}

	swap((char **)lo,(char **)top);

	if ( top - 1 - lo >= hi - bottom )
	{
		if (lo + sizeof(char **) < top)
		{
			lostk[stkptr] = lo;
			histk[stkptr] = top - sizeof(char **);
			stkptr++;
		}
		if (bottom < hi)
		{
			lo = bottom;
			goto nextone;
		}
	}
	else
	{
		if ( bottom < hi )
		{
			lostk[stkptr] = bottom;
			histk[stkptr] = hi;
			stkptr++;
		}
		if (lo + sizeof(char **) < top)
		{
			hi = top - sizeof(char **);
			goto nextone; 					/* do small recursion */
		}
	}

	stkptr--;

	if (stkptr >= 0)
	{
		lo = lostk[stkptr];
		hi = histk[stkptr];
		goto nextone;
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x240(%rbp)
cmpl $0x2, -0x14(%rbp)
jge 0x198e7
jmp 0x19b75
movl $0x0, -0x234(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x240(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x248(%rbp), %rdi
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
cltq
shrq $0x3, %rax
addq $0x1, %rax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x250(%rbp)
movl -0x44(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x250(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x19eb0
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
jmp 0x19986
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x251(%rbp)
ja 0x199c4
movq -0x248(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq (%rdi), %rax
callq *(%rax)
cmpl $0x0, %eax
setle %al
movb %al, -0x251(%rbp)
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0x19986
jmp 0x199d0
movq -0x40(%rbp), %rax
addq $-0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x252(%rbp)
jbe 0x19a0e
movq -0x248(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq (%rdi), %rax
callq *(%rax)
cmpl $0x0, %eax
setge %al
movb %al, -0x252(%rbp)
movb -0x252(%rbp), %al
testb $0x1, %al
jne 0x199d0
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x19a24
jmp 0x19a3d
movq -0x248(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x19eb0
jmp 0x19984
movq -0x248(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x19eb0
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jl 0x19ad0
movq -0x20(%rbp), %rax
addq $0x8, %rax
cmpq -0x40(%rbp), %rax
jae 0x19ab7
movq -0x20(%rbp), %rcx
movslq -0x234(%rbp), %rax
movq %rcx, -0x140(%rbp,%rax,8)
movq -0x40(%rbp), %rcx
addq $-0x8, %rcx
movslq -0x234(%rbp), %rax
movq %rcx, -0x230(%rbp,%rax,8)
movl -0x234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x19ace
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x19917
jmp 0x19b30
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x19b0f
movq -0x38(%rbp), %rcx
movslq -0x234(%rbp), %rax
movq %rcx, -0x140(%rbp,%rax,8)
movq -0x28(%rbp), %rcx
movslq -0x234(%rbp), %rax
movq %rcx, -0x230(%rbp,%rax,8)
movl -0x234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
movq -0x20(%rbp), %rax
addq $0x8, %rax
cmpq -0x40(%rbp), %rax
jae 0x19b2e
movq -0x40(%rbp), %rax
addq $-0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x19917
jmp 0x19b30
movl -0x234(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x234(%rbp)
cmpl $0x0, -0x234(%rbp)
jl 0x19b73
movslq -0x234(%rbp), %rax
movq -0x140(%rbp,%rax,8), %rax
movq %rax, -0x20(%rbp)
movslq -0x234(%rbp), %rax
movq -0x230(%rbp,%rax,8), %rax
movq %rax, -0x28(%rbp)
jmp 0x19917
jmp 0x19b75
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nop