// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
pxor %xmm0, %xmm0
movdqa %xmm0, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
movdqa %xmm0, 0x20(%rsp)
movl $0x0, 0x60(%rsp)
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x41c0
testl %ebp, %ebp
jle 0x22db9
movl %ebp, %eax
xorl %ecx, %ecx
movzbl (%rbx,%rcx), %edx
incl 0x20(%rsp,%rdx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x22da9
movl $0x1, %ecx
leaq 0x9c93(%rip), %rdx      # 0x2ca58
movl $0x1, %eax
shll %cl, %eax
cmpl %eax, 0x20(%rsp,%rcx,4)
jg 0x2326e
incq %rcx
cmpq $0x10, %rcx
jne 0x22dc5
xorl %esi, %esi
movl $0xf, %eax
leaq 0x9c75(%rip), %rdx      # 0x2ca62
xorl %edi, %edi
xorl %r8d, %r8d
movl %r8d, 0x74(%rsp,%rsi,4)
movw %r8w, 0x402(%r14,%rsi,2)
movw %di, 0x466(%r14,%rsi,2)
movl 0x24(%rsp,%rsi,4), %r9d
addl %r9d, %r8d
leal 0x1(%rsi), %ecx
movl $0x1, %r10d
shll %cl, %r10d
testl %r9d, %r9d
je 0x22e2b
cmpl %r10d, %r8d
jg 0x2326e
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 0x22df2
movl $0x10000, 0x460(%r14) # imm = 0x10000
movl $0x1, %eax
testl %ebp, %ebp
jle 0x23277
movl %ebp, %eax
movq %rax, 0x10(%rsp)
xorl %edi, %edi
movdqa 0x8e4b(%rip), %xmm0     # 0x2bcc0
movdqa 0x8e53(%rip), %xmm1     # 0x2bcd0
movdqa 0x8e5b(%rip), %xmm2     # 0x2bce0
movdqa 0x8e63(%rip), %xmm3     # 0x2bcf0
movdqa 0x8dcb(%rip), %xmm4     # 0x2bc60
pcmpeqd %xmm5, %xmm5
movq %rbx, 0x8(%rsp)
movzbl (%rbx,%rdi), %edx
testl %edx, %edx
je 0x23259
movl 0x70(%rsp,%rdx,4), %ecx
movzwl 0x400(%r14,%rdx,2), %eax
movl %ecx, 0x4(%rsp)
subl %eax, %ecx
movzwl 0x464(%r14,%rdx,2), %eax
movslq %ecx, %rcx
addq %rax, %rcx
movb %dl, 0x484(%r14,%rcx)
movw %di, 0x5a4(%r14,%rcx,2)
cmpb $0x9, %dl
ja 0x2324a
movl 0x4(%rsp), %eax
rolw $0x8, %ax
movl %eax, %ecx
shrl $0x4, %ecx
movl $0xf0f, %esi            # imm = 0xF0F
andl %esi, %ecx
andl %esi, %eax
shll $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
movl $0x3333, %esi           # imm = 0x3333
andl %esi, %ecx
shrl $0x2, %eax
andl %esi, %eax
leal (%rax,%rcx,4), %eax
movl %eax, %ecx
movl $0x5555, %esi           # imm = 0x5555
andl %esi, %ecx
shrl %eax
andl %esi, %eax
leal (%rax,%rcx,2), %eax
movb $0x10, %cl
subb %dl, %cl
shrl %cl, %eax
cmpl $0x1ff, %eax            # imm = 0x1FF
ja 0x2324a
movl %edx, %ecx
shll $0x9, %ecx
movl %edi, %r15d
orl %ecx, %r15d
movl $0x1, %r12d
movl %edx, %ecx
shlq %cl, %r12
movl %eax, %r13d
leaq (%r12,%r13), %rax
xorl %esi, %esi
movl $0x200, %ecx            # imm = 0x200
cmpq %rcx, %rax
setb %sil
cmpq $0x201, %rax            # imm = 0x201
movl $0x200, %r8d            # imm = 0x200
cmovaeq %rax, %r8
subq %rsi, %r8
subq %rax, %r8
movl %edx, %ecx
shrq %cl, %r8
leaq (%rsi,%r8), %rax
leaq (%rsi,%r8), %r11
addq $0x8, %r11
andq $-0x8, %r11
movl $0x3, %r8d
shlq %cl, %r8
movl $0x5, %r9d
shlq %cl, %r9
movq %rax, %xmm6
pshufd $0x44, %xmm6, %xmm6     # xmm6 = xmm6[0,1,0,1]
movl $0x6, %r10d
shlq %cl, %r10
movl $0x7, %esi
shlq %cl, %rsi
leaq (%r12,%r12), %rax
movq %rax, 0x18(%rsp)
leaq (,%r12,4), %rbp
pxor %xmm4, %xmm6
xorl %eax, %eax
movq %rax, %rbx
movl %edx, %ecx
shlq %cl, %rbx
addq %r13, %rbx
movq %rax, %xmm7
pshufd $0x44, %xmm7, %xmm7     # xmm7 = xmm7[0,1,0,1]
movdqa %xmm7, %xmm8
por %xmm3, %xmm8
pxor %xmm4, %xmm8
movdqa %xmm8, %xmm10
pcmpgtd %xmm6, %xmm10
pshufd $0xa0, %xmm10, %xmm9    # xmm9 = xmm10[0,0,2,2]
pshuflw $0xe8, %xmm9, %xmm11    # xmm11 = xmm9[0,2,2,3,4,5,6,7]
pcmpeqd %xmm6, %xmm8
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm12    # xmm12 = xmm8[0,2,2,3,4,5,6,7]
pand %xmm11, %xmm12
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
pshuflw $0xe8, %xmm10, %xmm11   # xmm11 = xmm10[0,2,2,3,4,5,6,7]
por %xmm12, %xmm11
pxor %xmm5, %xmm11
packssdw %xmm11, %xmm11
movd %xmm11, %ecx
testb $0x1, %cl
je 0x23047
movw %r15w, (%r14,%rbx,2)
pand %xmm9, %xmm8
por %xmm10, %xmm8
packssdw %xmm8, %xmm8
pxor %xmm5, %xmm8
packssdw %xmm8, %xmm8
movd %xmm8, %ecx
shrl $0x10, %ecx
testb $0x1, %cl
je 0x23076
leaq (%rbx,%r12), %rcx
movw %r15w, (%r14,%rcx,2)
movdqa %xmm7, %xmm9
por %xmm2, %xmm9
pxor %xmm4, %xmm9
movdqa %xmm9, %xmm10
pcmpgtd %xmm6, %xmm10
pshufd $0xa0, %xmm10, %xmm8    # xmm8 = xmm10[0,0,2,2]
pcmpeqd %xmm6, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
movdqa %xmm9, %xmm11
pand %xmm8, %xmm11
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
por %xmm10, %xmm11
packssdw %xmm11, %xmm11
pxor %xmm5, %xmm11
packssdw %xmm11, %xmm11
pextrw $0x2, %xmm11, %ecx
testb $0x1, %cl
je 0x230dc
movq 0x18(%rsp), %rcx
addq %rbx, %rcx
movw %r15w, (%r14,%rcx,2)
pshufhw $0x84, %xmm8, %xmm8     # xmm8 = xmm8[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm9, %xmm9     # xmm9 = xmm9[0,1,2,3,4,5,4,6]
pand %xmm8, %xmm9
pshufhw $0x84, %xmm10, %xmm8    # xmm8 = xmm10[0,1,2,3,4,5,4,6]
por %xmm9, %xmm8
pxor %xmm5, %xmm8
packssdw %xmm8, %xmm8
pextrw $0x3, %xmm8, %ecx
testb $0x1, %cl
je 0x23116
leaq (%rbx,%r8), %rcx
movw %r15w, (%r14,%rcx,2)
movdqa %xmm7, %xmm8
por %xmm1, %xmm8
pxor %xmm4, %xmm8
movdqa %xmm8, %xmm10
pcmpgtd %xmm6, %xmm10
pshufd $0xa0, %xmm10, %xmm9    # xmm9 = xmm10[0,0,2,2]
pshuflw $0xe8, %xmm9, %xmm11    # xmm11 = xmm9[0,2,2,3,4,5,6,7]
pcmpeqd %xmm6, %xmm8
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm12    # xmm12 = xmm8[0,2,2,3,4,5,6,7]
pand %xmm11, %xmm12
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
pshuflw $0xe8, %xmm10, %xmm11   # xmm11 = xmm10[0,2,2,3,4,5,6,7]
por %xmm12, %xmm11
pxor %xmm5, %xmm11
packssdw %xmm11, %xmm11
pextrw $0x4, %xmm11, %ecx
testb $0x1, %cl
je 0x23180
leaq (%rbx,%rbp), %rcx
movw %r15w, (%r14,%rcx,2)
pand %xmm9, %xmm8
por %xmm10, %xmm8
packssdw %xmm8, %xmm8
pxor %xmm5, %xmm8
packssdw %xmm8, %xmm8
pextrw $0x5, %xmm8, %ecx
testb $0x1, %cl
je 0x231ad
leaq (%rbx,%r9), %rcx
movw %r15w, (%r14,%rcx,2)
por %xmm0, %xmm7
pxor %xmm4, %xmm7
movdqa %xmm7, %xmm9
pcmpgtd %xmm6, %xmm9
pshufd $0xa0, %xmm9, %xmm8     # xmm8 = xmm9[0,0,2,2]
pcmpeqd %xmm6, %xmm7
pshufd $0xf5, %xmm7, %xmm7     # xmm7 = xmm7[1,1,3,3]
movdqa %xmm7, %xmm10
pand %xmm8, %xmm10
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
por %xmm9, %xmm10
packssdw %xmm10, %xmm10
pxor %xmm5, %xmm10
packssdw %xmm10, %xmm10
pextrw $0x6, %xmm10, %ecx
testb $0x1, %cl
je 0x23206
leaq (%rbx,%r10), %rcx
movw %r15w, (%r14,%rcx,2)
pshufhw $0x84, %xmm8, %xmm8     # xmm8 = xmm8[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm7, %xmm7     # xmm7 = xmm7[0,1,2,3,4,5,4,6]
pand %xmm8, %xmm7
pshufhw $0x84, %xmm9, %xmm8     # xmm8 = xmm9[0,1,2,3,4,5,4,6]
por %xmm7, %xmm8
pxor %xmm5, %xmm8
packssdw %xmm8, %xmm7
pextrw $0x7, %xmm7, %ecx
testb $0x1, %cl
je 0x2323d
addq %rsi, %rbx
movw %r15w, (%r14,%rbx,2)
addq $0x8, %rax
cmpq %rax, %r11
jne 0x22fcd
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x70(%rsp,%rdx,4)
movq 0x8(%rsp), %rbx
incq %rdi
cmpq 0x10(%rsp), %rdi
jne 0x22e9e
movl $0x1, %eax
jmp 0x23277
movq %rdx, 0x1411b(%rip)     # 0x37390
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq