// File: /workspace/github_c_makefile_star2_O2/archer1357[P]Offline-Raytracer/stb_image.c
// Function: stbi__zbuild_huffman
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, 255, sizeof(z->fast));
   for (i=0; i < num; ++i) 
      ++sizes[sizelist[i]];
   sizes[0] = 0;
   for (i=1; i < 16; ++i)
      STBI_ASSERT(sizes[i] <= (1 << i));
   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 JPEG");
      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];
         z->size [c] = (stbi_uc     ) s;
         z->value[c] = (stbi__uint16) i;
         if (s <= STBI__ZFAST_BITS) {
            int k = stbi__bit_reverse(next_code[s],s);
            while (k < (1 << STBI__ZFAST_BITS)) {
               z->fast[k] = (stbi__uint16) c;
               k += (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)
movl $0x400, %edx            # imm = 0x400
movl $0xff, %esi
callq 0x4010e8
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
cmpq %rax, %rbx
je 0x41042f
movzbl (%r14,%rax), %ecx
incl (%rsp,%rcx,4)
incq %rax
jmp 0x41041d
pushq $0x1
popq %rcx
pushq $0x1
popq %rax
cmpq $0x10, %rcx
je 0x41046a
movl %eax, %edx
shll %cl, %edx
leaq 0x1(%rcx), %rsi
cmpl %edx, (%rsp,%rcx,4)
movq %rsi, %rcx
jle 0x410435
leaq 0xc4a31(%rip), %rdi     # 0x4d4e83
leaq 0xc44b5(%rip), %rsi     # 0x4d490e
leaq 0xc4a38(%rip), %rcx     # 0x4d4e98
movl $0x6a7, %edx            # imm = 0x6A7
callq 0x41d270
xorl %esi, %esi
pushq $0xf
popq %rdx
pushq $-0xf
popq %rdi
xorl %r8d, %r8d
testq %rdi, %rdi
je 0x4104d0
movl %r8d, 0x90(%rsp,%rdi,4)
movw %r8w, 0x420(%r15,%rdi,2)
movw %si, 0x484(%r15,%rdi,2)
movl 0x40(%rsp,%rdi,4), %r9d
addl %r9d, %r8d
leal 0x10(%rdi), %ecx
movl %eax, %r10d
shll %cl, %r10d
testl %r9d, %r9d
je 0x4104b3
cmpl %r10d, %r8d
jg 0x4105a4
movl %r8d, %r10d
movl %edx, %ecx
shll %cl, %r10d
movl %r10d, 0x460(%r15,%rdi,4)
addl %r8d, %r8d
addl %r9d, %esi
decl %edx
incq %rdi
jmp 0x410475
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 0x4105b4
movzbl (%r14,%rsi), %edx
testl %edx, %edx
je 0x41059c
movslq 0x50(%rsp,%rdx,4), %r11
movzwl 0x400(%r15,%rdx,2), %ecx
movq %r11, %r13
subq %rcx, %r13
movzwl 0x464(%r15,%rdx,2), %r12d
addq %r13, %r12
movb %dl, 0x484(%r15,%r12)
movw %si, 0x5a4(%r15,%r12,2)
cmpb $0x9, %dl
ja 0x410594
movl %r11d, %ecx
rolw $0x8, %cx
movl %ecx, %ebp
shrl $0x4, %ebp
andl %edi, %ebp
andl %edi, %ecx
shll $0x4, %ecx
orl %ebp, %ecx
movl %ecx, %r13d
andl %r8d, %r13d
shrl $0x2, %ecx
andl %r8d, %ecx
leal (%rcx,%r13,4), %ecx
movl %ecx, %r13d
andl %r9d, %r13d
shrl %ecx
andl %r9d, %ecx
leal (%rcx,%r13,2), %r13d
movb $0x10, %cl
subb %dl, %cl
shrl %cl, %r13d
movq %r10, %rbp
movl %edx, %ecx
shlq %cl, %rbp
cmpq $0x1ff, %r13            # imm = 0x1FF
ja 0x410594
movw %r12w, (%r15,%r13,2)
addq %rbp, %r13
jmp 0x410581
leal 0x1(%r11), %ecx
movl %ecx, 0x50(%rsp,%rdx,4)
incq %rsi
jmp 0x4104f2
leaq 0xc4928(%rip), %rax     # 0x4d4ed3
movq %rax, 0x108f8e(%rip)    # 0x519540
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq