// File: /workspace/github_c_makefile_star2_O1/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
movl %r8d, %ebp
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x4, %r8d
movq %rcx, 0x10(%rsp)
jge 0xdd2ff
movl %ecx, %r15d
leaq 0x380(%rsp), %rdi
movl $0x404, %edx            # imm = 0x404
xorl %esi, %esi
movq %rcx, %r12
callq 0xb2f0
testl %r12d, %r12d
jle 0xdcb94
xorl %eax, %eax
movzbl (%rbx,%rax), %ecx
incl 0x380(%rsp,%rcx,4)
incq %rax
cmpq %rax, %r15
jne 0xdcb81
leaq 0x790(%rsp), %rdi
leaq 0x380(%rsp), %r13
movl $0x400, %edx            # imm = 0x400
movq %r13, %rsi
callq 0xb520
movl $0x1, %eax
movl (%r13), %ecx
addl 0x380(%rsp,%rax,4), %ecx
movl %ecx, 0x380(%rsp,%rax,4)
incq %rax
cmpq $0x101, %rax            # imm = 0x101
jne 0xdcbba
movq 0x10(%rsp), %r8
testl %r8d, %r8d
movq 0x18(%rsp), %rdi
jle 0xdcc08
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 0xdcbe4
cmpl $-0x3f, %r8d
jl 0xdcc3f
leal 0x1f(%r8), %eax
testl %r8d, %r8d
cmovnsl %r8d, %eax
sarl $0x5, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovnsl %eax, %ecx
incl %ecx
leaq 0x4(,%rcx,4), %rdx
xorl %esi, %esi
callq 0xb2f0
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
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 0xdcc41
leal 0x1(%r8), %eax
xorl %edx, %edx
leal (%r8,%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 0xdcc69
movl $0x1, 0xc(%rsp)
movq %r15, 0x50(%rsp)
movl %ebp, 0x40(%rsp)
cmpl $0x4, %ebp
jge 0xdd23a
testl %r8d, %r8d
movl 0xc(%rsp), %r9d
jle 0xdcced
xorl %eax, %eax
xorl %ecx, %ecx
movl %eax, %edx
shrl $0x5, %edx
movl (%rdi,%rdx,4), %edx
btl %eax, %edx
cmovbl %eax, %ecx
movl (%r14,%rax,4), %edx
subl %r9d, %edx
movl %edx, %esi
sarl $0x1f, %esi
andl %r15d, %esi
addl %edx, %esi
movslq %esi, %rdx
movl %ecx, (%rbx,%rdx,4)
incq %rax
cmpq %rax, %r15
jne 0xdccc0
xorl %r15d, %r15d
xorl %edx, %edx
leal -0x20(%r15), %ecx
leal -0x1(%r15), %r9d
movl %ecx, %eax
movl %r9d, %r10d
movl %r15d, %ecx
sarl $0x5, %ecx
movslq %ecx, %r9
movl %r15d, %ecx
andl $0x1f, %ecx
movl $0x1, %esi
shll %cl, %esi
andl (%rdi,%r9,4), %esi
incl %r15d
testl %ecx, %ecx
je 0xdcd2b
leal 0x1(%rax), %ecx
leal 0x1(%r10), %r9d
testl %esi, %esi
jne 0xdccfa
testl %esi, %esi
je 0xdcd5a
movl %r10d, %ebp
addl $0x20, %eax
movl %eax, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
leal 0x20(%rbp), %r10d
cmpl $-0x1, (%rdi,%rcx,4)
je 0xdcd2f
incl %ebp
movl %ebp, %eax
sarl $0x5, %eax
cltq
movl (%rdi,%rax,4), %eax
btl %ebp, %eax
jb 0xdcd47
jmp 0xdcd60
decl %r15d
movl %r15d, %ebp
cmpl %r8d, %ebp
jg 0xdd213
leal -0x1(%rbp), %r11d
leal -0x20(%rbp), %ecx
movl %r11d, %r9d
movl %ebp, %r15d
movl %ecx, %eax
movl %r9d, %r10d
movl %r15d, %ecx
sarl $0x5, %ecx
movslq %ecx, %r9
movl %r15d, %ecx
andl $0x1f, %ecx
movl $0x1, %esi
shll %cl, %esi
andl (%rdi,%r9,4), %esi
incl %r15d
testl %ecx, %ecx
je 0xdcda7
leal 0x1(%rax), %ecx
leal 0x1(%r10), %r9d
testl %esi, %esi
je 0xdcd76
testl %esi, %esi
je 0xdcdb0
decl %r15d
jmp 0xdcddc
movl %r10d, %r15d
addl $0x20, %eax
movl %eax, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
leal 0x20(%r15), %r10d
cmpl $0x0, (%rdi,%rcx,4)
je 0xdcdb0
incl %r15d
movl %r15d, %eax
sarl $0x5, %eax
cltq
movl (%rdi,%rax,4), %eax
btl %r15d, %eax
jae 0xdcdc8
cmpl %r8d, %r15d
jg 0xdd213
cmpl %ebp, %r15d
jle 0xdccf2
leal -0x1(%r15), %eax
subl %ebp, %edx
addl %r15d, %edx
incl %edx
movq %rdx, 0x58(%rsp)
movl %r11d, 0x44(%rsp)
movl %r11d, 0x1f0(%rsp)
movl %eax, 0x60(%rsp)
movl $0x1, %r13d
movq $0x0, 0x48(%rsp)
movl %r13d, %r13d
cmpq $0x63, %r13
jl 0xdce31
movl $0x3ec, %edi            # imm = 0x3EC
callq 0x97c40
leaq -0x1(%r13), %r8
movl 0x1ec(%rsp,%r13,4), %r9d
movslq %r9d, %rsi
movl 0x5c(%rsp,%r13,4), %ecx
movl %ecx, %eax
subl %esi, %eax
cmpl $0x9, %eax
movq %r13, 0x38(%rsp)
movq %r8, 0x28(%rsp)
jg 0xdcf5b
cmpl %r9d, %ecx
je 0xdcf45
movslq %ecx, %rdx
cmpl $0x4, %eax
setl %dil
leal -0x4(%rcx), %eax
movq %r9, 0x30(%rsp)
cmpl %r9d, %eax
setl %r8b
orb %dil, %r8b
jne 0xdcee0
movslq %eax, %r9
leaq -0x4(%rdx), %r8
movq %rdx, %r13
movslq (%r14,%r9,4), %r11
movq %r9, %rdi
cmpq %r8, %r9
jg 0xdceca
movl (%rbx,%r11,4), %r12d
movq %r13, %rax
movq %r9, %rdi
movq %rax, %r10
movl (%r14,%rax,4), %eax
cmpl (%rbx,%rax,4), %r12d
jbe 0xdceca
movslq %edi, %rdi
movl %eax, (%r14,%rdi,4)
leaq 0x4(%r10), %rax
movq %r10, %rdi
cmpq %rdx, %rax
jle 0xdcea3
addq $-0x4, %rax
movq %rax, %rdi
movslq %edi, %rax
movl %r11d, (%r14,%rax,4)
leaq -0x1(%r9), %rax
decq %r13
cmpq %rsi, %r9
movq %rax, %r9
jg 0xdce8d
cmpl 0x30(%rsp), %ecx
jle 0xdcf45
leal 0x1(%rcx), %eax
negl %ecx
leaq (%r14,%rdx,4), %r8
movl $0x1, %r9d
movq %rdx, %rdi
movslq -0x4(%r14,%rdi,4), %r11
movl %edi, %r10d
cmpq %rdx, %rdi
jg 0xdcf2b
movl (%rbx,%r11,4), %r12d
xorl %r10d, %r10d
movl (%r8,%r10,4), %r13d
cmpl (%rbx,%r13,4), %r12d
jbe 0xdcf28
movl %r13d, -0x4(%r8,%r10,4)
incq %r10
cmpl %r10d, %r9d
jne 0xdcf0c
movl %eax, %r10d
jmp 0xdcf2b
subl %ecx, %r10d
decq %rdi
movslq %r10d, %r10
movl %r11d, -0x4(%r14,%r10,4)
incq %rcx
incq %r9
addq $-0x4, %r8
cmpq %rsi, %rdi
jg 0xdcef8
cmpq $0x1, 0x38(%rsp)
movq 0x28(%rsp), %r13
jg 0xdce21
jmp 0xdd1b7
movq 0x48(%rsp), %rdx
imull $0x1dc5, %edx, %edx     # imm = 0x1DC5
incl %edx
andl $0x7fff, %edx           # imm = 0x7FFF
imulq $0x55555556, %rdx, %rax # imm = 0x55555556
shrq $0x20, %rax
leal (%rax,%rax,2), %edi
movq %rdx, 0x48(%rsp)
movl %r9d, %eax
subl %edi, %edx
je 0xdcf97
cmpl $0x1, %edx
jne 0xdcf95
leal (%rcx,%r9), %eax
sarl %eax
jmp 0xdcf97
movl %ecx, %eax
cltq
movl (%r14,%rax,4), %eax
movl (%rbx,%rax,4), %edi
movl %ecx, %r11d
movl %r9d, %r12d
movl %ecx, %edx
movq %r9, 0x30(%rsp)
cmpl %edx, %r9d
jg 0xdd010
movslq %edx, %r8
movslq %r12d, %r12
movl %edx, %r13d
movslq %r9d, %rax
decq %rax
movl %r9d, %r10d
movl 0x4(%r14,%rax,4), %edx
cmpl %edi, (%rbx,%rdx,4)
je 0xdcfdd
jg 0xdcffe
incl %r10d
incq %rax
cmpq %r8, %rax
jl 0xdcfc4
jmp 0xdd003
movl (%r14,%r12,4), %r9d
movl %r9d, 0x4(%r14,%rax,4)
movl %edx, (%r14,%r12,4)
incq %r12
leal 0x1(%r10), %r9d
movl %r13d, %edx
cmpl %r10d, %r13d
jg 0xdcfb8
incl %r10d
jmp 0xdd013
movl %r13d, %edx
jmp 0xdd013
movl %r13d, %edx
cmpl %r13d, %r9d
cmovlel %r13d, %r9d
incl %r9d
movl %r9d, %r10d
movslq %r10d, %r9
cmpl %edx, %r10d
jg 0xdd0a7
movq %r12, 0x20(%rsp)
movslq %r11d, %r11
movq %r11, %r13
movslq %edx, %r11
leaq 0x1(%r11), %rax
movl %edx, %r8d
movl -0x4(%r14,%rax,4), %r12d
cmpl %edi, (%rbx,%r12,4)
je 0xdd04e
jl 0xdd06f
decq %rax
decl %r8d
cmpq %r9, %rax
jg 0xdd034
jmp 0xdd092
movq %r13, %r11
movl (%r14,%r13,4), %edx
movl %edx, -0x4(%r14,%rax,4)
movl %r12d, (%r14,%r13,4)
decq %r11
leal -0x1(%r8), %edx
cmpl %r8d, %r10d
jl 0xdd027
jmp 0xdd1a7
movl (%r14,%r9,4), %edx
movl %r12d, (%r14,%r9,4)
movl %edx, -0x4(%r14,%rax,4)
incl %r9d
decl %r8d
movl %r8d, %edx
movq 0x20(%rsp), %r12
movq %r13, %r11
jmp 0xdcfad
cmpq %r9, %r11
cmovgeq %r9, %r11
decl %r11d
movl %r11d, %edx
movq 0x20(%rsp), %r12
movq %r13, %r11
cmpl %r12d, %r11d
jl 0xdd197
movl %edx, 0x20(%rsp)
movq %r11, %r13
movl %r12d, %eax
subl 0x30(%rsp), %eax
movl %r10d, %edi
subl %r12d, %edi
cmpl %edi, %eax
cmovll %eax, %edi
testl %edi, %edi
jle 0xdd0fd
movl %r10d, %eax
subl %edi, %eax
movslq %eax, %rdx
leaq (%r14,%rsi,4), %rax
leaq (%r14,%rdx,4), %rsi
incl %edi
xorl %r8d, %r8d
movl (%rax,%r8), %edx
movl (%rsi,%r8), %r11d
movl %r11d, (%rax,%r8)
movl %edx, (%rsi,%r8)
addq $0x4, %r8
decl %edi
cmpl $0x1, %edi
jg 0xdd0e2
movl %ecx, %eax
movq %r13, %r11
subl %r11d, %eax
subl 0x20(%rsp), %r11d
cmpl %r11d, %eax
cmovgel %r11d, %eax
testl %eax, %eax
jle 0xdd13d
movl %ecx, %edx
subl %eax, %edx
movslq %edx, %rsi
incl %eax
movq %r14, %rdi
movl (%rdi,%r9,4), %edx
movl 0x4(%rdi,%rsi,4), %r8d
movl %r8d, (%rdi,%r9,4)
movl %edx, 0x4(%rdi,%rsi,4)
addq $0x4, %rdi
decl %eax
cmpl $0x1, %eax
jg 0xdd121
notl %r12d
movq 0x30(%rsp), %r13
leal (%r12,%r13), %esi
addl %r10d, %esi
movl %ecx, %eax
subl %r11d, %eax
incl %eax
addl %r10d, %r12d
movl %ecx, %edx
subl %eax, %edx
cmpl %edx, %r12d
jle 0xdd16a
movq 0x28(%rsp), %rdx
movl %esi, 0x60(%rsp,%rdx,4)
jmp 0xdd17b
movq 0x28(%rsp), %rcx
movl %eax, 0x1f0(%rsp,%rcx,4)
movl %r13d, %eax
movl %esi, %ecx
movq 0x38(%rsp), %r13
movl %r13d, %edx
movl %eax, 0x1f0(%rsp,%rdx,4)
movl %ecx, 0x60(%rsp,%rdx,4)
leal 0x1(%r13), %eax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %r13
testl %r13d, %r13d
jg 0xdce1e
jmp 0xdd1b7
decl %r8d
movl %r8d, %edx
movq 0x20(%rsp), %r12
jmp 0xdd0a7
cmpl %r15d, %ebp
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rdi
movq 0x58(%rsp), %rdx
movl 0x44(%rsp), %ecx
jg 0xdccf2
movslq %ecx, %rax
leaq (%r14,%rax,4), %rax
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl (%rax), %esi
movl (%rbx,%rsi,4), %r9d
cmpl %r9d, %r10d
je 0xdd203
movl $0x1, %esi
shll %cl, %esi
movl %ecx, %r10d
sarl $0x5, %r10d
movslq %r10d, %r10
orl %esi, (%rdi,%r10,4)
movl %r9d, %r10d
incl %ecx
addq $0x4, %rax
cmpl %ecx, %r15d
jne 0xdd1e0
jmp 0xdccf2
movl 0x40(%rsp), %ebp
cmpl $0x4, %ebp
jge 0xdd265
movl 0xc(%rsp), %eax
addl %eax, %eax
movl %eax, 0xc(%rsp)
cmpl %r8d, %eax
movq 0x50(%rsp), %r15
jg 0xdd28f
testl %edx, %edx
jne 0xdcca9
jmp 0xdd28f
movq 0x73d7f(%rip), %rax     # 0x150fc0
movq (%rax), %rdi
leaq 0x2ee8d(%rip), %rsi     # 0x10c0d8
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0xb8d0
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
jmp 0xdccb2
movq 0x73d54(%rip), %rax     # 0x150fc0
movq (%rax), %rdi
leaq 0x2ee79(%rip), %rsi     # 0x10c0ef
xorl %eax, %eax
movq %rdx, %r15
callq 0xb8d0
movq %r15, %rdx
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
jmp 0xdd21c
cmpl $0x4, %ebp
jge 0xdd30e
testl %r8d, %r8d
jle 0xdd2d2
xorl %eax, %eax
xorl %ecx, %ecx
movslq %ecx, %rcx
decq %rcx
movl 0x794(%rsp,%rcx,4), %edx
incq %rcx
testl %edx, %edx
je 0xdd2a3
decl %edx
movl %edx, 0x790(%rsp,%rcx,4)
movl (%r14,%rax,4), %edx
movb %cl, (%rbx,%rdx)
incq %rax
cmpq %r15, %rax
jne 0xdd29d
cmpq $0x100, %rcx            # imm = 0x100
jge 0xdd2e4
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 0x97c40
callq 0x342d0
movq 0x10(%rsp), %rcx
jmp 0xdcb60
callq 0x342ec
movq 0x10(%rsp), %r8
jmp 0xdd294