// File: alan0201tw[P]RayTracer/include/stb_image.h
// Function: stbi__build_huffman(stbi__huffman*, int*)
static int stbi__build_huffman(stbi__huffman *h, int *count)
{
   int i,j,k=0;
   unsigned int code;
   // build size list for each symbol (from JPEG spec)
   for (i=0; i < 16; ++i)
      for (j=0; j < count[i]; ++j)
         h->size[k++] = (stbi_uc) (i+1);
   h->size[k] = 0;

   // compute actual symbols (from jpeg spec)
   code = 0;
   k = 0;
   for(j=1; j <= 16; ++j) {
      // compute delta to add to code to compute symbol id
      h->delta[j] = k - code;
      if (h->size[k] == j) {
         while (h->size[k] == j)
            h->code[k++] = (stbi__uint16) (code++);
         if (code-1 >= (1u << j)) return stbi__err("bad code lengths","Corrupt JPEG");
      }
      // compute largest code + 1 for this size, preshifted as needed later
      h->maxcode[j] = code << (16-j);
      code <<= 1;
   }
   h->maxcode[j] = 0xffffffff;

   // build non-spec acceleration table; 255 is flag for not-accelerated
   memset(h->fast, 255, 1 << FAST_BITS);
   for (i=0; i < k; ++i) {
      int s = h->size[i];
      if (s <= FAST_BITS) {
         int c = h->code[i] << (FAST_BITS-s);
         int m = 1 << (FAST_BITS-s);
         for (j=0; j < m; ++j) {
            h->fast[c+j] = (stbi_uc) i;
         }
      }
   }
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x10, -0x1c(%rbp)
jge 0x65ef4
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x65ee7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
movslq %ecx, %rcx
movb %dl, 0x500(%rax,%rcx)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x65eab
jmp 0x65ee9
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x65e9e
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb $0x0, 0x500(%rax,%rcx)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x1, -0x20(%rbp)
cmpl $0x10, -0x20(%rbp)
jg 0x65fec
movl -0x24(%rbp), %edx
subl -0x28(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl %edx, 0x64c(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl 0x500(%rax,%rcx), %eax
cmpl -0x20(%rbp), %eax
jne 0x65fba
jmp 0x65f4f
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl 0x500(%rax,%rcx), %eax
cmpl -0x20(%rbp), %eax
jne 0x65f8e
movl -0x28(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x28(%rbp)
movw %ax, %dx
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
movslq %ecx, %rcx
movw %dx, 0x200(%rax,%rcx,2)
jmp 0x65f4f
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl -0x20(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jb 0x65fb8
leaq 0x1b0e5(%rip), %rdi     # 0x81090
callq 0x56040
movl %eax, -0x4(%rbp)
jmp 0x660b5
jmp 0x65fba
movl -0x28(%rbp), %edx
movl $0x10, %ecx
subl -0x20(%rbp), %ecx
shll %cl, %edx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl %edx, 0x604(%rax,%rcx,4)
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x65f19
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl $0xffffffff, 0x604(%rax,%rcx,4) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movl $0xff, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x7290
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x660ae
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl 0x500(%rax,%rcx), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x9, -0x2c(%rbp)
jg 0x6609e
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzwl 0x200(%rax,%rcx,2), %eax
movl $0x9, %ecx
subl -0x2c(%rbp), %ecx
shll %cl, %eax
movl %eax, -0x30(%rbp)
movl $0x9, %ecx
subl -0x2c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x6609c
movl -0x1c(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x66074
jmp 0x6609e
jmp 0x660a0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x66019
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop