// File: /workspace/github_cpp_makefile_star2_O3/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, 0x20(%rsp)
movq 0x250(%rdi), %r14
movslq 0x210(%rdi), %rsi
cmpl $0x0, 0x170(%rdi)
movl %edx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
je 0x7f0ea
cmpl $0x0, 0x3c(%r14)
jne 0x7f0ea
movq %rbx, %rdi
callq 0x7f502
movq 0x10(%rsp), %rsi
movl 0x8(%rsp), %edx
testl %eax, %eax
je 0x7f474
cmpl $0x0, 0x10(%r14)
jne 0x7f229
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), %eax
movq (%r12), %r12
movq %rbx, 0x58(%rsp)
movl 0x20c(%rbx), %r13d
movq %rax, %rbx
testl %ebx, %ebx
setne %al
cmpl %esi, %r13d
setg %cl
movl $0x0, 0x1c(%rsp)
orb %al, %cl
movq %r14, 0x60(%rsp)
je 0x7f244
movl $0x0, 0xc(%rsp)
testl %ebx, %ebx
je 0x7f1fa
movq %rbx, 0x10(%rsp)
cmpl %esi, %r13d
jg 0x7f1ef
movslq %r13d, %rbx
shlq $0x2, %rbx
addq 0x65e16(%rip), %rbx     # 0xe4f90
subl %r13d, %esi
incl %esi
xorl %r13d, %r13d
movslq (%rbx,%r13,4), %r14
cmpw $0x0, (%r12,%r14,2)
je 0x7f1e7
testl %r15d, %r15d
jg 0x7f1c4
movq %rsi, %rbp
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7f4d5
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x8(%rsp), %edx
movq %rbp, %rsi
decl %r15d
btq %r15, %r9
jae 0x7f1e7
movswl (%r12,%r14,2), %eax
testl %eax, %edx
jne 0x7f1e7
testw %ax, %ax
movl %edx, %ecx
cmovsl 0x20(%rsp), %ecx
addl %eax, %ecx
movw %cx, (%r12,%r14,2)
incq %r13
cmpl %r13d, %esi
jne 0x7f182
movq 0x10(%rsp), %rax
decl %eax
movl %eax, 0x1c(%rsp)
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), %r14
movq %r9, 0x18(%r14)
movl %r15d, 0x20(%r14)
movl 0x1c(%rsp), %eax
movl %eax, 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
movq 0x60(%r14), %rbx
movl $0x0, 0xc(%rsp)
movq %rbx, 0x68(%rsp)
cmpl $0x7, %r15d
jg 0x7f28f
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7f4d5
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl $0x1, %r8d
cmpl $0x8, %r15d
movl 0x8(%rsp), %edx
jl 0x7f2bc
leal -0x8(%r15), %ecx
movq %r9, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%rbx,%rcx,4), %ecx
testl %ecx, %ecx
je 0x7f2b6
subl %ecx, %r15d
movzbl 0x520(%rbx,%rax), %eax
jmp 0x7f2e5
movl $0x9, %r8d
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movq %rbx, %rcx
callq 0x7e0c0
testl %eax, %eax
js 0x7f4d5
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x8(%rsp), %edx
movl %eax, %ebp
shrl $0x4, %ebp
movl %eax, %ecx
andl $0xf, %ecx
movq 0x10(%rsp), %rsi
leaq 0x2b9c5(%rip), %rdi     # 0xaacc0
je 0x7f383
cmpl $0x1, %ecx
je 0x7f333
movq 0x58(%rsp), %rdi
movq (%rdi), %rax
movl $0x76, 0x28(%rax)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r9, %rbx
callq *0x8(%rax)
leaq 0x2b999(%rip), %rdi     # 0xaacc0
movq %rbx, %r9
movq 0x10(%rsp), %rsi
movl 0x8(%rsp), %edx
testl %r15d, %r15d
jg 0x7f36f
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7f4d5
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x8(%rsp), %edx
movq 0x10(%rsp), %rsi
leaq 0x2b951(%rip), %rdi     # 0xaacc0
decl %r15d
btq %r15, %r9
movl %edx, %eax
cmovael 0x20(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x7f394
movl $0x0, 0x24(%rsp)
cmpl $0xf, %ebp
jne 0x7f47b
movslq %r13d, %rbx
cmpl %esi, %ebx
movl %esi, %eax
cmovgl %ebx, %eax
incl %eax
movl %eax, 0x54(%rsp)
decq %rbx
movslq 0x4(%rdi,%rbx,4), %r14
cmpw $0x0, (%r12,%r14,2)
je 0x7f415
testl %r15d, %r15d
jg 0x7f3f0
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7f4d5
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x8(%rsp), %edx
movq 0x10(%rsp), %rsi
leaq 0x2b8d0(%rip), %rdi     # 0xaacc0
decl %r15d
btq %r15, %r9
jae 0x7f41b
movswl (%r12,%r14,2), %eax
testl %eax, %edx
jne 0x7f41b
testw %ax, %ax
movl %edx, %ecx
cmovsl 0x20(%rsp), %ecx
addl %eax, %ecx
movw %cx, (%r12,%r14,2)
jmp 0x7f41b
testl %ebp, %ebp
jle 0x7f42d
decl %ebp
incl %r13d
incq %rbx
cmpq %rsi, %rbx
jl 0x7f3a7
movl 0x54(%rsp), %eax
movl %eax, %r13d
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
movq 0x68(%rsp), %rbx
je 0x7f457
movslq %r13d, %rax
movslq (%rdi,%rax,4), %rax
movw %cx, (%r12,%rax,2)
movl 0xc(%rsp), %edi
movslq %edi, %rcx
incl %edi
movl %edi, 0xc(%rsp)
movl %eax, 0x70(%rsp,%rcx,4)
leal 0x1(%r13), %eax
cmpl %esi, %r13d
movl %eax, %r13d
jl 0x7f255
movl $0x0, 0x1c(%rsp)
jmp 0x7f1fa
xorl %eax, %eax
jmp 0x7f232
movl $0x1, %ebx
movl %ebp, %ecx
shll %cl, %ebx
cmpl $0x10, %eax
jb 0x7f15e
cmpl %ebp, %r15d
jge 0x7f4bb
leaq 0x28(%rsp), %rdi
movq %r9, %rsi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7f4d5
movq 0x38(%rsp), %r9
movl 0x40(%rsp), %r15d
movl 0x8(%rsp), %edx
movq 0x10(%rsp), %rsi
subl %ebp, %r15d
movq %r9, %rax
movl %r15d, %ecx
sarq %cl, %rax
leal -0x1(%rbx), %ecx
andl %eax, %ecx
addl %ebx, %ecx
movl %ecx, %ebx
jmp 0x7f156
xorl %eax, %eax
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
jle 0x7f232
movl %ecx, %ecx
incq %rcx
movslq 0x68(%rsp,%rcx,4), %rdx
movw $0x0, (%r12,%rdx,2)
decq %rcx
cmpq $0x1, %rcx
ja 0x7f4e8
jmp 0x7f232