// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x868, %rsp            # imm = 0x868
movq %rdi, 0x860(%rsp)
movq %rsi, 0x858(%rsp)
movq %rdx, 0x850(%rsp)
movl %ecx, 0x84c(%rsp)
movl %r8d, 0x848(%rsp)
movq 0x858(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x4, 0x848(%rsp)
jl 0x1529bd
movq 0x6162c(%rip), %rax     # 0x1b3fd8
movq (%rax), %rdi
leaq 0x3c3b7(%rip), %rsi     # 0x18ed6d
movb $0x0, %al
callq 0xb890
movl $0x0, 0x38(%rsp)
cmpl $0x101, 0x38(%rsp)      # imm = 0x101
jge 0x1529ec
movslq 0x38(%rsp), %rax
movl $0x0, 0x440(%rsp,%rax,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1529c5
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x84c(%rsp), %eax
jge 0x152a2d
movq 0x10(%rsp), %rax
movslq 0x38(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movl 0x440(%rsp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, 0x440(%rsp,%rax,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1529f4
movl $0x0, 0x38(%rsp)
cmpl $0x100, 0x38(%rsp)      # imm = 0x100
jge 0x152a61
movslq 0x38(%rsp), %rax
movl 0x440(%rsp,%rax,4), %ecx
movslq 0x38(%rsp), %rax
movl %ecx, 0x40(%rsp,%rax,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152a35
movl $0x1, 0x38(%rsp)
cmpl $0x101, 0x38(%rsp)      # imm = 0x101
jge 0x152aa3
movl 0x38(%rsp), %eax
subl $0x1, %eax
cltq
movl 0x440(%rsp,%rax,4), %ecx
movslq 0x38(%rsp), %rax
addl 0x440(%rsp,%rax,4), %ecx
movl %ecx, 0x440(%rsp,%rax,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152a69
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x84c(%rsp), %eax
jge 0x152b0e
movq 0x10(%rsp), %rax
movslq 0x38(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, 0x34(%rsp)
movslq 0x34(%rsp), %rax
movl 0x440(%rsp,%rax,4), %eax
subl $0x1, %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %ecx
movslq 0x34(%rsp), %rax
movl %ecx, 0x440(%rsp,%rax,4)
movl 0x38(%rsp), %edx
movq 0x860(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152aab
movl 0x84c(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
addl $0x2, %eax
movl %eax, 0x18(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x18(%rsp), %eax
jge 0x152b57
movq 0x850(%rsp), %rax
movslq 0x38(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152b2c
movl $0x0, 0x38(%rsp)
cmpl $0x100, 0x38(%rsp)      # imm = 0x100
jge 0x152bac
movslq 0x38(%rsp), %rax
movl 0x440(%rsp,%rax,4), %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movq 0x850(%rsp), %rax
movslq 0x38(%rsp), %rcx
movl 0x440(%rsp,%rcx,4), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152b5f
movl $0x0, 0x38(%rsp)
cmpl $0x20, 0x38(%rsp)
jge 0x152c50
movl 0x84c(%rsp), %ecx
movl 0x38(%rsp), %eax
shll %eax
addl %eax, %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movq 0x850(%rsp), %rax
movl 0x84c(%rsp), %ecx
movl 0x38(%rsp), %esi
shll %esi
addl %esi, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x84c(%rsp), %ecx
movl 0x38(%rsp), %eax
shll %eax
addl %eax, %ecx
addl $0x1, %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
xorl $-0x1, %edx
movq 0x850(%rsp), %rax
movl 0x84c(%rsp), %ecx
movl 0x38(%rsp), %esi
shll %esi
addl %esi, %ecx
addl $0x1, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
andl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152bb4
movl $0x1, 0x3c(%rsp)
cmpl $0x4, 0x848(%rsp)
jl 0x152c7e
movq 0x6136f(%rip), %rax     # 0x1b3fd8
movq (%rax), %rdi
movl 0x3c(%rsp), %edx
leaq 0x3c112(%rip), %rsi     # 0x18ed89
movb $0x0, %al
callq 0xb890
movl $0x0, 0x34(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x84c(%rsp), %eax
jge 0x152d25
movq 0x850(%rsp), %rax
movl 0x38(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl 0x38(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x152cd3
movl 0x38(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x860(%rsp), %rax
movslq 0x38(%rsp), %rcx
movl (%rax,%rcx,4), %eax
subl 0x3c(%rsp), %eax
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x30(%rsp)
jge 0x152d01
movl 0x84c(%rsp), %eax
addl 0x30(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x34(%rsp), %edx
movq 0x858(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152c8e
movl $0x0, 0x1c(%rsp)
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x8(%rsp)
movl 0x30(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %eax
shll %cl, %eax
movl 0x8(%rsp), %ecx
andl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xf(%rsp)
je 0x152d89
movl 0x30(%rsp), %eax
andl $0x1f, %eax
cmpl $0x0, %eax
setne %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x152d93
jmp 0x152da0
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x152d40
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl 0x30(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x152e30
jmp 0x152dce
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x152df3
movl 0x30(%rsp), %eax
addl $0x20, %eax
movl %eax, 0x30(%rsp)
jmp 0x152dce
jmp 0x152df5
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl 0x30(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x152e2e
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x152df5
jmp 0x152e30
movl 0x30(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x84c(%rsp), %eax
jl 0x152e4d
jmp 0x153028
jmp 0x152e4f
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, (%rsp)
movl 0x30(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %eax
shll %cl, %eax
movl (%rsp), %ecx
andl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x7(%rsp)
jne 0x152e96
movl 0x30(%rsp), %eax
andl $0x1f, %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x152ea0
jmp 0x152ead
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x152e4f
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl 0x30(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x152f46
jmp 0x152edb
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x152f00
movl 0x30(%rsp), %eax
addl $0x20, %eax
movl %eax, 0x30(%rsp)
jmp 0x152edb
jmp 0x152f02
movq 0x850(%rsp), %rax
movl 0x30(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl 0x30(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x152f37
jmp 0x152f44
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x152f02
jmp 0x152f46
movl 0x30(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x84c(%rsp), %eax
jl 0x152f63
jmp 0x153028
movl 0x28(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jle 0x153023
movl 0x28(%rsp), %eax
subl 0x2c(%rsp), %eax
addl $0x1, %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x860(%rsp), %rdi
movq 0x858(%rsp), %rsi
movl 0x2c(%rsp), %edx
movl 0x28(%rsp), %ecx
callq 0x154040
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
movl 0x2c(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x28(%rsp), %eax
jg 0x153021
movq 0x858(%rsp), %rax
movq 0x860(%rsp), %rcx
movslq 0x38(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x20(%rsp), %eax
je 0x153012
movl 0x38(%rsp), %ecx
andl $0x1f, %ecx
movl $0x1, %edx
shll %cl, %edx
movq 0x850(%rsp), %rax
movl 0x38(%rsp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x20(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x153014
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x152fb1
jmp 0x153023
jmp 0x152d35
cmpl $0x4, 0x848(%rsp)
jl 0x15304e
movq 0x60f9f(%rip), %rax     # 0x1b3fd8
movq (%rax), %rdi
movl 0x1c(%rsp), %edx
leaq 0x3bd59(%rip), %rsi     # 0x18eda0
movb $0x0, %al
callq 0xb890
movl 0x3c(%rsp), %eax
shll %eax
movl %eax, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x84c(%rsp), %eax
jg 0x15306c
cmpl $0x0, 0x1c(%rsp)
jne 0x15306e
jmp 0x153073
jmp 0x152c58
cmpl $0x4, 0x848(%rsp)
jl 0x153095
movq 0x60f54(%rip), %rax     # 0x1b3fd8
movq (%rax), %rdi
leaq 0x3bd2a(%rip), %rsi     # 0x18edb8
movb $0x0, %al
callq 0xb890
movl $0x0, 0x34(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x84c(%rsp), %eax
jge 0x153108
jmp 0x1530b4
movslq 0x34(%rsp), %rax
cmpl $0x0, 0x40(%rsp,%rax,4)
jne 0x1530cd
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x1530b4
movslq 0x34(%rsp), %rax
movl 0x40(%rsp,%rax,4), %ecx
addl $-0x1, %ecx
movl %ecx, 0x40(%rsp,%rax,4)
movl 0x34(%rsp), %eax
movb %al, %dl
movq 0x10(%rsp), %rax
movq 0x860(%rsp), %rcx
movslq 0x38(%rsp), %rsi
movl (%rcx,%rsi,4), %ecx
movb %dl, (%rax,%rcx)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1530a5
cmpl $0x100, 0x34(%rsp)      # imm = 0x100
jl 0x15311c
movl $0x3ed, %edi            # imm = 0x3ED
callq 0xc7b30
addq $0x868, %rsp            # imm = 0x868
retq
nopw %cs:(%rax,%rax)