// File: jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/midl.c
// Function: mdb_midl_sort
void
mdb_midl_sort( MDB_IDL ids )
{
	/* Max possible depth of int-indexed tree * 2 items/level */
	int istack[sizeof(int)*CHAR_BIT * 2];
	int i,j,k,l,ir,jstack;
	MDB_ID a, itmp;

	ir = (int)ids[0];
	l = 1;
	jstack = 0;
	for(;;) {
		if (ir - l < SMALL) {	/* Insertion sort */
			for (j=l+1;j<=ir;j++) {
				a = ids[j];
				for (i=j-1;i>=1;i--) {
					if (ids[i] >= a) break;
					ids[i+1] = ids[i];
				}
				ids[i+1] = a;
			}
			if (jstack == 0) break;
			ir = istack[jstack--];
			l = istack[jstack--];
		} else {
			k = (l + ir) >> 1;	/* Choose median of left, center, right */
			MIDL_SWAP(ids[k], ids[l+1]);
			if (ids[l] < ids[ir]) {
				MIDL_SWAP(ids[l], ids[ir]);
			}
			if (ids[l+1] < ids[ir]) {
				MIDL_SWAP(ids[l+1], ids[ir]);
			}
			if (ids[l] < ids[l+1]) {
				MIDL_SWAP(ids[l], ids[l+1]);
			}
			i = l+1;
			j = ir;
			a = ids[l+1];
			for(;;) {
				do i++; while(ids[i] > a);
				do j--; while(ids[j] < a);
				if (j < i) break;
				MIDL_SWAP(ids[i],ids[j]);
			}
			ids[l+1] = ids[j];
			ids[j] = a;
			jstack += 2;
			if (ir-i+1 >= j-l) {
				istack[jstack] = ir;
				istack[jstack-1] = i;
				ir = j-1;
			} else {
				istack[jstack] = j-1;
				istack[jstack-1] = l;
				l = i;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x124(%rbp)
movl $0x1, -0x120(%rbp)
movl $0x0, -0x128(%rbp)
movl -0x124(%rbp), %eax
subl -0x120(%rbp), %eax
cmpl $0x8, %eax
jge 0x12d54
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %eax
cmpl -0x124(%rbp), %eax
jg 0x12d01
movq -0x8(%rbp), %rax
movslq -0x118(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x130(%rbp)
movl -0x118(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x114(%rbp)
cmpl $0x1, -0x114(%rbp)
jl 0x12cd2
movq -0x8(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x130(%rbp), %rax
jb 0x12c9e
jmp 0x12cd2
movq -0x8(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movl -0x114(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x114(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x12c7b
movq -0x130(%rbp), %rdx
movq -0x8(%rbp), %rax
movl -0x114(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x12c44
cmpl $0x0, -0x128(%rbp)
jne 0x12d0f
jmp 0x130e5
movl -0x128(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x128(%rbp)
cltq
movl -0x110(%rbp,%rax,4), %eax
movl %eax, -0x124(%rbp)
movl -0x128(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x128(%rbp)
cltq
movl -0x110(%rbp,%rax,4), %eax
movl %eax, -0x120(%rbp)
jmp 0x130e0
movl -0x120(%rbp), %eax
addl -0x124(%rbp), %eax
sarl %eax
movl %eax, -0x11c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x138(%rbp)
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x138(%rbp), %rdx
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movslq -0x120(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movslq -0x124(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x12e26
movq -0x8(%rbp), %rax
movslq -0x120(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x138(%rbp)
movq -0x8(%rbp), %rax
movslq -0x124(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movslq -0x120(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x138(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x124(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movslq -0x124(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x12e9f
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x138(%rbp)
movq -0x8(%rbp), %rax
movslq -0x124(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x138(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x124(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movslq -0x120(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movl -0x120(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x12f18
movq -0x8(%rbp), %rax
movslq -0x120(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x138(%rbp)
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movslq -0x120(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x138(%rbp), %rdx
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
movl -0x124(%rbp), %eax
movl %eax, -0x118(%rbp)
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x130(%rbp)
jmp 0x12f50
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
movq -0x8(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x130(%rbp), %rax
ja 0x12f50
jmp 0x12f79
movl -0x118(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x118(%rbp)
movq -0x8(%rbp), %rax
movslq -0x118(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x130(%rbp), %rax
jb 0x12f79
movl -0x118(%rbp), %eax
cmpl -0x114(%rbp), %eax
jge 0x12fb0
jmp 0x12fff
movq -0x8(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x138(%rbp)
movq -0x8(%rbp), %rax
movslq -0x118(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movslq -0x114(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x138(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x118(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x12f4e
movq -0x8(%rbp), %rax
movslq -0x118(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movl -0x120(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x130(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x118(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x128(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x128(%rbp)
movl -0x124(%rbp), %eax
subl -0x114(%rbp), %eax
addl $0x1, %eax
movl -0x118(%rbp), %ecx
subl -0x120(%rbp), %ecx
cmpl %ecx, %eax
jl 0x130a3
movl -0x124(%rbp), %ecx
movslq -0x128(%rbp), %rax
movl %ecx, -0x110(%rbp,%rax,4)
movl -0x114(%rbp), %ecx
movl -0x128(%rbp), %eax
subl $0x1, %eax
cltq
movl %ecx, -0x110(%rbp,%rax,4)
movl -0x118(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x130de
movl -0x118(%rbp), %ecx
subl $0x1, %ecx
movslq -0x128(%rbp), %rax
movl %ecx, -0x110(%rbp,%rax,4)
movl -0x120(%rbp), %ecx
movl -0x128(%rbp), %eax
subl $0x1, %eax
cltq
movl %ecx, -0x110(%rbp,%rax,4)
movl -0x114(%rbp), %eax
movl %eax, -0x120(%rbp)
jmp 0x130e0
jmp 0x12c20
addq $0xc0, %rsp
popq %rbp
retq
nop