// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl (%rdi), %r8d
xorl %eax, %eax
movl $0x1, %esi
leal 0x1(%rsi), %r9d
movslq %r9d, %r10
movslq %esi, %rcx
movl %ecx, %r11d
negl %r11d
movl %r8d, %ebp
subl %esi, %ebp
movslq %r8d, %rbx
movslq %eax, %rdx
cmpl $0x7, %ebp
jle 0xb50c
leal (%r8,%rsi), %ebp
sarl %ebp
movslq %ebp, %r15
movq (%rdi,%r15,8), %r14
movq (%rdi,%r10,8), %r12
movq %r12, (%rdi,%r15,8)
movq %r14, (%rdi,%r10,8)
movq (%rdi,%rcx,8), %r15
movq (%rdi,%rbx,8), %r12
cmpq %r12, %r15
jae 0xb44a
movq %r12, (%rdi,%rcx,8)
movq %r15, (%rdi,%rbx,8)
movq (%rdi,%r10,8), %r14
jmp 0xb44d
movq %r12, %r15
cmpq %r15, %r14
jae 0xb45e
movq %r15, (%rdi,%r10,8)
movq %r14, (%rdi,%rbx,8)
movq (%rdi,%r10,8), %r14
movq (%rdi,%rcx,8), %r15
cmpq %r14, %r15
jae 0xb471
movq %r14, (%rdi,%rcx,8)
movq %r15, (%rdi,%r10,8)
jmp 0xb474
movq %r14, %r15
movl %r8d, %ebx
movl %r9d, %r14d
movslq %r14d, %r14
movq 0x8(%rdi,%r14,8), %r12
incq %r14
cmpq %r15, %r12
ja 0xb47d
movslq %ebx, %r13
incq %r13
movq -0x10(%rdi,%r13,8), %rbp
decl %ebx
decq %r13
cmpq %r15, %rbp
jb 0xb490
cmpq %r14, %r13
jle 0xb4af
movq %rbp, (%rdi,%r14,8)
movq %r12, -0x8(%rdi,%r13,8)
jmp 0xb47a
movq %rbp, (%rdi,%r10,8)
movq %r15, -0x8(%rdi,%r13,8)
addl $0x2, %eax
movl %r8d, %ebp
subl %r14d, %ebp
incl %ebp
leal (%r11,%rbx), %r12d
movslq %eax, %r15
cmpl %r12d, %ebp
jl 0xb529
movl %r8d, -0x80(%rsp,%r15,4)
movl %r14d, -0x7c(%rsp,%rdx,4)
decl %ebx
movl %ebx, %r8d
jmp 0xb402
movslq %ecx, %rsi
incq %rcx
movq (%rdi,%rcx,8), %r8
testl %esi, %esi
jle 0xb507
movl %esi, %r9d
movq (%rdi,%r9,8), %r10
cmpq %r8, %r10
jae 0xb507
movq %r10, 0x8(%rdi,%r9,8)
decq %rsi
jmp 0xb4ed
movq %r8, 0x8(%rdi,%rsi,8)
cmpq %rbx, %rcx
jl 0xb4e3
testl %eax, %eax
je 0xb53c
movl -0x84(%rsp,%rdx,4), %esi
movl -0x80(%rsp,%rdx,4), %r8d
addl $-0x2, %eax
jmp 0xb3f2
decl %ebx
movl %ebx, -0x80(%rsp,%r15,4)
movl %esi, -0x7c(%rsp,%rdx,4)
movl %r14d, %esi
jmp 0xb3f2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq