// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdphuff.c
// Function: decode_mcu_AC_first
METHODDEF(jboolean)
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{   
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  int Se = cinfo->Se;
  int Al = cinfo->Al;
  register int s, k, r;
  unsigned int EOBRUN;
  JBLOCKROW block;
  BITREAD_STATE_VARS;
  d_derived_tbl * tbl;

  /* Process restart marker if needed; may have to suspend */
  if (cinfo->restart_interval) {
    if (entropy->restarts_to_go == 0)
      if (! process_restart(cinfo))
	return FALSE;
  }

  /* If we've run out of data, just leave the MCU set to zeroes.
   * This way, we return uniform gray for the remainder of the segment.
   */
  if (! entropy->pub.insufficient_data) {

    /* Load up working state.
     * We can avoid loading/saving bitread state if in an EOB run.
     */
    EOBRUN = entropy->saved.EOBRUN;	/* only part of saved state we need */

    /* There is always only one block per MCU */

    if (EOBRUN > 0)		/* if it's a band of zeroes... */
      EOBRUN--;			/* ...process it now (we do nothing) */
    else {
      BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
      block = MCU_data[0];
      tbl = entropy->ac_derived_tbl;

      for (k = cinfo->Ss; k <= Se; k++) {
	HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
	r = s >> 4;
	s &= 15;
	if (s) {
	  k += r;
	  CHECK_BIT_BUFFER(br_state, s, return FALSE);
	  r = GET_BITS(s);
	  s = HUFF_EXTEND(r, s);
	  /* Scale and output coefficient in natural (dezigzagged) order */
	  (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
	} else {
	  if (r == 15) {	/* ZRL */
	    k += 15;		/* skip 15 zeroes in band */
	  } else {		/* EOBr, run length is 2^r + appended bits */
	    EOBRUN = 1 << r;
	    if (r) {		/* EOBr, r > 0 */
	      CHECK_BIT_BUFFER(br_state, r, return FALSE);
	      r = GET_BITS(r);
	      EOBRUN += r;
	    }
	    EOBRUN--;		/* this band is processed at this moment */
	    break;		/* force end-of-band */
	  }
	}
      }

      BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
    }

    /* Completed MCU, so update state */
    entropy->saved.EOBRUN = EOBRUN;	/* only part of saved state we need */
  }

  /* Account for restart interval (no-op if not using restarts) */
  entropy->restarts_to_go--;

  return TRUE;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq 0x88(%rsp), %rax
movq 0x250(%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x88(%rsp), %rax
movl 0x210(%rax), %eax
movl %eax, 0x74(%rsp)
movq 0x88(%rsp), %rax
movl 0x218(%rax), %eax
movl %eax, 0x70(%rsp)
movq 0x88(%rsp), %rax
cmpl $0x0, 0x170(%rax)
je 0xeb461
movq 0x78(%rsp), %rax
cmpl $0x0, 0x3c(%rax)
jne 0xeb45f
movq 0x88(%rsp), %rdi
callq 0xec320
cmpl $0x0, %eax
jne 0xeb45d
movl $0x0, 0x94(%rsp)
jmp 0xeb869
jmp 0xeb45f
jmp 0xeb461
movq 0x78(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0xeb850
movq 0x78(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x60(%rsp)
cmpl $0x0, 0x60(%rsp)
jbe 0xeb493
movl 0x60(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xeb844
movq 0x88(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x88(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x88(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x78(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x78(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0x80(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x78(%rsp), %rax
movq 0x60(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x88(%rsp), %rax
movl 0x20c(%rax), %eax
movl %eax, 0x68(%rsp)
movl 0x68(%rsp), %eax
cmpl 0x74(%rsp), %eax
jg 0xeb801
cmpl $0x8, 0x4c(%rsp)
jge 0xeb577
movq 0x50(%rsp), %rsi
movl 0x4c(%rsp), %edx
leaq 0x20(%rsp), %rdi
xorl %ecx, %ecx
callq 0xe97e0
cmpl $0x0, %eax
jne 0xeb552
movl $0x0, 0x94(%rsp)
jmp 0xeb869
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x4c(%rsp)
cmpl $0x8, 0x4c(%rsp)
jge 0xeb575
movl $0x1, 0x14(%rsp)
jmp 0xeb5d9
jmp 0xeb577
movq 0x50(%rsp), %rax
movl 0x4c(%rsp), %ecx
subl $0x8, %ecx
movl %ecx, %ecx
sarq %cl, %rax
andl $0xff, %eax
movl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl 0x120(%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, %eax
je 0xeb5d1
movl 0x14(%rsp), %ecx
movl 0x4c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x4c(%rsp)
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movzbl 0x520(%rax,%rcx), %eax
movl %eax, 0x6c(%rsp)
jmp 0xeb621
movl $0x9, 0x14(%rsp)
movq 0x50(%rsp), %rsi
movl 0x4c(%rsp), %edx
movq 0x18(%rsp), %rcx
movl 0x14(%rsp), %r8d
leaq 0x20(%rsp), %rdi
callq 0xe9a60
movl %eax, 0x6c(%rsp)
cmpl $0x0, %eax
jge 0xeb60f
movl $0x0, 0x94(%rsp)
jmp 0xeb869
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x6c(%rsp), %eax
sarl $0x4, %eax
movl %eax, 0x64(%rsp)
movl 0x6c(%rsp), %eax
andl $0xf, %eax
movl %eax, 0x6c(%rsp)
cmpl $0x0, 0x6c(%rsp)
je 0xeb72d
movl 0x64(%rsp), %eax
addl 0x68(%rsp), %eax
movl %eax, 0x68(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0xeb696
movq 0x50(%rsp), %rsi
movl 0x4c(%rsp), %edx
movl 0x6c(%rsp), %ecx
leaq 0x20(%rsp), %rdi
callq 0xe97e0
cmpl $0x0, %eax
jne 0xeb684
movl $0x0, 0x94(%rsp)
jmp 0xeb869
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x50(%rsp), %rax
movl 0x6c(%rsp), %edx
movl 0x4c(%rsp), %ecx
subl %edx, %ecx
movl %ecx, 0x4c(%rsp)
movl %ecx, %ecx
sarq %cl, %rax
movl 0x6c(%rsp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
movslq 0x6c(%rsp), %rdx
leaq 0x4bc0c(%rip), %rcx     # 0x1372e0
cmpl (%rcx,%rdx,4), %eax
jge 0xeb6f2
movl 0x64(%rsp), %eax
movslq 0x6c(%rsp), %rdx
leaq 0x4bc37(%rip), %rcx     # 0x137320
addl (%rcx,%rdx,4), %eax
movl %eax, 0xc(%rsp)
jmp 0xeb6fa
movl 0x64(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
movl 0x70(%rsp), %ecx
shll %cl, %eax
movw %ax, %dx
movq 0x58(%rsp), %rax
movslq 0x68(%rsp), %rsi
leaq 0x4be40(%rip), %rcx     # 0x137560
movslq (%rcx,%rsi,4), %rcx
movw %dx, (%rax,%rcx,2)
jmp 0xeb7ef
cmpl $0xf, 0x64(%rsp)
jne 0xeb744
movl 0x68(%rsp), %eax
addl $0xf, %eax
movl %eax, 0x68(%rsp)
jmp 0xeb7ed
movl 0x64(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x60(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0xeb7e0
movl 0x4c(%rsp), %eax
cmpl 0x64(%rsp), %eax
jge 0xeb7a6
movq 0x50(%rsp), %rsi
movl 0x4c(%rsp), %edx
movl 0x64(%rsp), %ecx
leaq 0x20(%rsp), %rdi
callq 0xe97e0
cmpl $0x0, %eax
jne 0xeb794
movl $0x0, 0x94(%rsp)
jmp 0xeb869
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x50(%rsp), %rax
movl 0x64(%rsp), %edx
movl 0x4c(%rsp), %ecx
subl %edx, %ecx
movl %ecx, 0x4c(%rsp)
movl %ecx, %ecx
sarq %cl, %rax
movl 0x64(%rsp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
addl 0x60(%rsp), %eax
movl %eax, 0x60(%rsp)
movl 0x60(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xeb801
jmp 0xeb7ef
jmp 0xeb7f1
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0xeb513
movq 0x20(%rsp), %rcx
movq 0x88(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rcx
movq 0x88(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x50(%rsp), %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x18(%rax)
movl 0x4c(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0x20(%rax)
movl 0x60(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x78(%rsp), %rax
movl 0x3c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x3c(%rax)
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopl (%rax,%rax)