// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdphuff.c
// Function: decode_mcu_DC_refine
METHODDEF(jboolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{   
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  int p1 = 1 << cinfo->Al;	/* 1 in the bit position being coded */
  int blkn;
  JBLOCKROW block;
  BITREAD_STATE_VARS;

  /* 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;
  }

  /* Not worth the cycles to check insufficient_data here,
   * since we will not change the data anyway if we read zeroes.
   */

  /* Load up working state */
  BITREAD_LOAD_STATE(cinfo,entropy->bitstate);

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

  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
    block = MCU_data[blkn];

    /* Encoded data is simply the next bit of the two's-complement DC value */
    CHECK_BIT_BUFFER(br_state, 1, return FALSE);
    if (GET_BITS(1))
      (*block)[0] |= p1;
    /* Note: since we use |=, repeating the assignment later is safe */
  }

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

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

  return TRUE;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq 0x58(%rsp), %rax
movq 0x250(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rax
movl 0x218(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x44(%rsp)
movq 0x58(%rsp), %rax
cmpl $0x0, 0x170(%rax)
je 0xeb8ee
movq 0x48(%rsp), %rax
cmpl $0x0, 0x3c(%rax)
jne 0xeb8ec
movq 0x58(%rsp), %rdi
callq 0xec320
cmpl $0x0, %eax
jne 0xeb8ea
movl $0x0, 0x64(%rsp)
jmp 0xeba37
jmp 0xeb8ec
jmp 0xeb8ee
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x2c(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl 0x1e0(%rcx), %eax
jge 0xeb9e5
movq 0x50(%rsp), %rax
movslq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
cmpl $0x1, 0x2c(%rsp)
jge 0xeb9a5
movq 0x30(%rsp), %rsi
movl 0x2c(%rsp), %edx
movq %rsp, %rdi
movl $0x1, %ecx
callq 0xe97e0
cmpl $0x0, %eax
jne 0xeb993
movl $0x0, 0x64(%rsp)
jmp 0xeba37
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x30(%rsp), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movl %ecx, 0x2c(%rsp)
movl %ecx, %ecx
sarq %cl, %rax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xeb9d3
movl 0x44(%rsp), %edx
movq 0x38(%rsp), %rax
movswl (%rax), %ecx
orl %edx, %ecx
movw %cx, (%rax)
jmp 0xeb9d5
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xeb93c
movq (%rsp), %rcx
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rcx
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x30(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x18(%rax)
movl 0x2c(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x48(%rsp), %rax
movl 0x3c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x3c(%rax)
movl $0x1, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq