// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__jpeg_decode_block_prog_ac(stbi__jpeg*, short*, stbi__huffman*, short*)
static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, stbi__int16 *fac)
{
   int k;
   if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");

   if (j->succ_high == 0) {
      int shift = j->succ_low;

      if (j->eob_run) {
         --j->eob_run;
         return 1;
      }

      k = j->spec_start;
      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;
            zig = stbi__jpeg_dezigzag[k++];
            data[zig] = (short) ((r >> 8) << shift);
         } 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 (r < 15) {
                  j->eob_run = (1 << r);
                  if (r)
                     j->eob_run += stbi__jpeg_get_bits(j, r);
                  --j->eob_run;
                  break;
               }
               k += 16;
            } else {
               k += r;
               zig = stbi__jpeg_dezigzag[k++];
               data[zig] = (short) (stbi__extend_receive(j,s) << shift);
            }
         }
      } while (k <= j->spec_end);
   } else {
      // refinement scan for these AC coefficients

      short bit = (short) (1 << j->succ_low);

      if (j->eob_run) {
         --j->eob_run;
         for (k = j->spec_start; k <= j->spec_end; ++k) {
            short *p = &data[stbi__jpeg_dezigzag[k]];
            if (*p != 0)
               if (stbi__jpeg_get_bit(j))
                  if ((*p & bit)==0) {
                     if (*p > 0)
                        *p += bit;
                     else
                        *p -= bit;
                  }
         }
      } else {
         k = j->spec_start;
         do {
            int r,s;
            int rs = stbi__jpeg_huff_decode(j, hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh
            if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG");
            s = rs & 15;
            r = rs >> 4;
            if (s == 0) {
               if (r < 15) {
                  j->eob_run = (1 << r) - 1;
                  if (r)
                     j->eob_run += stbi__jpeg_get_bits(j, r);
                  r = 64; // force end of block
               } else {
                  // r=15 s=0 should write 16 0s, so we just do
                  // a run of 15 0s and then write s (which is 0),
                  // so we don't have to do anything special here
               }
            } else {
               if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG");
               // sign bit
               if (stbi__jpeg_get_bit(j))
                  s = bit;
               else
                  s = -bit;
            }

            // advance by r
            while (k <= j->spec_end) {
               short *p = &data[stbi__jpeg_dezigzag[k++]];
               if (*p != 0) {
                  if (stbi__jpeg_get_bit(j))
                     if ((*p & bit)==0) {
                        if (*p > 0)
                           *p += bit;
                        else
                           *p -= bit;
                     }
               } else {
                  if (r == 0) {
                     *p = (short) s;
                     break;
                  }
                  --r;
               }
            }
         } while (k <= j->spec_end);
      }
   }
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4734(%rax)
jne 0x2f749
leaq 0x18a35(%rip), %rdi     # 0x48171
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2fc07
movq -0x10(%rbp), %rax
cmpl $0x0, 0x473c(%rax)
jne 0x2f960
movq -0x10(%rbp), %rax
movl 0x4740(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4744(%rax)
je 0x2f793
movq -0x10(%rbp), %rax
movl 0x4744(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x4744(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2fc07
movq -0x10(%rbp), %rax
movl 0x4734(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x10, 0x4724(%rax)
jge 0x2f7b6
movq -0x10(%rbp), %rdi
callq 0x2f500
movq -0x10(%rbp), %rax
movl 0x4720(%rax), %eax
shrl $0x17, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x2f85e
movl -0x3c(%rbp), %eax
sarl $0x4, %eax
andl $0xf, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x3c(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rax
movl 0x4720(%rax), %edx
shll %cl, %edx
movl %edx, %ecx
movl %ecx, 0x4720(%rax)
movl -0x40(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x4724(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x4724(%rax)
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movslq %eax, %rcx
leaq 0x2cc17(%rip), %rax     # 0x5c450
movzbl (%rax,%rcx), %eax
movl %eax, -0x34(%rbp)
movl -0x3c(%rbp), %eax
sarl $0x8, %eax
movl -0x30(%rbp), %ecx
shll %cl, %eax
movw %ax, %dx
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movw %dx, (%rax,%rcx,2)
jmp 0x2f946
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2fc10
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x2f888
leaq 0x187d7(%rip), %rdi     # 0x48052
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2fc07
movl -0x44(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x2f900
cmpl $0xf, -0x3c(%rbp)
jge 0x2f8f5
movl -0x3c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4744(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x2f8e0
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x2ffc0
movl %eax, %ecx
movq -0x10(%rbp), %rax
addl 0x4744(%rax), %ecx
movl %ecx, 0x4744(%rax)
movq -0x10(%rbp), %rax
movl 0x4744(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x4744(%rax)
jmp 0x2f95b
movl -0x2c(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2f944
movl -0x3c(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movslq %eax, %rcx
leaq 0x2cb32(%rip), %rax     # 0x5c450
movzbl (%rax,%rcx), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x2fe40
movl -0x30(%rbp), %ecx
shll %cl, %eax
movw %ax, %dx
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movw %dx, (%rax,%rcx,2)
jmp 0x2f946
jmp 0x2f948
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4738(%rcx), %eax
jle 0x2f7a0
jmp 0x2fc00
movq -0x10(%rbp), %rax
movl 0x4740(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movw %ax, -0x46(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4744(%rax)
je 0x2fa4b
movq -0x10(%rbp), %rax
movl 0x4744(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x4744(%rax)
movq -0x10(%rbp), %rax
movl 0x4734(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4738(%rcx), %eax
jg 0x2fa46
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rdx
leaq 0x2ca88(%rip), %rcx     # 0x5c450
movzbl (%rcx,%rdx), %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
je 0x2fa36
movq -0x10(%rbp), %rdi
callq 0x2ff50
cmpl $0x0, %eax
je 0x2fa34
movq -0x50(%rbp), %rax
movswl (%rax), %eax
movswl -0x46(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x2fa32
movq -0x50(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
jle 0x2fa20
movswl -0x46(%rbp), %edx
movq -0x50(%rbp), %rax
movswl (%rax), %ecx
addl %edx, %ecx
movw %cx, (%rax)
jmp 0x2fa30
movswl -0x46(%rbp), %edx
movq -0x50(%rbp), %rax
movswl (%rax), %ecx
subl %edx, %ecx
movw %cx, (%rax)
jmp 0x2fa32
jmp 0x2fa34
jmp 0x2fa36
jmp 0x2fa38
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2f9a6
jmp 0x2fbfe
movq -0x10(%rbp), %rax
movl 0x4734(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2fc10
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jge 0x2fa82
leaq 0x185dd(%rip), %rdi     # 0x48052
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2fc07
movl -0x5c(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x58(%rbp)
movl -0x5c(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x58(%rbp)
jne 0x2faea
cmpl $0xf, -0x54(%rbp)
jge 0x2fae6
movl -0x54(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
subl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4744(%rax)
cmpl $0x0, -0x54(%rbp)
je 0x2fadd
movq -0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x2ffc0
movl %eax, %ecx
movq -0x10(%rbp), %rax
addl 0x4744(%rax), %ecx
movl %ecx, 0x4744(%rax)
movl $0x40, -0x54(%rbp)
jmp 0x2fae8
jmp 0x2fae8
jmp 0x2fb28
cmpl $0x1, -0x58(%rbp)
je 0x2fb04
leaq 0x1855b(%rip), %rdi     # 0x48052
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x2fc07
movq -0x10(%rbp), %rdi
callq 0x2ff50
cmpl $0x0, %eax
je 0x2fb1b
movswl -0x46(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x2fb26
movswl -0x46(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
jmp 0x2fb28
jmp 0x2fb2a
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4738(%rcx), %eax
jg 0x2fbe7
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rdx
leaq 0x2c8fa(%rip), %rcx     # 0x5c450
movzbl (%rcx,%rdx), %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
je 0x2fbc4
movq -0x10(%rbp), %rdi
callq 0x2ff50
cmpl $0x0, %eax
je 0x2fbc2
movq -0x68(%rbp), %rax
movswl (%rax), %eax
movswl -0x46(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x2fbc0
movq -0x68(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
jle 0x2fbae
movswl -0x46(%rbp), %edx
movq -0x68(%rbp), %rax
movswl (%rax), %ecx
addl %edx, %ecx
movw %cx, (%rax)
jmp 0x2fbbe
movswl -0x46(%rbp), %edx
movq -0x68(%rbp), %rax
movswl (%rax), %ecx
subl %edx, %ecx
movw %cx, (%rax)
jmp 0x2fbc0
jmp 0x2fbc2
jmp 0x2fbe2
cmpl $0x0, -0x54(%rbp)
jne 0x2fbd9
movl -0x58(%rbp), %eax
movw %ax, %cx
movq -0x68(%rbp), %rax
movw %cx, (%rax)
jmp 0x2fbe7
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x2fb2a
jmp 0x2fbe9
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4738(%rcx), %eax
jle 0x2fa58
jmp 0x2fbfe
jmp 0x2fc00
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq