// File: /workspace/github_c_makefile_star2_O1/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__zbuild_huffman(stbi__zhuffman*, unsigned char const*, int)
static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int num)
{
   int i,k=0;
   int code, next_code[16], sizes[17];

   // DEFLATE spec for generating codes
   memset(sizes, 0, sizeof(sizes));
   memset(z->fast, 0, sizeof(z->fast));
   for (i=0; i < num; ++i)
      ++sizes[sizelist[i]];
   sizes[0] = 0;
   for (i=1; i < 16; ++i)
      if (sizes[i] > (1 << i))
         return stbi__err("bad sizes", "Corrupt PNG");
   code = 0;
   for (i=1; i < 16; ++i) {
      next_code[i] = code;
      z->firstcode[i] = (stbi__uint16) code;
      z->firstsymbol[i] = (stbi__uint16) k;
      code = (code + sizes[i]);
      if (sizes[i])
         if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt PNG");
      z->maxcode[i] = code << (16-i); // preshift for inner loop
      code <<= 1;
      k += sizes[i];
   }
   z->maxcode[16] = 0x10000; // sentinel
   for (i=0; i < num; ++i) {
      int s = sizelist[i];
      if (s) {
         int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s];
         stbi__uint16 fastv = (stbi__uint16) ((s << 9) | i);
         z->size [c] = (stbi_uc     ) s;
         z->value[c] = (stbi__uint16) i;
         if (s <= STBI__ZFAST_BITS) {
            int j = stbi__bit_reverse(next_code[s],s);
            while (j < (1 << STBI__ZFAST_BITS)) {
               z->fast[j] = fastv;
               j += (1 << s);
            }
         }
         ++next_code[s];
      }
   }
   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x90, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movl $0x0, 0x40(%rsp)
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x20f0
testl %ebp, %ebp
jle 0x153ee
movl %ebp, %eax
xorl %ecx, %ecx
movzbl (%rbx,%rcx), %edx
incl (%rsp,%rdx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x153df
movl $0x0, (%rsp)
movl $0x1, %ecx
leaq 0x2ff5(%rip), %rdx      # 0x183f6
movl $0x1, %eax
shll %cl, %eax
cmpl %eax, (%rsp,%rcx,4)
jg 0x1557c
incq %rcx
cmpq $0x10, %rcx
jne 0x15401
xorl %esi, %esi
movl $0xf, %eax
leaq 0x2fd8(%rip), %rdx      # 0x18400
xorl %edi, %edi
xorl %r8d, %r8d
movl %r8d, 0x54(%rsp,%rsi,4)
movw %r8w, 0x402(%r14,%rsi,2)
movw %di, 0x466(%r14,%rsi,2)
movl 0x4(%rsp,%rsi,4), %r9d
addl %r9d, %r8d
leal 0x1(%rsi), %ecx
movl $0x1, %r10d
shll %cl, %r10d
testl %r9d, %r9d
je 0x15466
cmpl %r10d, %r8d
jg 0x1557c
movl %r8d, %r10d
movl %eax, %ecx
shll %cl, %r10d
movl %r10d, 0x424(%r14,%rsi,4)
addl %r8d, %r8d
addl %r9d, %edi
decl %eax
incq %rsi
cmpq $0xf, %rsi
jne 0x1542d
movl $0x10000, 0x460(%r14) # imm = 0x10000
movl $0x1, %eax
testl %ebp, %ebp
jle 0x15585
movl %ebp, %esi
xorl %edi, %edi
movl $0xf0f, %r8d            # imm = 0xF0F
movl $0x3333, %r9d           # imm = 0x3333
movl $0x5555, %r10d          # imm = 0x5555
movzbl (%rbx,%rdi), %edx
testl %edx, %edx
je 0x1556e
movl 0x50(%rsp,%rdx,4), %r11d
movzwl 0x400(%r14,%rdx,2), %ecx
movl %r11d, %ebp
subl %ecx, %ebp
movzwl 0x464(%r14,%rdx,2), %ecx
movslq %ebp, %r15
addq %rcx, %r15
movb %dl, 0x484(%r14,%r15)
movw %di, 0x5a4(%r14,%r15,2)
cmpb $0x9, %dl
ja 0x15566
movl %r11d, %ecx
rolw $0x8, %cx
movl %ecx, %ebp
shrl $0x4, %ebp
andl %r8d, %ebp
andl %r8d, %ecx
shll $0x4, %ecx
orl %ebp, %ecx
movl %ecx, %r15d
andl %r9d, %r15d
shrl $0x2, %ecx
andl %r9d, %ecx
leal (%rcx,%r15,4), %ecx
movl %ecx, %r15d
andl %r10d, %r15d
shrl %ecx
andl %r10d, %ecx
leal (%rcx,%r15,2), %ebp
movb $0x10, %cl
subb %dl, %cl
shrl %cl, %ebp
cmpl $0x1ff, %ebp            # imm = 0x1FF
ja 0x15566
movl %edx, %ecx
shll $0x9, %ecx
movl %edi, %r15d
orl %ecx, %r15d
movl $0x1, %r12d
movl %edx, %ecx
shlq %cl, %r12
movl %ebp, %ecx
movw %r15w, (%r14,%rcx,2)
addq %r12, %rcx
cmpq $0x200, %rcx            # imm = 0x200
jb 0x15555
incl %r11d
movl %r11d, 0x50(%rsp,%rdx,4)
incq %rdi
cmpq %rsi, %rdi
jne 0x154b5
jmp 0x15585
movq %rdx, 0x6ca5(%rip)      # 0x1c228
xorl %eax, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq