// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/bzip2-1.0.6/huffman.c
// Function: BZ2_hbMakeCodeLengths
void BZ2_hbMakeCodeLengths ( UChar *len, 
                             Int32 *freq,
                             Int32 alphaSize,
                             Int32 maxLen )
{
   /*--
      Nodes and heap entries run from 1.  Entry 0
      for both the heap and nodes is a sentinel.
   --*/
   Int32 nNodes, nHeap, n1, n2, i, j, k;
   Bool  tooLong;

   Int32 heap   [ BZ_MAX_ALPHA_SIZE + 2 ];
   Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
   Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; 

   for (i = 0; i < alphaSize; i++)
      weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;

   while (True) {

      nNodes = alphaSize;
      nHeap = 0;

      heap[0] = 0;
      weight[0] = 0;
      parent[0] = -2;

      for (i = 1; i <= alphaSize; i++) {
         parent[i] = -1;
         nHeap++;
         heap[nHeap] = i;
         UPHEAP(nHeap);
      }

      AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
   
      while (nHeap > 1) {
         n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
         n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
         nNodes++;
         parent[n1] = parent[n2] = nNodes;
         weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
         parent[nNodes] = -1;
         nHeap++;
         heap[nHeap] = nNodes;
         UPHEAP(nHeap);
      }

      AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );

      tooLong = False;
      for (i = 1; i <= alphaSize; i++) {
         j = 0;
         k = i;
         while (parent[k] >= 0) { k = parent[k]; j++; }
         len[i-1] = j;
         if (j > maxLen) tooLong = True;
      }
      
      if (! tooLong) break;

      /* 17 Oct 04: keep-going condition for the following loop used
         to be 'i < alphaSize', which missed the last element,
         theoretically leading to the possibility of the compressor
         looping.  However, this count-scaling step is only needed if
         one of the generated Huffman code words is longer than
         maxLen, which up to and including version 1.0.2 was 20 bits,
         which is extremely unlikely.  In version 1.0.3 maxLen was
         changed to 17 bits, which has minimal effect on compression
         ratio, but does mean this scaling step is used from time to
         time, enough to verify that it works.

         This means that bzip2-1.0.3 and later will only produce
         Huffman codes with a maximum length of 17 bits.  However, in
         order to preserve backwards compatibility with bitstreams
         produced by versions pre-1.0.3, the decompressor must still
         handle lengths of up to 20. */

      for (i = 1; i <= alphaSize; i++) {
         j = weight[i] >> 8;
         j = 1 + (j / 2);
         weight[i] = j << 8;
      }
   }
}

