// File: /workspace/github_cpp_makefile_star2_O2/srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__zbuild_huffman(stbi__zhuffman*, unsigned char*, int)
static int stbi__zbuild_huffman(stbi__zhuffman *z, 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 %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
andl $0x0, 0x40(%rsp)
xorl %r12d, %r12d
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x41d0
testl %ebx, %ebx
cmovlel %r12d, %ebx
cmpq %r12, %rbx
je 0x1a9a7
movzbl (%r14,%r12), %eax
incl (%rsp,%rax,4)
incq %r12
jmp 0x1a995
pushq $0x1
popq %rcx
pushq $0x1
popq %rax
leaq 0x7fa4(%rip), %rsi      # 0x22958
cmpq $0x10, %rcx
je 0x1a9e5
movl %eax, %edx
shll %cl, %edx
leaq 0x1(%rcx), %rdi
cmpl %edx, (%rsp,%rcx,4)
movq %rdi, %rcx
jle 0x1a9b4
movq %rsi, 0x149ff(%rip)     # 0x2f3d0
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
pushq $0xf
popq %rdx
pushq $-0xf
popq %r8
leaq 0x7f6d(%rip), %rsi      # 0x22962
xorl %r9d, %r9d
testq %r8, %r8
je 0x1aa4f
movl %edi, 0x90(%rsp,%r8,4)
movw %di, 0x420(%r15,%r8,2)
movw %r9w, 0x484(%r15,%r8,2)
movl 0x40(%rsp,%r8,4), %r10d
addl %r10d, %edi
leal 0x10(%r8), %ecx
movl %eax, %r11d
shll %cl, %r11d
testl %r10d, %r10d
je 0x1aa33
cmpl %r11d, %edi
jg 0x1a9ca
movl %edi, %r11d
movl %edx, %ecx
shll %cl, %r11d
movl %r11d, 0x460(%r15,%r8,4)
addl %edi, %edi
addl %r10d, %r9d
decl %edx
incq %r8
jmp 0x1a9f8
movl $0x10000, 0x460(%r15) # imm = 0x10000
xorl %esi, %esi
movl $0xf0f, %edi            # imm = 0xF0F
movl $0x3333, %r8d           # imm = 0x3333
movl $0x5555, %r9d           # imm = 0x5555
pushq $0x1
popq %r10
cmpq %rbx, %rsi
je 0x1a9d3
movzbl (%r14,%rsi), %edx
testl %edx, %edx
je 0x1ab2c
movl 0x50(%rsp,%rdx,4), %r11d
movzwl 0x400(%r15,%rdx,2), %ecx
movl %r11d, %ebp
subl %ecx, %ebp
movzwl 0x464(%r15,%rdx,2), %ecx
movslq %ebp, %r12
addq %rcx, %r12
movb %dl, 0x484(%r15,%r12)
movw %si, 0x5a4(%r15,%r12,2)
cmpb $0x9, %dl
ja 0x1ab24
movl %edx, %ecx
shll $0x9, %ecx
movl %esi, %ebp
movl %r11d, %r12d
rolw $0x8, %r12w
orl %ecx, %ebp
movl %r12d, %ecx
shrl $0x4, %ecx
andl %edi, %ecx
andl %edi, %r12d
shll $0x4, %r12d
orl %ecx, %r12d
movl %r12d, %ecx
andl %r8d, %ecx
shrl $0x2, %r12d
andl %r8d, %r12d
leal (%r12,%rcx,4), %ecx
movl %ecx, %r12d
andl %r9d, %r12d
shrl %ecx
andl %r9d, %ecx
leal (%rcx,%r12,2), %r12d
movb $0x10, %cl
subb %dl, %cl
shrl %cl, %r12d
movq %r10, %r13
movl %edx, %ecx
shlq %cl, %r13
cmpq $0x1ff, %r12            # imm = 0x1FF
ja 0x1ab24
movw %bp, (%r15,%r12,2)
addq %r13, %r12
jmp 0x1ab11
incl %r11d
movl %r11d, 0x50(%rsp,%rdx,4)
incq %rsi
jmp 0x1aa71