// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rdi, %rbx
movb 0x218(%rdi), %cl
movl $0x1, %edx
shll %cl, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %eax, 0x14(%rsp)
movq 0x250(%rdi), %r14
movslq 0x210(%rdi), %rsi
cmpl $0x0, 0x170(%rdi)
movl %edx, 0x4(%rsp)
movq %rsi, 0x8(%rsp)
je 0x7fea0
cmpl $0x0, 0x3c(%r14)
jne 0x7fea0
movq %rbx, %rdi
callq 0x802e6
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edx
testl %eax, %eax
je 0x80201
cmpl $0x0, 0x10(%r14)
jne 0x80232
movq %rbx, 0x48(%rsp)
movq 0x28(%rbx), %rax
movq (%rax), %rcx
movq %rcx, 0x28(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%r14), %r9
movl 0x20(%r14), %r15d
movl 0x28(%r14), %ecx
movq %rbx, %rax
movq (%r12), %rbx
movq %rax, 0x50(%rsp)
movl 0x20c(%rax), %r12d
movq %rcx, 0x18(%rsp)
testl %ecx, %ecx
setne %al
cmpl %esi, %r12d
setg %cl
orb %al, %cl
movq %r14, 0x58(%rsp)
je 0x7ffad
movl $0x0, 0x10(%rsp)
cmpl $0x0, 0x18(%rsp)
je 0x80205
cmpl %esi, %r12d
jg 0x7ff9f
movslq %r12d, %r13
shlq $0x2, %r13
addq 0x65065(%rip), %r13     # 0xe4f90
subl %r12d, %esi
incl %esi
xorl %ebp, %ebp
movslq (%r13,%rbp,4), %r14
cmpw $0x0, (%rbx,%r14,2)
je 0x7ff98
testl %r15d, %r15d
jg 0x7ff75
movq %rsi, %r12
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x80252
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x4(%rsp), %edx
movq %r12, %rsi
decl %r15d
btq %r15, %r9
jae 0x7ff98
movswl (%rbx,%r14,2), %eax
testl %eax, %edx
jne 0x7ff98
testw %ax, %ax
movl %edx, %ecx
cmovsl 0x14(%rsp), %ecx
addl %eax, %ecx
movw %cx, (%rbx,%r14,2)
incq %rbp
cmpl %ebp, %esi
jne 0x7ff32
movq 0x18(%rsp), %rax
decl %eax
movl %eax, %edx
jmp 0x80207
movq 0x60(%r14), %r13
movl $0x0, 0x10(%rsp)
movq %r13, 0x60(%rsp)
cmpl $0x7, %r15d
jg 0x80000
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
movq %r9, %r14
callq 0x7ebdf
testl %eax, %eax
je 0x80064
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl $0x1, %r8d
cmpl $0x8, %r15d
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rsi
jl 0x80031
leal -0x8(%r15), %ecx
movq %r9, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%r13,%rcx,4), %ecx
testl %ecx, %ecx
je 0x8002b
subl %ecx, %r15d
movzbl 0x520(%r13,%rax), %ebp
xorl %eax, %eax
jmp 0x80075
movl $0x9, %r8d
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movq %r13, %rcx
movq %r9, %r14
callq 0x7ed1e
movl %eax, %ebp
testl %eax, %eax
js 0x80064
movq 0x38(%rsp), %r9
xorl %eax, %eax
movl 0x40(%rsp), %r15d
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rsi
jmp 0x80075
movl $0x5, %eax
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rsi
movq %r14, %r9
testl %eax, %eax
jne 0x8024d
movl %ebp, %ecx
sarl $0x4, %ebp
movl %ecx, %eax
andl $0xf, %eax
je 0x8010f
cmpl $0x1, %eax
je 0x800b8
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movl $0x76, 0x28(%rax)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r9, %r14
callq *0x8(%rax)
movq %r14, %r9
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edx
testl %r15d, %r15d
leaq 0x2abbe(%rip), %rdi     # 0xaac80
jg 0x800fb
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x80252
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rsi
leaq 0x2ab85(%rip), %rdi     # 0xaac80
decl %r15d
btq %r15, %r9
movl %edx, %eax
cmovael 0x14(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x80127
cmpl $0xf, %ebp
leaq 0x2ab67(%rip), %rdi     # 0xaac80
jne 0x80279
movl $0x0, 0x24(%rsp)
movslq %r12d, %r13
cmpl %esi, %r13d
movl %esi, %eax
cmovgl %r13d, %eax
incl %eax
movq %rax, 0x68(%rsp)
decq %r13
movslq 0x4(%rdi,%r13,4), %r14
cmpw $0x0, (%rbx,%r14,2)
je 0x801ab
testl %r15d, %r15d
jg 0x80186
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x80252
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rsi
leaq 0x2aafa(%rip), %rdi     # 0xaac80
decl %r15d
btq %r15, %r9
jae 0x801b1
movswl (%rbx,%r14,2), %eax
testl %eax, %edx
jne 0x801b1
testw %ax, %ax
movl %edx, %ecx
cmovsl 0x14(%rsp), %ecx
addl %eax, %ecx
movw %cx, (%rbx,%r14,2)
jmp 0x801b1
testl %ebp, %ebp
jle 0x801c3
decl %ebp
incl %r12d
incq %r13
cmpq %rsi, %r13
jl 0x8013d
movq 0x68(%rsp), %r8
jmp 0x801c6
movl %r12d, %r8d
movl 0x24(%rsp), %ebp
testl %ebp, %ebp
movq 0x60(%rsp), %r13
je 0x801ef
movslq %r8d, %rax
movslq (%rdi,%rax,4), %rax
movw %bp, (%rbx,%rax,2)
movl 0x10(%rsp), %edi
movslq %edi, %rcx
incl %edi
movl %edi, 0x10(%rsp)
movl %eax, 0x70(%rsp,%rcx,4)
leal 0x1(%r8), %r12d
cmpl %esi, %r8d
jl 0x7ffbe
jmp 0x7ff09
xorl %eax, %eax
jmp 0x8023b
xorl %edx, %edx
movq 0x28(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq %rax, (%rcx)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rcx)
movq 0x58(%rsp), %r14
movq %r9, 0x18(%r14)
movl %r15d, 0x20(%r14)
movl %edx, 0x28(%r14)
decl 0x3c(%r14)
movl $0x1, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x5, %eax
jne 0x80277
xorl %eax, %eax
movl 0x10(%rsp), %ecx
testl %ecx, %ecx
jle 0x8023b
movl %ecx, %ecx
incq %rcx
movslq 0x68(%rsp,%rcx,4), %rdx
movw $0x0, (%rbx,%rdx,2)
decq %rcx
cmpq $0x1, %rcx
jg 0x80261
jmp 0x8023b
jmp 0x8023b
movl %ecx, %r8d
movl $0x1, %eax
movl %ebp, %ecx
shll %cl, %eax
movq %rax, 0x18(%rsp)
cmpl $0x10, %r8d
jb 0x7ff09
cmpl %ebp, %r15d
jge 0x802c2
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x80252
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rsi
subl %ebp, %r15d
movq %r9, %rax
movl %r15d, %ecx
sarq %cl, %rax
movq 0x18(%rsp), %rdi
leal -0x1(%rdi), %ecx
andl %eax, %ecx
addl %edi, %ecx
movl %ecx, %eax
movq %rax, 0x18(%rsp)
jmp 0x7ff09