// File: /workspace/github_c_makefile_star2_O2/snej[P]zdelta/inftrees.c
// Function: huft_build
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
uInt n;                 /* number of codes (assumed <= 288) */
uInt s;                 /* number of simple-valued codes (0..s-1) */
const uIntf *d;         /* list of base values for non-simple codes */
const uIntf *e;         /* list of extra bits for non-simple codes */
inflate_huft * FAR *t;  /* result: starting table */
uIntf *m;               /* maximum lookup bits, returns actual */
inflate_huft *hp;       /* space for trees */
uInt *hn;               /* hufts used in space */
uIntf *v;               /* working area: values in order of bit length */
/* Given a list of code lengths and a maximum table size, make a set of
   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
   if the given code set is incomplete (the tables are still built in this
   case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
   lengths), or Z_MEM_ERROR if not enough memory. */
{

  uInt a;                       /* counter for codes of length k */
  uInt c[BMAX+1];               /* bit length count table */
  uInt f;                       /* i repeats in table every f entries */
  int g;                        /* maximum code length */
  int h;                        /* table level */
  register uInt i;              /* counter, current code */
  register uInt j;              /* counter */
  register int k;               /* number of bits in current code */
  int l;                        /* bits per table (returned in m) */
  uInt mask;                    /* (1 << w) - 1, to avoid cc -O bug on HP */
  register uIntf *p;            /* pointer into c[], b[], or v[] */
  inflate_huft *q;              /* points to current table */
  struct inflate_huft_s r;      /* table entry for structure assignment */
   inflate_huft *u[BMAX];        /* table stack */
  register int w;               /* bits before this table == (l * h) */
  uInt x[BMAX+1];               /* bit offsets, then code stack */
  uIntf *xp;                    /* pointer into x */
  int y;                        /* number of dummy codes added */
  uInt z;                       /* number of entries in current table */


  /* Generate counts for each bit length */
  p = c;
#define C0 *p++ = 0;
#define C2 C0 C0 C0 C0
#define C4 C2 C2 C2 C2
  C4                            /* clear c[]--assume BMAX+1 is 16 */
  p = b;  i = n;
  do {
    c[*p++]++;                  /* assume all entries <= BMAX */
  } while (--i);
  if (c[0] == n)                /* null input--all zero length codes */
  {
    *t = (inflate_huft *)ZD_NULL;
    *m = 0;
    return ZD_OK;
  }


  /* Find minimum and maximum length, bound *m by those */
  l = *m;
  for (j = 1; j <= BMAX; j++)
    if (c[j])
      break;
  k = j;                        /* minimum code length */
  if ((uInt)l < j)
    l = j;
  for (i = BMAX; i; i--) 
    if (c[i])
      break;
  g = i;                        /* maximum code length */
  if ((uInt)l > i)
    l = i;
  *m = l;


  /* Adjust last length count to fill out codes, if needed */
  for (y = 1 << j; j < i; j++, y <<= 1)
    if ((y -= c[j]) < 0)
      return ZD_DATA_ERROR;
  if ((y -= c[i]) < 0)
    return ZD_DATA_ERROR;
  c[i] += y;


  /* Generate starting offsets into the value table for each length */
  x[1] = j = 0;
  p = c + 1;  xp = x + 2;
  while (--i) {                 /* note that i == g from above */
    *xp++ = (j += *p++);
  }


  /* Make a table of values in order of bit lengths */
  p = b;  i = 0;
  do {
    if ((j = *p++) != 0)
      v[x[j]++] = i;
  } while (++i < n);
  n = x[g];                     /* set n to length of v */


  /* Generate the Huffman codes and for each, make the table entries */
  x[0] = i = 0;                 /* first Huffman code is zero */
  p = v;                        /* grab values in bit order */
  h = -1;                       /* no tables yet--level -1 */
  w = -l;                       /* bits decoded == (l * h) */
  u[0] = (inflate_huft *)ZD_NULL;        /* just to keep compilers happy */
  q = (inflate_huft *)ZD_NULL;   /* ditto */
  z = 0;                        /* ditto */

  /* go through the bit lengths (k already is bits in shortest code) */
  for (; k <= g; k++)
  {
    a = c[k];
    while (a--)
    {
      /* here i is the Huffman code of length k bits for value *p */
      /* make tables up to required level */
      while (k > w + l)
      {
        h++;
        w += l;                 /* previous table always l bits */

        /* compute minimum size table less than or equal to l bits */
        z = g - w;
        z = z > (uInt)l ? (uInt) l : z;         /* table size upper limit */
        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
        {                       /* too few codes for k-w bit table */
          f -= a + 1;           /* deduct codes from patterns left */
          xp = c + k;
          if (j < z)
            while (++j < z)     /* try smaller tables up to z bits */
            {
              if ((f <<= 1) <= *++xp)
                break;          /* enough codes to use up j bits */
              f -= *xp;         /* else deduct codes from patterns */
            }
        }
        z = 1 << j;             /* table entries for j-bit table */

        /* allocate new table */
        if (*hn + z > MANY)     /* (note: doesn't matter for fixed) */
          return ZD_MEM_ERROR;   /* not enough memory */
        u[h] = q = hp + *hn;
        *hn += z;

        /* connect to last table, if there is one */
        if (h)
        {
          x[h] = i;             /* save pattern for backing up */
          r.bits = (Byte)l;     /* bits to dump before this table */
          r.exop = (Byte)j;     /* bits in this table */
          j = i >> (w - l);
          r.base = (uInt)(q - u[h-1] - j);   /* offset to this table */
          u[h-1][j] = r;        /* connect to last table */
        }
        else
          *t = q;               /* first table is returned result */
      }

      /* set up table entry in r */
      r.bits = (Byte)(k - w);
      if (p >= v + n)
        r.exop = 128 + 64;      /* out of values--invalid code */
      else if (*p < s)
      {
        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
        r.base = *p++;          /* simple code is just the value */
      }
      else
      {
        r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
        r.base = d[*p++ - s];
      }

      /* fill code-like entries with r */
      f = 1 << (k - w);
      for (j = i >> w; j < z; j += f)
        q[j] = r;

      /* backwards increment the k-bit code i */
      for (j = 1 << (k - 1); i & j; j >>= 1)
        i ^= j;
      i ^= j;

      /* backup over finished tables */
      mask = (1 << w) - 1;      /* needed on HP, cc -O bug */
      while ((i & mask) != x[h])
      {
        h--;                    /* don't need to update q */
        w -= l;
        mask = (1 << w) - 1;
      }
    }
  }


  /* Return Z_BUF_ERROR if we were given an incomplete table */
  return y != 0 && g != 1 ? ZD_BUF_ERROR : ZD_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r9, -0x10(%rsp)
movq %rcx, %r11
movq 0x158(%rsp), %rax
movq %rax, -0x60(%rsp)
movq 0x150(%rsp), %r13
movq 0x140(%rsp), %r10
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movl %esi, %ebx
xorl %eax, %eax
movl (%rdi,%rax,4), %r9d
incl 0x10(%rsp,%r9,4)
incq %rax
cmpl %eax, %ebx
jne 0x810c
cmpl %esi, 0x10(%rsp)
jne 0x8136
movq -0x10(%rsp), %rax
andq $0x0, (%rax)
andl $0x0, (%r10)
xorl %eax, %eax
jmp 0x8585
movl (%r10), %r12d
movabsq $0x1, %rsi
movl $0x10, %ecx
movq %r8, 0x8(%rsp)
cmpq $0x10, %rsi
je 0x8161
cmpl $0x0, 0x10(%rsp,%rsi,4)
jne 0x815f
incq %rsi
jmp 0x814d
movl %esi, %ecx
cmpl %ecx, %r12d
cmovbel %ecx, %r12d
movl $0xf, %r14d
xorl %ebp, %ebp
leaq 0xf(%rbp), %r9
cmpl $-0xf, %ebp
je 0x818b
movl %r9d, %esi
cmpl $0x0, 0x10(%rsp,%rsi,4)
jne 0x818b
decl %r14d
decq %rbp
jmp 0x8170
cmpl %r9d, %r12d
movl %r9d, %esi
movq %r9, -0x48(%rsp)
movl %r9d, %r15d
movq %rsi, %r9
cmovbl %r12d, %r15d
movq %r15, -0x50(%rsp)
movl %r15d, (%r10)
movl $0x1, %r15d
shll %cl, %r15d
movl %ecx, %esi
movabsq $-0xe, %r10
subq %rbp, %r10
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
movq %rsi, %r8
cmpq %r9, %rsi
jae 0x81e0
subl 0x10(%rsp,%rsi,4), %r15d
js 0x8585
incq %rsi
addl %r15d, %r15d
jmp 0x81c8
movl 0x10(%rsp,%r9,4), %esi
movl %esi, -0x34(%rsp)
cmpl %esi, %r15d
js 0x8585
andl $0x0, 0x54(%rsp)
movq %r9, -0x40(%rsp)
movl %r15d, 0x10(%rsp,%r9,4)
xorl %esi, %esi
movabsq $0x2, %r9
movq 0x158(%rsp), %rax
testl %r10d, %r10d
je 0x822c
addl 0xc(%rsp,%r9,4), %esi
movl %esi, 0x50(%rsp,%r9,4)
incl %r10d
incq %r9
jmp 0x8215
movl %r14d, -0x74(%rsp)
xorl %r14d, %r14d
movq -0x40(%rsp), %r9
movl (%rdi,%r14,4), %esi
testq %rsi, %rsi
je 0x8259
movl 0x50(%rsp,%rsi,4), %r10d
leal 0x1(%r10), %r9d
movl %r9d, 0x50(%rsp,%rsi,4)
movq -0x40(%rsp), %r9
movl %r14d, (%rax,%r10,4)
incq %r14
cmpl %ebx, %r14d
jb 0x8239
movl %edx, -0x38(%rsp)
movq %r11, -0x8(%rsp)
movl 0x8c(%rsp,%rbp,4), %edx
andl $0x0, 0x50(%rsp)
movq -0x50(%rsp), %r11
movl %r11d, %edi
negl %edi
andq $0x0, 0x90(%rsp)
leaq (%rax,%rdx,4), %rax
movq %rax, (%rsp)
incl %ecx
movl %ecx, -0x68(%rsp)
movq -0x48(%rsp), %rcx
cmpl %ecx, %r12d
cmovbl %r12d, %ecx
movq %rcx, -0x48(%rsp)
leaq (%rsp,%r8,4), %rax
addq $0x14, %rax
movq %rax, -0x18(%rsp)
movl -0x74(%rsp), %ecx
cmpl %ecx, %r12d
cmovael %ecx, %r12d
subl %r12d, %ecx
movl %ecx, -0x74(%rsp)
negl %r12d
movslq %r12d, %rax
leaq (%rax,%rbp), %r10
addq $0xf, %r10
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %eax, %eax
xorl %ebx, %ebx
xorl %edx, %edx
movq %rbp, -0x28(%rsp)
movq %r10, -0x20(%rsp)
cmpq %r9, %r8
ja 0x8597
movl 0x10(%rsp,%r8,4), %r10d
leal -0x1(%r8), %ecx
movl $0x1, %esi
shll %cl, %esi
movl %esi, -0x30(%rsp)
movl %r10d, -0x64(%rsp)
movl %r10d, %ecx
movq -0x20(%rsp), %r10
movq %r8, -0x58(%rsp)
subl $0x1, %ecx
jb 0x856e
movl %ecx, -0x2c(%rsp)
movl %r10d, %ebp
subl %edi, %ebp
movl %r12d, -0x70(%rsp)
movslq %r12d, %r9
movq -0x48(%rsp), %rcx
addl %edi, %ecx
movl -0x68(%rsp), %esi
subl %ecx, %esi
movl %esi, -0x6c(%rsp)
leaq (%rsp,%r9,4), %r10
addq $0x50, %r10
cmpl %ebp, %r11d
movl %ebp, %esi
cmovbl %r11d, %esi
leal (%rdi,%r11), %r12d
movslq %r12d, %rcx
cmpq %rcx, %r8
jle 0x846c
movl -0x74(%rsp), %ebx
subl %edi, %ebx
cmpl %r11d, %ebx
cmovael %r11d, %ebx
movl %r8d, %r11d
subl %r12d, %r11d
movl $0x1, %ecx
movl %ecx, %edx
movl %r11d, %ecx
shll %cl, %edx
movl %edx, %ecx
subl -0x64(%rsp), %ecx
jbe 0x83cd
cmpl %ebx, %r11d
jae 0x83cd
movq -0x18(%rsp), %rdx
movl -0x6c(%rsp), %r8d
cmpl %ebx, %r8d
jae 0x83b6
addl %ecx, %ecx
incl %r8d
leaq 0x4(%rdx), %r13
incl %r11d
subl (%rdx), %ecx
movq %r13, %rdx
ja 0x839c
jmp 0x83b9
movl %esi, %r11d
movl $0x1, %ecx
movl %ecx, %edx
movl %r11d, %ecx
shll %cl, %edx
movq 0x150(%rsp), %r13
movl (%r13), %ecx
leal (%rcx,%rdx), %r8d
cmpl $0x5a0, %r8d            # imm = 0x5A0
ja 0x8580
movq %r9, %rsi
movq 0x148(%rsp), %rbx
leaq (%rbx,%rcx,8), %rbx
incq %rsi
movq %rbx, 0x90(%rsp,%rsi,8)
movl %r8d, (%r13)
je 0x8438
movl %eax, 0x50(%rsp,%rsi,4)
movl %eax, %r8d
movl %edi, %ecx
shrl %cl, %r8d
movq 0x90(%rsp,%r9,8), %rcx
movq %rbx, %r14
subq %rcx, %r14
shrq $0x3, %r14
subl %r8d, %r14d
movb %r11b, (%rcx,%r8,8)
movq -0x50(%rsp), %r11
movb %r11b, 0x1(%rcx,%r8,8)
movl %r14d, 0x4(%rcx,%r8,8)
jmp 0x8445
movq -0x10(%rsp), %rcx
movq %rbx, (%rcx)
movq -0x50(%rsp), %r11
movq -0x58(%rsp), %r8
subl %r11d, %ebp
movl -0x6c(%rsp), %ecx
subl -0x48(%rsp), %ecx
movl %ecx, -0x6c(%rsp)
incl -0x70(%rsp)
addq $0x4, %r10
movq %rsi, %r9
movl %r12d, %edi
jmp 0x834d
movb $-0x40, %sil
movq -0x60(%rsp), %r9
cmpq (%rsp), %r9
jae 0x84b0
movl (%r9), %r14d
movl %r14d, %ecx
subl -0x38(%rsp), %ecx
movq -0x28(%rsp), %rbp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jae 0x84c2
cmpl $0x100, %r14d           # imm = 0x100
movl $0x60, %esi
movl $0x0, %ecx
cmovbl %ecx, %esi
addq $0x4, %r9
movq %r9, -0x60(%rsp)
jmp 0x84e6
movq %r9, -0x60(%rsp)
movq -0x28(%rsp), %rbp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x84e6
movq 0x8(%rsp), %rsi
movb (%rsi,%rcx,4), %sil
addb $0x50, %sil
addq $0x4, %r9
movq %r9, -0x60(%rsp)
movq -0x8(%rsp), %r8
movl (%r8,%rcx,4), %r14d
movq -0x58(%rsp), %r8
movl %r8d, %r11d
subl %edi, %r11d
movl $0x1, %r8d
movl %r11d, %ecx
shll %cl, %r8d
movl %eax, %r9d
movl %edi, %ecx
shrl %cl, %r9d
cmpl %edx, %r9d
jae 0x851b
movl %r9d, %ecx
movb %sil, (%rbx,%rcx,8)
movb %r11b, 0x1(%rbx,%rcx,8)
movl %r14d, 0x4(%rbx,%rcx,8)
addl %r8d, %r9d
jmp 0x8500
movl -0x30(%rsp), %ecx
movq -0x40(%rsp), %r9
movq -0x50(%rsp), %r11
movq -0x58(%rsp), %r8
movl %eax, %esi
movl %ecx, %eax
xorl %esi, %eax
testl %esi, %ecx
je 0x8547
shrl %ecx
jmp 0x852e
subl %r11d, %edi
decl -0x70(%rsp)
addq $-0x4, %r10
movl %r12d, %esi
movl %edi, %ecx
shll %cl, %esi
notl %esi
andl %eax, %esi
cmpl (%r10), %esi
jne 0x853c
movl -0x2c(%rsp), %ecx
movl %ecx, -0x64(%rsp)
movq -0x20(%rsp), %r10
movl -0x70(%rsp), %r12d
jmp 0x831a
incq %r8
incl -0x68(%rsp)
addq $0x4, -0x18(%rsp)
jmp 0x82eb
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpl -0x34(%rsp), %r15d
sete %al
xorl %ecx, %ecx
cmpl $-0xe, %ebp
leal -0x5(%rax,%rax,4), %eax
cmovel %ecx, %eax
jmp 0x8585