// Assembly:
subq $0x14a8, %rsp           # imm = 0x14A8
movq %rdi, 0x14a0(%rsp)
movq %rsi, 0x1498(%rsp)
movl %edx, 0x1494(%rsp)
movl %ecx, 0x1490(%rsp)
movl $0x0, 0x147c(%rsp)
movl 0x147c(%rsp), %eax
cmpl 0x1494(%rsp), %eax
jge 0x156255
movq 0x1498(%rsp), %rax
movslq 0x147c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x156211
movl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x156228
movq 0x1498(%rsp), %rax
movslq 0x147c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %ecx
shll $0x8, %ecx
movl 0x147c(%rsp), %eax
addl $0x1, %eax
cltq
movl %ecx, 0x850(%rsp,%rax,4)
movl 0x147c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x147c(%rsp)
jmp 0x1561e0
jmp 0x156257
movl 0x1494(%rsp), %eax
movl %eax, 0x148c(%rsp)
movl $0x0, 0x1488(%rsp)
movl $0x0, 0x1060(%rsp)
movl $0x0, 0x850(%rsp)
movl $0xfffffffe, 0x40(%rsp) # imm = 0xFFFFFFFE
movl $0x1, 0x147c(%rsp)
movl 0x147c(%rsp), %eax
cmpl 0x1494(%rsp), %eax
jg 0x156372
movslq 0x147c(%rsp), %rax
movl $0xffffffff, 0x40(%rsp,%rax,4) # imm = 0xFFFFFFFF
movl 0x1488(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1488(%rsp)
movl 0x147c(%rsp), %ecx
movslq 0x1488(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x1488(%rsp), %eax
movl %eax, 0x3c(%rsp)
movslq 0x3c(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %eax
movl %eax, 0x38(%rsp)
movslq 0x38(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
movl 0x3c(%rsp), %ecx
sarl %ecx
movslq %ecx, %rcx
movslq 0x1060(%rsp,%rcx,4), %rcx
cmpl 0x850(%rsp,%rcx,4), %eax
jge 0x15634c
movl 0x3c(%rsp), %eax
sarl %eax
cltq
movl 0x1060(%rsp,%rax,4), %ecx
movslq 0x3c(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x3c(%rsp), %eax
sarl %eax
movl %eax, 0x3c(%rsp)
jmp 0x1562ff
movl 0x38(%rsp), %ecx
movslq 0x3c(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x147c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x147c(%rsp)
jmp 0x156299
cmpl $0x104, 0x1488(%rsp) # imm = 0x104
jl 0x156389
movl $0x7d1, %edi            # imm = 0x7D1
callq 0xc7b30
jmp 0x15638b
cmpl $0x1, 0x1488(%rsp)
jle 0x156737
movl 0x1064(%rsp), %eax
movl %eax, 0x1484(%rsp)
movslq 0x1488(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %eax
movl %eax, 0x1064(%rsp)
movl 0x1488(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1488(%rsp)
movl $0x1, 0x34(%rsp)
movslq 0x34(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %eax
movl %eax, 0x2c(%rsp)
movl 0x34(%rsp), %eax
shll %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x1488(%rsp), %eax
jle 0x156402
jmp 0x156491
movl 0x30(%rsp), %eax
cmpl 0x1488(%rsp), %eax
jge 0x156448
movl 0x30(%rsp), %eax
addl $0x1, %eax
cltq
movslq 0x1060(%rsp,%rax,4), %rax
movl 0x850(%rsp,%rax,4), %eax
movslq 0x30(%rsp), %rcx
movslq 0x1060(%rsp,%rcx,4), %rcx
cmpl 0x850(%rsp,%rcx,4), %eax
jge 0x156448
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
movslq 0x2c(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
movslq 0x30(%rsp), %rcx
movslq 0x1060(%rsp,%rcx,4), %rcx
cmpl 0x850(%rsp,%rcx,4), %eax
jge 0x15646c
jmp 0x156491
movslq 0x30(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %ecx
movslq 0x34(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x30(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x1563e6
movl 0x2c(%rsp), %ecx
movslq 0x34(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x1064(%rsp), %eax
movl %eax, 0x1480(%rsp)
movslq 0x1488(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %eax
movl %eax, 0x1064(%rsp)
movl 0x1488(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1488(%rsp)
movl $0x1, 0x28(%rsp)
movslq 0x28(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %eax
movl %eax, 0x20(%rsp)
movl 0x28(%rsp), %eax
shll %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x1488(%rsp), %eax
jle 0x15650a
jmp 0x156599
movl 0x24(%rsp), %eax
cmpl 0x1488(%rsp), %eax
jge 0x156550
movl 0x24(%rsp), %eax
addl $0x1, %eax
cltq
movslq 0x1060(%rsp,%rax,4), %rax
movl 0x850(%rsp,%rax,4), %eax
movslq 0x24(%rsp), %rcx
movslq 0x1060(%rsp,%rcx,4), %rcx
cmpl 0x850(%rsp,%rcx,4), %eax
jge 0x156550
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movslq 0x20(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
movslq 0x24(%rsp), %rcx
movslq 0x1060(%rsp,%rcx,4), %rcx
cmpl 0x850(%rsp,%rcx,4), %eax
jge 0x156574
jmp 0x156599
movslq 0x24(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %ecx
movslq 0x28(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x24(%rsp), %eax
movl %eax, 0x28(%rsp)
jmp 0x1564ee
movl 0x20(%rsp), %ecx
movslq 0x28(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x148c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x148c(%rsp)
movl 0x148c(%rsp), %ecx
movslq 0x1480(%rsp), %rax
movl %ecx, 0x40(%rsp,%rax,4)
movslq 0x1484(%rsp), %rax
movl %ecx, 0x40(%rsp,%rax,4)
movslq 0x1484(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
movslq 0x1480(%rsp), %rcx
movl 0x850(%rsp,%rcx,4), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
addl %ecx, %eax
movl %eax, 0x10(%rsp)
movslq 0x1484(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
andl $0xff, %eax
movslq 0x1480(%rsp), %rcx
movl 0x850(%rsp,%rcx,4), %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
jle 0x15664f
movslq 0x1484(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
andl $0xff, %eax
movl %eax, 0xc(%rsp)
jmp 0x156667
movslq 0x1480(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
andl $0xff, %eax
movl %eax, 0xc(%rsp)
movl 0x10(%rsp), %ecx
movl 0xc(%rsp), %eax
addl $0x1, %eax
orl %eax, %ecx
movslq 0x148c(%rsp), %rax
movl %ecx, 0x850(%rsp,%rax,4)
movslq 0x148c(%rsp), %rax
movl $0xffffffff, 0x40(%rsp,%rax,4) # imm = 0xFFFFFFFF
movl 0x1488(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1488(%rsp)
movl 0x148c(%rsp), %ecx
movslq 0x1488(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x1488(%rsp), %eax
movl %eax, 0x1c(%rsp)
movslq 0x1c(%rsp), %rax
movl 0x1060(%rsp,%rax,4), %eax
movl %eax, 0x18(%rsp)
movslq 0x18(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
movl 0x1c(%rsp), %ecx
sarl %ecx
movslq %ecx, %rcx
movslq 0x1060(%rsp,%rcx,4), %rcx
cmpl 0x850(%rsp,%rcx,4), %eax
jge 0x156722
movl 0x1c(%rsp), %eax
sarl %eax
cltq
movl 0x1060(%rsp,%rax,4), %ecx
movslq 0x1c(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
movl 0x1c(%rsp), %eax
sarl %eax
movl %eax, 0x1c(%rsp)
jmp 0x1566d5
movl 0x18(%rsp), %ecx
movslq 0x1c(%rsp), %rax
movl %ecx, 0x1060(%rsp,%rax,4)
jmp 0x15638b
cmpl $0x204, 0x148c(%rsp) # imm = 0x204
jl 0x15674e
movl $0x7d2, %edi            # imm = 0x7D2
callq 0xc7b30
movb $0x0, 0x1473(%rsp)
movl $0x1, 0x147c(%rsp)
movl 0x147c(%rsp), %eax
cmpl 0x1494(%rsp), %eax
jg 0x156814
movl $0x0, 0x1478(%rsp)
movl 0x147c(%rsp), %eax
movl %eax, 0x1474(%rsp)
movslq 0x1474(%rsp), %rax
cmpl $0x0, 0x40(%rsp,%rax,4)
jl 0x1567c3
movslq 0x1474(%rsp), %rax
movl 0x40(%rsp,%rax,4), %eax
movl %eax, 0x1474(%rsp)
movl 0x1478(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1478(%rsp)
jmp 0x15678e
movl 0x1478(%rsp), %eax
movb %al, %dl
movq 0x14a0(%rsp), %rax
movl 0x147c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl 0x1478(%rsp), %eax
cmpl 0x1490(%rsp), %eax
jle 0x1567fc
movb $0x1, 0x1473(%rsp)
jmp 0x1567fe
movl 0x147c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x147c(%rsp)
jmp 0x156761
cmpb $0x0, 0x1473(%rsp)
jne 0x156820
jmp 0x15689e
movl $0x1, 0x147c(%rsp)
movl 0x147c(%rsp), %eax
cmpl 0x1494(%rsp), %eax
jg 0x156899
movslq 0x147c(%rsp), %rax
movl 0x850(%rsp,%rax,4), %eax
sarl $0x8, %eax
movl %eax, 0x1478(%rsp)
movl 0x1478(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movl %eax, 0x1478(%rsp)
movl 0x1478(%rsp), %ecx
shll $0x8, %ecx
movslq 0x147c(%rsp), %rax
movl %ecx, 0x850(%rsp,%rax,4)
movl 0x147c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x147c(%rsp)
jmp 0x15682b
jmp 0x156257
addq $0x14a8, %rsp           # imm = 0x14A8
retq
nopw %cs:(%rax,%rax)