// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/bzip2-1.0.6/blocksort.c
// Function: fallbackSort
static
void fallbackSort ( UInt32* fmap, 
                    UInt32* eclass, 
                    UInt32* bhtab,
                    Int32   nblock,
                    Int32   verb )
{
   Int32 ftab[257];
   Int32 ftabCopy[256];
   Int32 H, i, j, k, l, r, cc, cc1;
   Int32 nNotDone;
   Int32 nBhtab;
   UChar* eclass8 = (UChar*)eclass;

   /*--
      Initial 1-char radix sort to generate
      initial fmap and initial BH bits.
   --*/
   if (verb >= 4)
      VPrintf0 ( "        bucket sorting ...\n" );
   for (i = 0; i < 257;    i++) ftab[i] = 0;
   for (i = 0; i < nblock; i++) ftab[eclass8[i]]++;
   for (i = 0; i < 256;    i++) ftabCopy[i] = ftab[i];
   for (i = 1; i < 257;    i++) ftab[i] += ftab[i-1];

   for (i = 0; i < nblock; i++) {
      j = eclass8[i];
      k = ftab[j] - 1;
      ftab[j] = k;
      fmap[k] = i;
   }

   nBhtab = 2 + (nblock / 32);
   for (i = 0; i < nBhtab; i++) bhtab[i] = 0;
   for (i = 0; i < 256; i++) SET_BH(ftab[i]);

   /*--
      Inductively refine the buckets.  Kind-of an
      "exponential radix sort" (!), inspired by the
      Manber-Myers suffix array construction algorithm.
   --*/

   /*-- set sentinel bits for block-end detection --*/
   for (i = 0; i < 32; i++) { 
      SET_BH(nblock + 2*i);
      CLEAR_BH(nblock + 2*i + 1);
   }

   /*-- the log(N) loop --*/
   H = 1;
   while (1) {

      if (verb >= 4) 
         VPrintf1 ( "        depth %6d has ", H );

      j = 0;
      for (i = 0; i < nblock; i++) {
         if (ISSET_BH(i)) j = i;
         k = fmap[i] - H; if (k < 0) k += nblock;
         eclass[k] = j;
      }

      nNotDone = 0;
      r = -1;
      while (1) {

	 /*-- find the next non-singleton bucket --*/
         k = r + 1;
         while (ISSET_BH(k) && UNALIGNED_BH(k)) k++;
         if (ISSET_BH(k)) {
            while (WORD_BH(k) == 0xffffffff) k += 32;
            while (ISSET_BH(k)) k++;
         }
         l = k - 1;
         if (l >= nblock) break;
         while (!ISSET_BH(k) && UNALIGNED_BH(k)) k++;
         if (!ISSET_BH(k)) {
            while (WORD_BH(k) == 0x00000000) k += 32;
            while (!ISSET_BH(k)) k++;
         }
         r = k - 1;
         if (r >= nblock) break;

         /*-- now [l, r] bracket current bucket --*/
         if (r > l) {
            nNotDone += (r - l + 1);
            fallbackQSort3 ( fmap, eclass, l, r );

            /*-- scan bucket and generate header bits-- */
            cc = -1;
            for (i = l; i <= r; i++) {
               cc1 = eclass[fmap[i]];
               if (cc != cc1) { SET_BH(i); cc = cc1; };
            }
         }
      }

      if (verb >= 4) 
         VPrintf1 ( "%6d unresolved strings\n", nNotDone );

      H *= 2;
      if (H > nblock || nNotDone == 0) break;
   }

   /*-- 
      Reconstruct the original block in
      eclass8 [0 .. nblock-1], since the
      previous phase destroyed it.
   --*/
   if (verb >= 4)
      VPrintf0 ( "        reconstructing block ...\n" );
   j = 0;
   for (i = 0; i < nblock; i++) {
      while (ftabCopy[j] == 0) j++;
      ftabCopy[j]--;
      eclass8[fmap[i]] = (UChar)j;
   }
   AssertH ( j < 256, 1005 );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb98, %rsp            # imm = 0xB98
movq %rdx, 0x28(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movl %r8d, 0x3c(%rsp)
cmpl $0x4, %r8d
movq %rcx, 0x18(%rsp)
jge 0xdd9ee
movl %ecx, %r15d
leaq 0x380(%rsp), %rdi
xorl %ebp, %ebp
movl $0x404, %edx            # imm = 0x404
xorl %esi, %esi
callq 0xb2f0
cmpl $0x0, 0x18(%rsp)
jle 0xdd283
xorl %eax, %eax
movzbl (%rbx,%rax), %ecx
incl 0x380(%rsp,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0xdd269
movl 0x380(%rsp), %ebp
leaq 0x790(%rsp), %rdi
leaq 0x380(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0xb520
movl $0x1, %eax
addl 0x380(%rsp,%rax,4), %ebp
movl %ebp, 0x380(%rsp,%rax,4)
incq %rax
cmpq $0x101, %rax            # imm = 0x101
jne 0xdd2a2
movq 0x18(%rsp), %r9
testl %r9d, %r9d
movq 0x28(%rsp), %rdi
jle 0xdd2f0
xorl %eax, %eax
movzbl (%rbx,%rax), %ecx
movslq 0x380(%rsp,%rcx,4), %rdx
leaq -0x1(%rdx), %rsi
movl %esi, 0x380(%rsp,%rcx,4)
movl %eax, -0x4(%r14,%rdx,4)
incq %rax
cmpq %rax, %r15
jne 0xdd2cc
cmpl $-0x3f, %r9d
jl 0xdd31f
leal 0x1f(%r9), %eax
testl %r9d, %r9d
cmovnsl %r9d, %eax
sarl $0x5, %eax
incl %eax
leaq 0x4(,%rax,4), %rdx
xorl %esi, %esi
callq 0xb2f0
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %r9
xorl %eax, %eax
movl 0x380(%rsp,%rax,4), %ecx
movl $0x1, %edx
shll %cl, %edx
sarl $0x5, %ecx
movslq %ecx, %rcx
orl %edx, (%rdi,%rcx,4)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0xdd321
leal 0x1(%r9), %eax
xorl %edx, %edx
leal (%r9,%rdx), %ecx
movl $0x1, %esi
shll %cl, %esi
sarl $0x5, %ecx
movslq %ecx, %rcx
orl %esi, (%rdi,%rcx,4)
leal (%rax,%rdx), %ecx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
roll %cl, %esi
sarl $0x5, %ecx
movslq %ecx, %rcx
andl %esi, (%rdi,%rcx,4)
addl $0x2, %edx
cmpl $0x40, %edx
jne 0xdd349
movl $0x1, %edx
movq %r15, 0x50(%rsp)
cmpl $0x4, 0x3c(%rsp)
movl %edx, 0x24(%rsp)
jge 0xdd90c
testl %r9d, %r9d
jle 0xdd3c9
xorl %eax, %eax
xorl %ecx, %ecx
movl %eax, %esi
shrl $0x5, %esi
movl (%rdi,%rsi,4), %esi
btl %eax, %esi
cmovbl %eax, %ecx
movl (%r14,%rax,4), %r8d
subl %edx, %r8d
movl %r8d, %esi
sarl $0x1f, %esi
andl %r15d, %esi
addl %r8d, %esi
movslq %esi, %rsi
movl %ecx, (%rbx,%rsi,4)
incq %rax
cmpq %rax, %r15
jne 0xdd39a
xorl %r15d, %r15d
movq $0x0, 0x30(%rsp)
leal -0x20(%r15), %ecx
leal -0x1(%r15), %r8d
movl %ecx, %r10d
movl %r8d, %esi
movl %r15d, %eax
sarl $0x5, %eax
movslq %eax, %r8
movl %r15d, %ecx
andl $0x1f, %ecx
movl $0x1, %eax
shll %cl, %eax
andl (%rdi,%r8,4), %eax
incl %r15d
testl %ecx, %ecx
je 0xdd410
leal 0x1(%r10), %ecx
leal 0x1(%rsi), %r8d
testl %eax, %eax
jne 0xdd3dd
testl %eax, %eax
je 0xdd440
movl %esi, %eax
addl $0x20, %r10d
movl %r10d, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
leal 0x20(%rax), %esi
cmpl $-0x1, (%rdi,%rcx,4)
je 0xdd414
incl %eax
movl %eax, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rdi,%rcx,4), %ecx
btl %eax, %ecx
jb 0xdd42c
jmp 0xdd446
decl %r15d
movl %r15d, %eax
cmpl %r9d, %eax
jg 0xdd8e8
leal -0x1(%rax), %r8d
leal -0x20(%rax), %ecx
movl %r8d, 0x44(%rsp)
movl %eax, %r15d
movl %ecx, %r11d
movl %r8d, %esi
movl %r15d, %ecx
sarl $0x5, %ecx
movslq %ecx, %r8
movl %r15d, %ecx
andl $0x1f, %ecx
movl $0x1, %r10d
shll %cl, %r10d
andl (%rdi,%r8,4), %r10d
incl %r15d
testl %ecx, %ecx
je 0xdd494
leal 0x1(%r11), %ecx
leal 0x1(%rsi), %r8d
testl %r10d, %r10d
je 0xdd45e
testl %r10d, %r10d
je 0xdd49e
decl %r15d
jmp 0xdd4cd
movl %esi, %r15d
addl $0x20, %r11d
movl %r11d, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
leal 0x20(%r15), %esi
cmpl $0x0, (%rdi,%rcx,4)
je 0xdd49e
incl %r15d
movl %r15d, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rdi,%rcx,4), %ecx
btl %r15d, %ecx
jae 0xdd4b8
cmpl %r9d, %r15d
movl 0x44(%rsp), %esi
jg 0xdd8e8
cmpl %eax, %r15d
jle 0xdd3d5
leal -0x1(%r15), %ecx
movq 0x30(%rsp), %rdx
subl %eax, %edx
addl %r15d, %edx
incl %edx
movq %rdx, 0x30(%rsp)
movl %esi, 0x1f0(%rsp)
movl %ecx, 0x60(%rsp)
movl $0x1, %ebp
movl $0x0, 0x40(%rsp)
movl %ebp, %ebp
movq %rbp, %r13
cmpq $0x63, %rbp
jb 0xdd525
movl $0x3ec, %edi            # imm = 0x3EC
callq 0x97178
leaq -0x1(%r13), %rbp
movl 0x1ec(%rsp,%r13,4), %edx
movslq %edx, %rsi
movl 0x5c(%rsp,%r13,4), %ecx
movl %ecx, %eax
subl %esi, %eax
cmpl $0x9, %eax
movq %rbp, 0x58(%rsp)
jg 0xdd641
cmpl %edx, %ecx
je 0xdd62d
movq %r13, 0x10(%rsp)
movslq %ecx, %rbp
cmpl $0x4, %eax
setl %dil
leal -0x4(%rcx), %eax
cmpl %edx, %eax
setl %r8b
orb %dil, %r8b
jne 0xdd5c5
movslq %eax, %r9
leaq -0x4(%rbp), %r8
movq %rbp, %rax
movslq (%r14,%r9,4), %r11
cmpq %r8, %r9
jle 0xdd588
movl %r9d, %edi
jmp 0xdd5af
movl (%rbx,%r11,4), %r12d
movl %r9d, %edi
movq %rax, %r10
movl (%r14,%r10,4), %r13d
cmpl (%rbx,%r13,4), %r12d
jbe 0xdd5af
movslq %edi, %rdi
movl %r13d, (%r14,%rdi,4)
addq $0x4, %r10
addl $0x4, %edi
cmpq %rbp, %r10
jle 0xdd592
movslq %edi, %rdi
movl %r11d, (%r14,%rdi,4)
leaq -0x1(%r9), %rdi
decq %rax
cmpq %rsi, %r9
movq %rdi, %r9
jg 0xdd57a
cmpl %edx, %ecx
movq 0x10(%rsp), %r13
jle 0xdd62d
leal 0x1(%rcx), %edx
negl %ecx
leaq (%r14,%rbp,4), %r8
movl $0x1, %r9d
movq %rbp, %rdi
movslq -0x4(%r14,%rdi,4), %r11
movl %edi, %r10d
cmpq %rbp, %rdi
jg 0xdd613
movl (%rbx,%r11,4), %eax
xorl %r10d, %r10d
movl (%r8,%r10,4), %r12d
cmpl (%rbx,%r12,4), %eax
jbe 0xdd610
movl %r12d, -0x4(%r8,%r10,4)
incq %r10
cmpl %r10d, %r9d
jne 0xdd5f4
movl %edx, %r10d
jmp 0xdd613
subl %ecx, %r10d
decq %rdi
movslq %r10d, %rax
movl %r11d, -0x4(%r14,%rax,4)
incq %rcx
incq %r9
addq $-0x4, %r8
cmpq %rsi, %rdi
jg 0xdd5e0
cmpq $0x1, %r13
movq 0x58(%rsp), %rbp
jg 0xdd512
jmp 0xdd896
movl 0x40(%rsp), %edi
imull $0x1dc5, %edi, %edi     # imm = 0x1DC5
incl %edi
andl $0x7fff, %edi           # imm = 0x7FFF
imull $0x5556, %edi, %eax     # imm = 0x5556
shrl $0x10, %eax
leal (%rax,%rax,2), %eax
movl %edi, 0x40(%rsp)
subl %eax, %edi
movl %edx, %eax
testw %di, %di
je 0xdd67d
movzwl %di, %eax
cmpl $0x1, %eax
jne 0xdd67b
leal (%rcx,%rdx), %eax
sarl %eax
jmp 0xdd67d
movl %ecx, %eax
cltq
movl (%r14,%rax,4), %eax
movl (%rbx,%rax,4), %edi
movl %ecx, %eax
movq %rax, 0x10(%rsp)
movl %edx, %r12d
movl %ecx, %r11d
movl %edx, %r9d
cmpl %r11d, %r9d
jg 0xdd702
movslq %r11d, %r8
movslq %r12d, %r12
movl %r11d, 0xc(%rsp)
movslq %r9d, %rax
decq %rax
movl %r9d, %r10d
movl 0x4(%r14,%rax,4), %r11d
cmpl %edi, (%rbx,%r11,4)
je 0xdd6c9
jg 0xdd6ec
incl %r10d
incq %rax
cmpq %r8, %rax
jl 0xdd6af
jmp 0xdd6f3
movl (%r14,%r12,4), %r9d
movl %r9d, 0x4(%r14,%rax,4)
movl %r11d, (%r14,%r12,4)
incq %r12
leal 0x1(%r10), %r9d
movl 0xc(%rsp), %r11d
cmpl %r10d, %r11d
jg 0xdd6a6
incl %r10d
jmp 0xdd705
movl 0xc(%rsp), %r11d
jmp 0xdd705
movl 0xc(%rsp), %r11d
cmpl %r11d, %r9d
cmovlel %r11d, %r9d
incl %r9d
movl %r9d, %r10d
movslq %r10d, %r9
cmpl %r11d, %r10d
jg 0xdd7a2
movq %r12, 0x48(%rsp)
movq 0x10(%rsp), %rax
cltq
movq %rax, 0x10(%rsp)
movl %r11d, %r8d
movslq %r11d, %r11
leaq 0x1(%r11), %rax
movl -0x4(%r14,%rax,4), %r12d
cmpl %edi, (%rbx,%r12,4)
je 0xdd746
jl 0xdd773
decq %rax
decl %r8d
cmpq %r9, %rax
jg 0xdd72c
jmp 0xdd793
movq 0x10(%rsp), %r11
movl (%r14,%r11,4), %r11d
movl %r11d, -0x4(%r14,%rax,4)
movq 0x10(%rsp), %rax
movl %r12d, (%r14,%rax,4)
decq %rax
movq %rax, 0x10(%rsp)
leal -0x1(%r8), %r11d
cmpl %r8d, %r10d
jl 0xdd722
jmp 0xdd88b
movl (%r14,%r9,4), %r10d
movl %r12d, (%r14,%r9,4)
movl %r10d, -0x4(%r14,%rax,4)
incl %r9d
decl %r8d
movl %r8d, %r11d
movq 0x48(%rsp), %r12
jmp 0xdd696
cmpq %r9, %r11
cmovgeq %r9, %r11
decl %r11d
movq 0x48(%rsp), %r12
cmpl %r12d, 0x10(%rsp)
jl 0xdd881
movl %r11d, 0xc(%rsp)
movq %r12, %r8
movl %r8d, %eax
subl %edx, %eax
movl %r10d, %edi
subl %r8d, %edi
cmpl %edi, %eax
cmovll %eax, %edi
testl %edi, %edi
jle 0xdd7f9
movl %r10d, %eax
subl %edi, %eax
movslq %eax, %r8
leaq (%r14,%rsi,4), %rax
leaq (%r14,%r8,4), %rsi
incl %edi
xorl %r8d, %r8d
movl (%rax,%r8), %r11d
movl (%rsi,%r8), %ebp
movl %ebp, (%rax,%r8)
movl %r11d, (%rsi,%r8)
addq $0x4, %r8
decl %edi
cmpl $0x1, %edi
ja 0xdd7de
movl %ecx, %eax
movq 0x10(%rsp), %rsi
subl %esi, %eax
subl 0xc(%rsp), %esi
cmpl %esi, %eax
movq %rsi, %rbp
cmovgel %esi, %eax
testl %eax, %eax
jle 0xdd83b
movl %ecx, %esi
subl %eax, %esi
movslq %esi, %rsi
incl %eax
movq %r14, %rdi
movl (%rdi,%r9,4), %r8d
movl 0x4(%rdi,%rsi,4), %r11d
movl %r11d, (%rdi,%r9,4)
movl %r8d, 0x4(%rdi,%rsi,4)
addq $0x4, %rdi
decl %eax
cmpl $0x1, %eax
ja 0xdd81e
notl %r12d
leal (%rdx,%r12), %esi
addl %r10d, %esi
movl %ecx, %eax
subl %ebp, %eax
incl %eax
addl %r10d, %r12d
movl %ecx, %edi
subl %eax, %edi
cmpl %edi, %r12d
movq 0x58(%rsp), %r12
jle 0xdd863
movl %esi, 0x60(%rsp,%r12,4)
jmp 0xdd86f
movl %eax, 0x1f0(%rsp,%r12,4)
movl %edx, %eax
movl %esi, %ecx
movl %r13d, %edx
movl %eax, 0x1f0(%rsp,%rdx,4)
movl %ecx, 0x60(%rsp,%rdx,4)
leal 0x1(%r13), %ebp
testl %ebp, %ebp
jg 0xdd510
jmp 0xdd896
decl %r8d
movl %r8d, %r11d
jmp 0xdd79d
movl 0x44(%rsp), %ecx
movslq %ecx, %rax
leaq (%r14,%rax,4), %rax
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movq 0x18(%rsp), %r9
movq 0x28(%rsp), %rdi
movl 0x24(%rsp), %edx
movl (%rax), %esi
movl (%rbx,%rsi,4), %r8d
cmpl %r8d, %r10d
je 0xdd8d8
movl $0x1, %esi
shll %cl, %esi
movl %ecx, %r10d
sarl $0x5, %r10d
movslq %r10d, %r10
orl %esi, (%rdi,%r10,4)
movl %r8d, %r10d
incl %ecx
addq $0x4, %rax
cmpl %ecx, %r15d
jne 0xdd8b5
jmp 0xdd3d5
cmpl $0x4, 0x3c(%rsp)
jge 0xdd937
addl %edx, %edx
cmpl %r9d, %edx
movq 0x50(%rsp), %r15
jg 0xdd983
cmpl $0x0, 0x30(%rsp)
jne 0xdd382
jmp 0xdd983
movq 0x736ad(%rip), %rax     # 0x150fc0
movq (%rax), %rdi
leaq 0x2e5db(%rip), %rsi     # 0x10bef8
xorl %eax, %eax
callq 0xb8d0
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %r9
jmp 0xdd391
movq 0x73682(%rip), %rax     # 0x150fc0
movq (%rax), %rdi
leaq 0x2e5c7(%rip), %rsi     # 0x10bf0f
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0xb8d0
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %r9
addl %edx, %edx
cmpl %r9d, %edx
movq 0x50(%rsp), %r15
jg 0xdd979
cmpl $0x0, 0x30(%rsp)
jne 0xdd382
callq 0x33c8a
movq 0x18(%rsp), %r9
testl %r9d, %r9d
jle 0xdd9c1
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rcx
decq %rcx
movl 0x794(%rsp,%rcx,4), %edx
incq %rcx
testl %edx, %edx
je 0xdd992
decl %edx
movl %edx, 0x790(%rsp,%rcx,4)
movl (%r14,%rax,4), %edx
movb %cl, (%rbx,%rdx)
incq %rax
cmpq %r15, %rax
jne 0xdd98c
cmpq $0x100, %rcx            # imm = 0x100
jge 0xdd9d3
addq $0xb98, %rsp            # imm = 0xB98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x3ed, %edi            # imm = 0x3ED
addq $0xb98, %rsp            # imm = 0xB98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x97178
callq 0x33c6e
movq 0x18(%rsp), %rcx
jmp 0xdd247