// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/bzip2-1.0.6/compress.c
// Function: generateMTFValues
static
void generateMTFValues ( EState* s )
{
   UChar   yy[256];
   Int32   i, j;
   Int32   zPend;
   Int32   wr;
   Int32   EOB;

   /* 
      After sorting (eg, here),
         s->arr1 [ 0 .. s->nblock-1 ] holds sorted order,
         and
         ((UChar*)s->arr2) [ 0 .. s->nblock-1 ] 
         holds the original block data.

      The first thing to do is generate the MTF values,
      and put them in
         ((UInt16*)s->arr1) [ 0 .. s->nblock-1 ].
      Because there are strictly fewer or equal MTF values
      than block values, ptr values in this area are overwritten
      with MTF values only when they are no longer needed.

      The final compressed bitstream is generated into the
      area starting at
         (UChar*) (&((UChar*)s->arr2)[s->nblock])

      These storage aliases are set up in bzCompressInit(),
      except for the last one, which is arranged in 
      compressBlock().
   */
   UInt32* ptr   = s->ptr;
   UChar* block  = s->block;
   UInt16* mtfv  = s->mtfv;

   makeMaps_e ( s );
   EOB = s->nInUse+1;

   for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0;

   wr = 0;
   zPend = 0;
   for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i;

   for (i = 0; i < s->nblock; i++) {
      UChar ll_i;
      AssertD ( wr <= i, "generateMTFValues(1)" );
      j = ptr[i]-1; if (j < 0) j += s->nblock;
      ll_i = s->unseqToSeq[block[j]];
      AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" );

      if (yy[0] == ll_i) { 
         zPend++;
      } else {

         if (zPend > 0) {
            zPend--;
            while (True) {
               if (zPend & 1) {
                  mtfv[wr] = BZ_RUNB; wr++; 
                  s->mtfFreq[BZ_RUNB]++; 
               } else {
                  mtfv[wr] = BZ_RUNA; wr++; 
                  s->mtfFreq[BZ_RUNA]++; 
               }
               if (zPend < 2) break;
               zPend = (zPend - 2) / 2;
            };
            zPend = 0;
         }
         {
            register UChar  rtmp;
            register UChar* ryy_j;
            register UChar  rll_i;
            rtmp  = yy[1];
            yy[1] = yy[0];
            ryy_j = &(yy[1]);
            rll_i = ll_i;
            while ( rll_i != rtmp ) {
               register UChar rtmp2;
               ryy_j++;
               rtmp2  = rtmp;
               rtmp   = *ryy_j;
               *ryy_j = rtmp2;
            };
            yy[0] = rtmp;
            j = ryy_j - &(yy[0]);
            mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++;
         }

      }
   }

   if (zPend > 0) {
      zPend--;
      while (True) {
         if (zPend & 1) {
            mtfv[wr] = BZ_RUNB; wr++; 
            s->mtfFreq[BZ_RUNB]++; 
         } else {
            mtfv[wr] = BZ_RUNA; wr++; 
            s->mtfFreq[BZ_RUNA]++; 
         }
         if (zPend < 2) break;
         zPend = (zPend - 2) / 2;
      };
      zPend = 0;
   }

   mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++;

   s->nMTF = wr;
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x150(%rsp)
movq 0x150(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x150(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x150(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x150(%rsp), %rdi
callq 0x101790
movq 0x150(%rsp), %rax
movl 0x7c(%rax), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jg 0xfc948
movq 0x150(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl $0x0, 0x2a0(%rax,%rcx,4)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xfc919
movl $0x0, 0x40(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movq 0x150(%rsp), %rcx
cmpl 0x7c(%rcx), %eax
jge 0xfc98d
movl 0x4c(%rsp), %eax
movb %al, %cl
movslq 0x4c(%rsp), %rax
movb %cl, 0x50(%rsp,%rax)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xfc960
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movq 0x150(%rsp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0xfcb9b
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, 0x48(%rsp)
cmpl $0x0, 0x48(%rsp)
jge 0xfc9d8
movq 0x150(%rsp), %rax
movl 0x6c(%rax), %eax
addl 0x48(%rsp), %eax
movl %eax, 0x48(%rsp)
movq 0x150(%rsp), %rax
movq 0x28(%rsp), %rcx
movslq 0x48(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
movb 0x180(%rax,%rcx), %al
movb %al, 0x1f(%rsp)
movzbl 0x50(%rsp), %eax
movzbl 0x1f(%rsp), %ecx
cmpl %ecx, %eax
jne 0xfca17
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xfcb89
cmpl $0x0, 0x44(%rsp)
jle 0xfcac8
movl 0x44(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xfca6d
movq 0x20(%rsp), %rax
movslq 0x40(%rsp), %rcx
movw $0x1, (%rax,%rcx,2)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x150(%rsp), %rax
movl 0x2a4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2a4(%rax)
jmp 0xfca9f
movq 0x20(%rsp), %rax
movslq 0x40(%rsp), %rcx
movw $0x0, (%rax,%rcx,2)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x150(%rsp), %rax
movl 0x2a0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2a0(%rax)
cmpl $0x2, 0x44(%rsp)
jge 0xfcaa8
jmp 0xfcac0
movl 0x44(%rsp), %eax
subl $0x2, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x44(%rsp)
jmp 0xfca2d
movl $0x0, 0x44(%rsp)
movb 0x51(%rsp), %al
movb %al, 0x1e(%rsp)
movb 0x50(%rsp), %al
movb %al, 0x51(%rsp)
leaq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
movb 0x1f(%rsp), %al
movb %al, 0xf(%rsp)
movzbl 0xf(%rsp), %eax
movzbl 0x1e(%rsp), %ecx
cmpl %ecx, %eax
je 0xfcb2a
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
movb 0x1e(%rsp), %al
movb %al, 0xe(%rsp)
movq 0x10(%rsp), %rax
movb (%rax), %al
movb %al, 0x1e(%rsp)
movb 0xe(%rsp), %cl
movq 0x10(%rsp), %rax
movb %cl, (%rax)
jmp 0xfcaee
movb 0x1e(%rsp), %al
movb %al, 0x50(%rsp)
movq 0x10(%rsp), %rax
leaq 0x50(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x48(%rsp)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movw %ax, %dx
movq 0x20(%rsp), %rax
movslq 0x40(%rsp), %rcx
movw %dx, (%rax,%rcx,2)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x150(%rsp), %rax
movl 0x48(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl 0x2a0(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x2a0(%rax,%rcx,4)
jmp 0xfcb8b
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xfc995
cmpl $0x0, 0x44(%rsp)
jle 0xfcc4c
movl 0x44(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xfcbf1
movq 0x20(%rsp), %rax
movslq 0x40(%rsp), %rcx
movw $0x1, (%rax,%rcx,2)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x150(%rsp), %rax
movl 0x2a4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2a4(%rax)
jmp 0xfcc23
movq 0x20(%rsp), %rax
movslq 0x40(%rsp), %rcx
movw $0x0, (%rax,%rcx,2)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x150(%rsp), %rax
movl 0x2a0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2a0(%rax)
cmpl $0x2, 0x44(%rsp)
jge 0xfcc2c
jmp 0xfcc44
movl 0x44(%rsp), %eax
subl $0x2, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x44(%rsp)
jmp 0xfcbb1
movl $0x0, 0x44(%rsp)
movl 0x3c(%rsp), %eax
movw %ax, %dx
movq 0x20(%rsp), %rax
movslq 0x40(%rsp), %rcx
movw %dx, (%rax,%rcx,2)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x150(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movl 0x2a0(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x2a0(%rax,%rcx,4)
movl 0x40(%rsp), %ecx
movq 0x150(%rsp), %rax
movl %ecx, 0x29c(%rax)
addq $0x158, %rsp            # imm = 0x158
retq
nopw %cs:(%rax,%rax)