// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__compute_huffman_codes(stbi__zbuf*)
static int stbi__compute_huffman_codes(stbi__zbuf *a)
{
   static stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
   stbi__zhuffman z_codelength;
   stbi_uc lencodes[286+32+137];//padding for maximum single op
   stbi_uc codelength_sizes[19];
   int i,n;

   int hlit  = stbi__zreceive(a,5) + 257;
   int hdist = stbi__zreceive(a,5) + 1;
   int hclen = stbi__zreceive(a,4) + 4;

   memset(codelength_sizes, 0, sizeof(codelength_sizes));
   for (i=0; i < hclen; ++i) {
      int s = stbi__zreceive(a,3);
      codelength_sizes[length_dezigzag[i]] = (stbi_uc) s;
   }
   if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0;

   n = 0;
   while (n < hlit + hdist) {
      int c = stbi__zhuffman_decode(a, &z_codelength);
      if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG");
      if (c < 16)
         lencodes[n++] = (stbi_uc) c;
      else if (c == 16) {
         c = stbi__zreceive(a,2)+3;
         memset(lencodes+n, lencodes[n-1], c);
         n += c;
      } else if (c == 17) {
         c = stbi__zreceive(a,3)+3;
         memset(lencodes+n, 0, c);
         n += c;
      } else {
         STBI_ASSERT(c == 18);
         c = stbi__zreceive(a,7)+11;
         memset(lencodes+n, 0, c);
         n += c;
      }
   }
   if (n != hlit+hdist) return stbi__err("bad codelengths","Corrupt PNG");
   if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0;
   if (!stbi__zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0;
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa00, %rsp            # imm = 0xA00
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x5, %esi
callq 0x35bb0
addl $0x101, %eax            # imm = 0x101
movl %eax, -0x9ec(%rbp)
movq -0x10(%rbp), %rdi
movl $0x5, %esi
callq 0x35bb0
addl $0x1, %eax
movl %eax, -0x9f0(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x35bb0
addl $0x4, %eax
movl %eax, -0x9f4(%rbp)
leaq -0x9e0(%rbp), %rdi
xorl %esi, %esi
movl $0x13, %edx
callq 0x5230
movl $0x0, -0x9e4(%rbp)
movl -0x9e4(%rbp), %eax
cmpl -0x9f4(%rbp), %eax
jge 0x36297
movq -0x10(%rbp), %rdi
movl $0x3, %esi
callq 0x35bb0
movl %eax, -0x9f8(%rbp)
movl -0x9f8(%rbp), %eax
movb %al, %cl
movslq -0x9e4(%rbp), %rdx
leaq 0x262a5(%rip), %rax     # 0x5c520
movzbl (%rax,%rdx), %eax
movb %cl, -0x9e0(%rbp,%rax)
movl -0x9e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9e4(%rbp)
jmp 0x36243
leaq -0x9e0(%rbp), %rsi
leaq -0x7f4(%rbp), %rdi
movl $0x13, %edx
callq 0x35ec0
cmpl $0x0, %eax
jne 0x362c0
movl $0x0, -0x4(%rbp)
jmp 0x36513
movl $0x0, -0x9e8(%rbp)
movl -0x9e8(%rbp), %eax
movl -0x9ec(%rbp), %ecx
addl -0x9f0(%rbp), %ecx
cmpl %ecx, %eax
jge 0x36488
movq -0x10(%rbp), %rdi
leaq -0x7f4(%rbp), %rsi
callq 0x36a40
movl %eax, -0x9fc(%rbp)
cmpl $0x0, -0x9fc(%rbp)
jl 0x3630c
cmpl $0x13, -0x9fc(%rbp)
jl 0x36320
leaq 0x1246f(%rip), %rdi     # 0x48782
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x36513
cmpl $0x10, -0x9fc(%rbp)
jge 0x36350
movl -0x9fc(%rbp), %eax
movb %al, %cl
movl -0x9e8(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x9e8(%rbp)
cltq
movb %cl, -0x9c0(%rbp,%rax)
jmp 0x36483
cmpl $0x10, -0x9fc(%rbp)
jne 0x363ba
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x35bb0
addl $0x3, %eax
movl %eax, -0x9fc(%rbp)
leaq -0x9c0(%rbp), %rdi
movslq -0x9e8(%rbp), %rax
addq %rax, %rdi
movl -0x9e8(%rbp), %eax
subl $0x1, %eax
cltq
movzbl -0x9c0(%rbp,%rax), %eax
movslq -0x9fc(%rbp), %rdx
movzbl %al, %esi
callq 0x5230
movl -0x9fc(%rbp), %eax
addl -0x9e8(%rbp), %eax
movl %eax, -0x9e8(%rbp)
jmp 0x36481
cmpl $0x11, -0x9fc(%rbp)
jne 0x3640d
movq -0x10(%rbp), %rdi
movl $0x3, %esi
callq 0x35bb0
addl $0x3, %eax
movl %eax, -0x9fc(%rbp)
leaq -0x9c0(%rbp), %rdi
movslq -0x9e8(%rbp), %rax
addq %rax, %rdi
movslq -0x9fc(%rbp), %rdx
xorl %esi, %esi
callq 0x5230
movl -0x9fc(%rbp), %eax
addl -0x9e8(%rbp), %eax
movl %eax, -0x9e8(%rbp)
jmp 0x3647f
cmpl $0x12, -0x9fc(%rbp)
jne 0x36418
jmp 0x36437
leaq 0x1239e(%rip), %rdi     # 0x487bd
leaq 0x11c8f(%rip), %rsi     # 0x480b5
movl $0xe8b, %edx            # imm = 0xE8B
leaq 0x12393(%rip), %rcx     # 0x487c5
callq 0x52c0
movq -0x10(%rbp), %rdi
movl $0x7, %esi
callq 0x35bb0
addl $0xb, %eax
movl %eax, -0x9fc(%rbp)
leaq -0x9c0(%rbp), %rdi
movslq -0x9e8(%rbp), %rax
addq %rax, %rdi
movslq -0x9fc(%rbp), %rdx
xorl %esi, %esi
callq 0x5230
movl -0x9fc(%rbp), %eax
addl -0x9e8(%rbp), %eax
movl %eax, -0x9e8(%rbp)
jmp 0x36481
jmp 0x36483
jmp 0x362ca
movl -0x9e8(%rbp), %eax
movl -0x9ec(%rbp), %ecx
addl -0x9f0(%rbp), %ecx
cmpl %ecx, %eax
je 0x364af
leaq 0x122dd(%rip), %rdi     # 0x48782
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x36513
movq -0x10(%rbp), %rdi
addq $0x34, %rdi
leaq -0x9c0(%rbp), %rsi
movl -0x9ec(%rbp), %edx
callq 0x35ec0
cmpl $0x0, %eax
jne 0x364d7
movl $0x0, -0x4(%rbp)
jmp 0x36513
movq -0x10(%rbp), %rdi
addq $0x818, %rdi            # imm = 0x818
leaq -0x9c0(%rbp), %rsi
movslq -0x9ec(%rbp), %rax
addq %rax, %rsi
movl -0x9f0(%rbp), %edx
callq 0x35ec0
cmpl $0x0, %eax
jne 0x3650c
movl $0x0, -0x4(%rbp)
jmp 0x36513
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa00, %rsp            # imm = 0xA00
popq %rbp
retq
nop