// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jdphuff.c
// Function: decode_mcu_AC_refine
METHODDEF(jboolean)
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{   
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  int Se = cinfo->Se;
  int p1 = 1 << cinfo->Al;	/* 1 in the bit position being coded */
  int m1 = (-1) << cinfo->Al;	/* -1 in the bit position being coded */
  register int s, k, r;
  unsigned int EOBRUN;
  JBLOCKROW block;
  JCOEFPTR thiscoef;
  BITREAD_STATE_VARS;
  d_derived_tbl * tbl;
  int num_newnz;
  int newnz_pos[DCTSIZE2];

  /* 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, don't modify the MCU.
   */
  if (! entropy->pub.insufficient_data) {

    /* Load up working state */
    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
    EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */

    /* There is always only one block per MCU */
    block = MCU_data[0];
    tbl = entropy->ac_derived_tbl;

    /* If we are forced to suspend, we must undo the assignments to any newly
     * nonzero coefficients in the block, because otherwise we'd get confused
     * next time about which coefficients were already nonzero.
     * But we need not undo addition of bits to already-nonzero coefficients;
     * instead, we can test the current bit to see if we already did it.
     */
    num_newnz = 0;

    /* initialize coefficient loop counter to start of band */
    k = cinfo->Ss;

    if (EOBRUN == 0) {
      for (; k <= Se; k++) {
	HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
	r = s >> 4;
	s &= 15;
	if (s) {
	  if (s != 1)		/* size of new coef should always be 1 */
	    WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
	  CHECK_BIT_BUFFER(br_state, 1, goto undoit);
	  if (GET_BITS(1))
	    s = p1;		/* newly nonzero coef is positive */
	  else
	    s = m1;		/* newly nonzero coef is negative */
	} else {
	  if (r != 15) {
	    EOBRUN = 1 << r;	/* EOBr, run length is 2^r + appended bits */
	    if (r) {
	      CHECK_BIT_BUFFER(br_state, r, goto undoit);
	      r = GET_BITS(r);
	      EOBRUN += r;
	    }
	    break;		/* rest of block is handled by EOB logic */
	  }
	  /* note s = 0 for processing ZRL */
	}
	/* Advance over already-nonzero coefs and r still-zero coefs,
	 * appending correction bits to the nonzeroes.  A correction bit is 1
	 * if the absolute value of the coefficient must be increased.
	 */
	do {
	  thiscoef = *block + jpeg_natural_order[k];
	  if (*thiscoef != 0) {
	    CHECK_BIT_BUFFER(br_state, 1, goto undoit);
	    if (GET_BITS(1)) {
	      if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
		if (*thiscoef >= 0)
		  *thiscoef += p1;
		else
		  *thiscoef += m1;
	      }
	    }
	  } else {
	    if (--r < 0)
	      break;		/* reached target zero coefficient */
	  }
	  k++;
	} while (k <= Se);
	if (s) {
	  int pos = jpeg_natural_order[k];
	  /* Output newly nonzero coefficient */
	  (*block)[pos] = (JCOEF) s;
	  /* Remember its position in case we have to suspend */
	  newnz_pos[num_newnz++] = pos;
	}
      }
    }

    if (EOBRUN > 0) {
      /* Scan any remaining coefficient positions after the end-of-band
       * (the last newly nonzero coefficient, if any).  Append a correction
       * bit to each already-nonzero coefficient.  A correction bit is 1
       * if the absolute value of the coefficient must be increased.
       */
      for (; k <= Se; k++) {
	thiscoef = *block + jpeg_natural_order[k];
	if (*thiscoef != 0) {
	  CHECK_BIT_BUFFER(br_state, 1, goto undoit);
	  if (GET_BITS(1)) {
	    if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
	      if (*thiscoef >= 0)
		*thiscoef += p1;
	      else
		*thiscoef += m1;
	    }
	  }
	}
      }
      /* Count one block completed in EOB run */
      EOBRUN--;
    }

    /* Completed MCU, so update state */
    BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
    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;

undoit:
  /* Re-zero any output coefficients that we made newly nonzero */
  while (num_newnz > 0)
    (*block)[newnz_pos[--num_newnz]] = 0;

  return FALSE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %r13
