// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__jpeg_decode_block(stbi__jpeg*, short*, stbi__huffman*, stbi__huffman*, short*, int, unsigned char*)
static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi_uc *dequant)
{
   int diff,dc,k;
   int t;

   if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
   t = stbi__jpeg_huff_decode(j, hdc);
   if (t < 0) return stbi__err("bad huffman code","Corrupt JPEG");

   // 0 all the ac values now so we can do it 32-bits at a time
   memset(data,0,64*sizeof(data[0]));

   diff = t ? stbi__extend_receive(j, t) : 0;
   dc = j->img_comp[b].dc_pred + diff;
   j->img_comp[b].dc_pred = dc;
   data[0] = (short) (dc * dequant[0]);

   // decode AC components, see JPEG spec
   k = 1;
   do {
      unsigned int zig;
      int c,r,s;
      if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
      c = (j->code_buffer >> (32 - FAST_BITS)) & ((1 << FAST_BITS)-1);
      r = fac[c];
      if (r) { // fast-AC path
         k += (r >> 4) & 15; // run
         s = r & 15; // combined length
         j->code_buffer <<= s;
         j->code_bits -= s;
         // decode into unzigzag'd location
         zig = stbi__jpeg_dezigzag[k++];
         data[zig] = (short) ((r >> 8) * dequant[zig]);
      } else {
         int rs = stbi__jpeg_huff_decode(j, hac);
         if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG");
         s = rs & 15;
         r = rs >> 4;
         if (s == 0) {
            if (rs != 0xf0) break; // end block
            k += 16;
         } else {
            k += r;
            // decode into unzigzag'd location
            zig = stbi__jpeg_dezigzag[k++];
            data[zig] = (short) (stbi__extend_receive(j,s) * dequant[zig]);
         }
      }
   } while (k < 64);
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x10, 0x4724(%rax)
jge 0x2f2ba
movq -0x10(%rbp), %rdi
callq 0x2f500
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2fc10
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x2f2e4
leaq 0x18d7b(%rip), %rdi     # 0x48052
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2f4f4
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x5230
cmpl $0x0, -0x44(%rbp)
je 0x2f30b
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x2fe40
movl %eax, -0x5c(%rbp)
jmp 0x2f312
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x2f312
movl -0x5c(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x45a0, %rax           # imm = 0x45A0
movslq -0x34(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
addq $0x45a0, %rax           # imm = 0x45A0
movslq -0x34(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movl -0x3c(%rbp), %eax
movq 0x10(%rbp), %rcx
movzbl (%rcx), %ecx
imull %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movl $0x1, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x10, 0x4724(%rax)
jge 0x2f385
movq -0x10(%rbp), %rdi
callq 0x2f500
movq -0x10(%rbp), %rax
movl 0x4720(%rax), %eax
shrl $0x17, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x2f43a
movl -0x50(%rbp), %eax
sarl $0x4, %eax
andl $0xf, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x50(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %ecx
movq -0x10(%rbp), %rax
movl 0x4720(%rax), %edx
shll %cl, %edx
movl %edx, %ecx
movl %ecx, 0x4720(%rax)
movl -0x54(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x4724(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x4724(%rax)
movl -0x40(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movslq %eax, %rcx
leaq 0x2d044(%rip), %rax     # 0x5c450
movzbl (%rax,%rcx), %eax
movl %eax, -0x48(%rbp)
movl -0x50(%rbp), %eax
sarl $0x8, %eax
movq 0x10(%rbp), %rcx
movl -0x48(%rbp), %edx
movzbl (%rcx,%rdx), %ecx
imull %ecx, %eax
movw %ax, %dx
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
movw %dx, (%rax,%rcx,2)
jmp 0x2f4e1
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2fc10
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jge 0x2f464
leaq 0x18bfb(%rip), %rdi     # 0x48052
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2f4f4
movl -0x58(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0x2f492
cmpl $0xf0, -0x58(%rbp)
je 0x2f487
jmp 0x2f4ed
movl -0x40(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x40(%rbp)
jmp 0x2f4df
movl -0x50(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
movslq %eax, %rcx
leaq 0x2cfa0(%rip), %rax     # 0x5c450
movzbl (%rax,%rcx), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x2fe40
movq 0x10(%rbp), %rcx
movl -0x48(%rbp), %edx
movzbl (%rcx,%rdx), %ecx
imull %ecx, %eax
movw %ax, %dx
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
movw %dx, (%rax,%rcx,2)
jmp 0x2f4e1
jmp 0x2f4e3
cmpl $0x40, -0x40(%rbp)
jl 0x2f36f
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)