// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdphuff.c
// Function: decode_mcu_DC_first
METHODDEF(jboolean)
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{   
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  int Al = cinfo->Al;
  register int s, r;
  int blkn, ci;
  JBLOCKROW block;
  BITREAD_STATE_VARS;
  savable_state state;
  d_derived_tbl * tbl;
  jpeg_component_info * compptr;

  /* 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 */
    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
    ASSIGN_STATE(state, entropy->saved);

    /* Outer loop handles each block in the MCU */

    for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
      block = MCU_data[blkn];
      ci = cinfo->MCU_membership[blkn];
      compptr = cinfo->cur_comp_info[ci];
      tbl = entropy->derived_tbls[compptr->dc_tbl_no];

      /* Decode a single block's worth of coefficients */

      /* Section F.2.2.1: decode the DC coefficient difference */
      HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
      if (s) {
	CHECK_BIT_BUFFER(br_state, s, return FALSE);
	r = GET_BITS(s);
	s = HUFF_EXTEND(r, s);
      }

      /* Convert DC difference to actual value, update last_dc_val */
      s += state.last_dc_val[ci];
      state.last_dc_val[ci] = s;
      /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */
      (*block)[0] = (JCOEF) (s << Al);
    }

    /* Completed MCU, so update state */
    BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
    ASSIGN_STATE(entropy->saved, state);
  }

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

  return TRUE;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq 0xa8(%rsp), %rax
movq 0x250(%rax), %rax
movq %rax, 0x98(%rsp)
movq 0xa8(%rsp), %rax
movl 0x218(%rax), %eax
movl %eax, 0x94(%rsp)
movq 0xa8(%rsp), %rax
cmpl $0x0, 0x170(%rax)
je 0xeafc8
movq 0x98(%rsp), %rax
cmpl $0x0, 0x3c(%rax)
jne 0xeafc6
movq 0xa8(%rsp), %rdi
callq 0xec320
cmpl $0x0, %eax
jne 0xeafc4
movl $0x0, 0xb4(%rsp)
jmp 0xeb3b3
jmp 0xeafc6
jmp 0xeafc8
movq 0x98(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0xeb397
movq 0xa8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xa8(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movq 0xa8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x98(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x6c(%rsp)
movq 0x98(%rsp), %rax
movq 0x28(%rax), %rcx
movq %rcx, 0x2c(%rsp)
movq 0x30(%rax), %rcx
movq %rcx, 0x34(%rsp)
movl 0x38(%rax), %eax
movl %eax, 0x3c(%rsp)
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
movq 0xa8(%rsp), %rcx
cmpl 0x1e0(%rcx), %eax
jge 0xeb32d
movq 0xa0(%rsp), %rax
movslq 0x88(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x78(%rsp)
movq 0xa8(%rsp), %rax
movslq 0x88(%rsp), %rcx
movl 0x1e4(%rax,%rcx,4), %eax
movl %eax, 0x84(%rsp)
movq 0xa8(%rsp), %rax
movslq 0x84(%rsp), %rcx
movq 0x1b8(%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rax
movq 0x18(%rsp), %rcx
movslq 0x14(%rcx), %rcx
movq 0x40(%rax,%rcx,8), %rax
movq %rax, 0x20(%rsp)
cmpl $0x8, 0x6c(%rsp)
jge 0xeb13c
movq 0x70(%rsp), %rsi
movl 0x6c(%rsp), %edx
leaq 0x40(%rsp), %rdi
xorl %ecx, %ecx
callq 0xe97e0
cmpl $0x0, %eax
jne 0xeb117
movl $0x0, 0xb4(%rsp)
jmp 0xeb3b3
movq 0x50(%rsp), %rax
movq %rax, 0x70(%rsp)
movl 0x58(%rsp), %eax
movl %eax, 0x6c(%rsp)
cmpl $0x8, 0x6c(%rsp)
jge 0xeb13a
movl $0x1, 0x14(%rsp)
jmp 0xeb1a1
jmp 0xeb13c
movq 0x70(%rsp), %rax
movl 0x6c(%rsp), %ecx
subl $0x8, %ecx
movl %ecx, %ecx
sarq %cl, %rax
andl $0xff, %eax
movl %eax, 0x10(%rsp)
movq 0x20(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl 0x120(%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, %eax
je 0xeb199
movl 0x14(%rsp), %ecx
movl 0x6c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x6c(%rsp)
movq 0x20(%rsp), %rax
movslq 0x10(%rsp), %rcx
movzbl 0x520(%rax,%rcx), %eax
movl %eax, 0x90(%rsp)
jmp 0xeb1ec
movl $0x9, 0x14(%rsp)
movq 0x70(%rsp), %rsi
movl 0x6c(%rsp), %edx
movq 0x20(%rsp), %rcx
movl 0x14(%rsp), %r8d
leaq 0x40(%rsp), %rdi
callq 0xe9a60
movl %eax, 0x90(%rsp)
cmpl $0x0, %eax
jge 0xeb1da
movl $0x0, 0xb4(%rsp)
jmp 0xeb3b3
movq 0x50(%rsp), %rax
movq %rax, 0x70(%rsp)
movl 0x58(%rsp), %eax
movl %eax, 0x6c(%rsp)
cmpl $0x0, 0x90(%rsp)
je 0xeb2cf
movl 0x6c(%rsp), %eax
cmpl 0x90(%rsp), %eax
jge 0xeb248
movq 0x70(%rsp), %rsi
movl 0x6c(%rsp), %edx
movl 0x90(%rsp), %ecx
leaq 0x40(%rsp), %rdi
callq 0xe97e0
cmpl $0x0, %eax
jne 0xeb236
movl $0x0, 0xb4(%rsp)
jmp 0xeb3b3
movq 0x50(%rsp), %rax
movq %rax, 0x70(%rsp)
movl 0x58(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x70(%rsp), %rax
movl 0x90(%rsp), %edx
movl 0x6c(%rsp), %ecx
subl %edx, %ecx
movl %ecx, 0x6c(%rsp)
movl %ecx, %ecx
sarq %cl, %rax
movl 0x90(%rsp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, 0x8c(%rsp)
movl 0x8c(%rsp), %eax
movslq 0x90(%rsp), %rdx
leaq 0x4c04b(%rip), %rcx     # 0x1372e0
cmpl (%rcx,%rdx,4), %eax
jge 0xeb2b9
movl 0x8c(%rsp), %eax
movslq 0x90(%rsp), %rdx
leaq 0x4c070(%rip), %rcx     # 0x137320
addl (%rcx,%rdx,4), %eax
movl %eax, 0xc(%rsp)
jmp 0xeb2c4
movl 0x8c(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x90(%rsp)
movslq 0x84(%rsp), %rax
movl 0x30(%rsp,%rax,4), %eax
addl 0x90(%rsp), %eax
movl %eax, 0x90(%rsp)
movl 0x90(%rsp), %ecx
movslq 0x84(%rsp), %rax
movl %ecx, 0x30(%rsp,%rax,4)
movl 0x90(%rsp), %eax
movl 0x94(%rsp), %ecx
shll %cl, %eax
movw %ax, %cx
movq 0x78(%rsp), %rax
movw %cx, (%rax)
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0xeb05c
movq 0x40(%rsp), %rcx
movq 0xa8(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, (%rax)
movq 0x48(%rsp), %rcx
movq 0xa8(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x70(%rsp), %rcx
movq 0x98(%rsp), %rax
movq %rcx, 0x18(%rax)
movl 0x6c(%rsp), %ecx
movq 0x98(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x98(%rsp), %rax
movq 0x2c(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq 0x34(%rsp), %rcx
movq %rcx, 0x30(%rax)
movl 0x3c(%rsp), %ecx
movl %ecx, 0x38(%rax)
movq 0x98(%rsp), %rax
movl 0x3c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x3c(%rax)
movl $0x1, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)