movq %rdi, %r14
movb 0x218(%rdi), %cl
pushq $0x1
popq %rbx
movl %ebx, %edx
shll %cl, %edx
pushq $-0x1
popq %rax
shll %cl, %eax
movl %eax, 0x24(%rsp)
movq 0x250(%rdi), %r15
movslq 0x210(%rdi), %rsi
cmpl $0x0, 0x170(%rdi)
movl %edx, 0xc(%rsp)
movq %rsi, 0x18(%rsp)
je 0x72e92
cmpl $0x0, 0x3c(%r15)
jne 0x72e92
movq %r14, %rdi
callq 0x73255
movq 0x18(%rsp), %rsi
movl 0xc(%rsp), %edx
testl %eax, %eax
je 0x7323f
cmpl $0x0, 0x10(%r15)
jne 0x72f9d
movq %r14, 0x48(%rsp)
movq 0x28(%r14), %rax
movq (%rax), %rcx
movq %rcx, 0x28(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%r15), %r9
movl 0x20(%r15), %r12d
movl 0x28(%r15), %eax
movq (%r13), %rbx
movq %r14, 0x58(%rsp)
movl 0x20c(%r14), %ebp
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
testl %eax, %eax
movq %r15, 0x60(%rsp)
je 0x72fa6
movslq %ebp, %r14
leaq 0x28ae9(%rip), %rbp     # 0x9b9e0
pushq $0x1
popq %r13
cmpq %rsi, %r14
jg 0x72f68
movslq (%rbp,%r14,4), %r15
cmpw $0x0, (%rbx,%r15,2)
je 0x72f63
testl %r12d, %r12d
jg 0x72f40
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x71e39
testl %eax, %eax
je 0x73226
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r12d
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rsi
decl %r12d
btq %r12, %r9
jae 0x72f63
movswl (%rbx,%r15,2), %eax
testl %eax, %edx
jne 0x72f63
testw %ax, %ax
movl %edx, %ecx
cmovsl 0x24(%rsp), %ecx
addl %eax, %ecx
movw %cx, (%rbx,%r15,2)
incq %r14
jmp 0x72efb
movq 0x10(%rsp), %rdx
decl %edx
movq 0x28(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq %rax, (%rcx)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rcx)
movq 0x60(%rsp), %r15
movq %r9, 0x18(%r15)
movl %r12d, 0x20(%r15)
movl %edx, 0x28(%r15)
pushq $0x1
popq %rbx
decl 0x3c(%r15)
jmp 0x73241
movq 0x60(%r15), %r14
leal 0x1(%rsi), %eax
movl %eax, 0x54(%rsp)
movl $0x0, 0x8(%rsp)
movq %r14, 0x68(%rsp)
cmpl %esi, %ebp
jg 0x7321f
cmpl $0x7, %r12d
jg 0x72ffe
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x71e39
testl %eax, %eax
je 0x73226
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r12d
pushq $0x1
popq %r8
cmpl $0x8, %r12d
movl 0xc(%rsp), %edx
jl 0x7302c
leal -0x8(%r12), %ecx
movq %r9, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%r14,%rcx,4), %ecx
testl %ecx, %ecx
je 0x73028
subl %ecx, %r12d
movzbl 0x520(%r14,%rax), %eax
jmp 0x73055
pushq $0x9
popq %r8
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r12d, %edx
movq %r14, %rcx
callq 0x71f5f
testl %eax, %eax
js 0x73226
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r12d
movl 0xc(%rsp), %edx
movl %eax, %r13d
shrl $0x4, %r13d
movl %eax, %ecx
andl $0xf, %ecx
movq 0x18(%rsp), %rsi
leaq 0x28973(%rip), %rdi     # 0x9b9e0
je 0x730ed
cmpl $0x1, %ecx
je 0x7309f
movq 0x58(%rsp), %rdi
movq (%rdi), %rax
movl $0x76, 0x28(%rax)
pushq $-0x1
popq %rsi
movq %r9, %r14
callq *0x8(%rax)
leaq 0x2894d(%rip), %rdi     # 0x9b9e0
movq %r14, %r9
movq 0x18(%rsp), %rsi
movl 0xc(%rsp), %edx
testl %r12d, %r12d
jg 0x730d9
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r12d, %edx
pushq $0x1
popq %rcx
callq 0x71e39
testl %eax, %eax
je 0x73226
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r12d
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rsi
leaq 0x28907(%rip), %rdi     # 0x9b9e0
decl %r12d
btq %r12, %r9
movl %edx, %eax
cmovael 0x24(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x730ff
movl $0x0, 0x10(%rsp)
cmpl $0xf, %r13d
jne 0x731b7
movslq %ebp, %r14
decq %r14
movslq 0x4(%rdi,%r14,4), %r15
cmpw $0x0, (%rbx,%r15,2)
je 0x73171
testl %r12d, %r12d
jg 0x7314c
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r12d, %edx
pushq $0x1
popq %rcx
callq 0x71e39
testl %eax, %eax
je 0x73226
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r12d
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rsi
leaq 0x28894(%rip), %rdi     # 0x9b9e0
decl %r12d
btq %r12, %r9
jae 0x73179
movswl (%rbx,%r15,2), %eax
testl %eax, %edx
jne 0x73179
testw %ax, %ax
movl %edx, %ecx
cmovsl 0x24(%rsp), %ecx
addl %eax, %ecx
movw %cx, (%rbx,%r15,2)
jmp 0x73179
testl %r13d, %r13d
jle 0x73187
decl %r13d
incl %ebp
incq %r14
cmpq %rsi, %r14
jl 0x73105
movl 0x54(%rsp), %ebp
movl 0x10(%rsp), %ecx
testl %ecx, %ecx
movq 0x68(%rsp), %r14
je 0x731b0
movslq %ebp, %rax
movslq (%rdi,%rax,4), %rax
movw %cx, (%rbx,%rax,2)
movl 0x8(%rsp), %edi
movslq %edi, %rcx
incl %edi
movl %edi, 0x8(%rsp)
movl %eax, 0x70(%rsp,%rcx,4)
incl %ebp
jmp 0x72fbe
pushq $0x1
popq %rdi
movl %r13d, %ecx
shll %cl, %edi
movq %rdi, 0x10(%rsp)
cmpl $0x10, %eax
jb 0x72eed
cmpl %r13d, %r12d
jge 0x731fc
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x71e39
testl %eax, %eax
je 0x73226
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r12d
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rsi
subl %r13d, %r12d
movq %r9, %rax
movl %r12d, %ecx
sarq %cl, %rax
movq 0x10(%rsp), %rdi
leal -0x1(%rdi), %ecx
andl %eax, %ecx
addl %ecx, %edi
movq %rdi, 0x10(%rsp)
jne 0x72eed
xorl %edx, %edx
jmp 0x72f6f
movl 0x8(%rsp), %eax
movl %eax, %eax
testl %eax, %eax
jle 0x7323f
movslq 0x6c(%rsp,%rax,4), %rcx
decq %rax
andw $0x0, (%rbx,%rcx,2)
jmp 0x7322c
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq