// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/jpeg/jdhuff.c
// Function: decode_mcu
METHODDEF(jboolean)
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{
  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  int blkn;
  BITREAD_STATE_VARS;
  savable_state state;

  /* 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++) {
      JBLOCKROW block = MCU_data[blkn];
      d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
      d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
      register int s, k, r;

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

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

      if (entropy->dc_needed[blkn]) {
	/* Convert DC difference to actual value, update last_dc_val */
	int ci = cinfo->MCU_membership[blkn];
	s += state.last_dc_val[ci];
	state.last_dc_val[ci] = s;
	/* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
	(*block)[0] = (JCOEF) s;
      }

      if (entropy->ac_needed[blkn]) {

	/* Section F.2.2.2: decode the AC coefficients */
	/* Since zeroes are skipped, output area must be cleared beforehand */
	for (k = 1; k < DCTSIZE2; k++) {
	  HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
      
	  r = s >> 4;
	  s &= 15;
      
	  if (s) {
	    k += r;
	    CHECK_BIT_BUFFER(br_state, s, return FALSE);
	    r = GET_BITS(s);
	    s = HUFF_EXTEND(r, s);
	    /* Output coefficient in natural (dezigzagged) order.
	     * Note: the extra entries in jpeg_natural_order[] will save us
	     * if k >= DCTSIZE2, which could happen if the data is corrupted.
	     */
	    (*block)[jpeg_natural_order[k]] = (JCOEF) s;
	  } else {
	    if (r != 15)
	      break;
	    k += 15;
	  }
	}

      } else {

	/* Section F.2.2.2: decode the AC coefficients */
	/* In this path we just discard the values */
	for (k = 1; k < DCTSIZE2; k++) {
	  HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
      
	  r = s >> 4;
	  s &= 15;
      
	  if (s) {
	    k += r;
	    CHECK_BIT_BUFFER(br_state, s, return FALSE);
	    DROP_BITS(s);
	  } else {
	    if (r != 15)
	      break;
	    k += 15;
	  }
	}

      }
    }

    /* 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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x250(%rdi), %r14
cmpl $0x0, 0x170(%rdi)
je 0x7e383
cmpl $0x0, 0x38(%r14)
je 0x7e757
cmpl $0x0, 0x10(%r14)
je 0x7e398
decl 0x38(%r14)
movl $0x1, %ebp
jmp 0x7e7cb
movq %rbx, 0x28(%rsp)
movq 0x28(%rbx), %rax
movq (%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x8(%rax), %rdi
movq %rdi, 0x10(%rsp)
movq 0x18(%r14), %rsi
movl 0x20(%r14), %edx
movups 0x28(%r14), %xmm0
movaps %xmm0, 0x40(%rsp)
cmpl $0x0, 0x1e0(%rbx)
jle 0x7e736
xorl %ecx, %ecx
movq %r15, 0x50(%rsp)
movq (%r15,%rcx,8), %rax
movq %rax, 0x38(%rsp)
movq 0x80(%r14,%rcx,8), %r13
movq %rcx, 0x30(%rsp)
movq 0xd0(%r14,%rcx,8), %r12
cmpl $0x7, %edx
jg 0x7e42f
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7e7cb
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
cmpl $0x7, %edx
jg 0x7e42f
leaq 0x8(%rsp), %rdi
movq %r13, %rcx
movl $0x1, %r8d
jmp 0x7e469
leal -0x8(%rdx), %ecx
movq %rsi, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%r13,%rcx,4), %ecx
testl %ecx, %ecx
je 0x7e45b
subl %ecx, %edx
movzbl 0x520(%r13,%rax), %ebp
movq 0x30(%rsp), %r15
jmp 0x7e486
leaq 0x8(%rsp), %rdi
movq %r13, %rcx
movl $0x9, %r8d
callq 0x7e0c0
movl %eax, %ebp
testl %eax, %eax
movq 0x30(%rsp), %r15
js 0x7e7c9
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
testl %ebp, %ebp
je 0x7e4dc
cmpl %ebp, %edx
jge 0x7e4ab
leaq 0x8(%rsp), %rdi
movl %ebp, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7e7c9
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
subl %ebp, %edx
movq %rsi, %rdi
movl %edx, %ecx
sarq %cl, %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %eax
notl %eax
andl %edi, %eax
movl %ebp, %ecx
leaq 0x2c485(%rip), %rdi     # 0xaa950
cmpl (%rdi,%rcx,4), %eax
jge 0x7e4de
leaq 0x2c4b9(%rip), %rdi     # 0xaa990
addl (%rdi,%rcx,4), %eax
jmp 0x7e4de
xorl %eax, %eax
cmpl $0x0, 0x120(%r14,%r15,4)
je 0x7e501
movslq 0x1e4(%rbx,%r15,4), %rcx
addl 0x40(%rsp,%rcx,4), %eax
movl %eax, 0x40(%rsp,%rcx,4)
movq 0x38(%rsp), %rcx
movw %ax, (%rcx)
cmpl $0x0, 0x148(%r14,%r15,4)
je 0x7e638
movl $0x1, %r13d
cmpl $0x7, %edx
jg 0x7e54f
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7e7cb
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
cmpl $0x7, %edx
jg 0x7e54f
leaq 0x8(%rsp), %rdi
movq %r12, %rcx
movl $0x1, %r8d
jmp 0x7e584
leal -0x8(%rdx), %ecx
movq %rsi, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%r12,%rcx,4), %ecx
testl %ecx, %ecx
je 0x7e576
subl %ecx, %edx
movzbl 0x520(%r12,%rax), %ebp
jmp 0x7e59c
leaq 0x8(%rsp), %rdi
movq %r12, %rcx
movl $0x9, %r8d
callq 0x7e0c0
movl %eax, %ebp
testl %eax, %eax
js 0x7e7c9
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
movl %ebp, %r15d
shrl $0x4, %r15d
andl $0xf, %ebp
je 0x7e614
cmpl %ebp, %edx
jge 0x7e5c9
leaq 0x8(%rsp), %rdi
movl %ebp, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7e7c9
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
subl %ebp, %edx
movq %rsi, %rdi
movl %edx, %ecx
sarq %cl, %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %eax
notl %eax
andl %edi, %eax
movl %ebp, %ecx
leaq 0x2c367(%rip), %rdi     # 0xaa950
cmpl (%rdi,%rcx,4), %eax
jge 0x7e5f8
leaq 0x2c39b(%rip), %rdi     # 0xaa990
addl (%rdi,%rcx,4), %eax
addl %r13d, %r15d
movslq %r15d, %rcx
leaq 0x2c6bb(%rip), %rdi     # 0xaacc0
movslq (%rdi,%rcx,4), %rcx
movq 0x38(%rsp), %rdi
movw %ax, (%rdi,%rcx,2)
jmp 0x7e625
cmpl $0xf, %r15d
jne 0x7e70b
addl $0xf, %r13d
movl %r13d, %r15d
leal 0x1(%r15), %r13d
cmpl $0x3f, %r15d
jl 0x7e516
jmp 0x7e70b
movl $0x1, %r13d
cmpl $0x7, %edx
jg 0x7e677
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
xorl %ecx, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7e7cb
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
cmpl $0x7, %edx
jg 0x7e677
leaq 0x8(%rsp), %rdi
movq %r12, %rcx
movl $0x1, %r8d
jmp 0x7e6ac
leal -0x8(%rdx), %ecx
movq %rsi, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%r12,%rcx,4), %ecx
testl %ecx, %ecx
je 0x7e69e
subl %ecx, %edx
movzbl 0x520(%r12,%rax), %ebp
jmp 0x7e6c4
leaq 0x8(%rsp), %rdi
movq %r12, %rcx
movl $0x9, %r8d
callq 0x7e0c0
movl %eax, %ebp
testl %eax, %eax
js 0x7e7c9
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
movl %ebp, %r15d
shrl $0x4, %r15d
andl $0xf, %ebp
je 0x7e6f5
cmpl %ebp, %edx
jge 0x7e6f1
leaq 0x8(%rsp), %rdi
movl %ebp, %ecx
callq 0x7df73
testl %eax, %eax
je 0x7e7c9
movq 0x18(%rsp), %rsi
movl 0x20(%rsp), %edx
subl %ebp, %edx
jmp 0x7e6fb
cmpl $0xf, %r15d
jne 0x7e70b
addl %r15d, %r13d
incl %r13d
cmpl $0x40, %r13d
jl 0x7e63e
movq 0x30(%rsp), %rcx
incq %rcx
movslq 0x1e0(%rbx), %rax
cmpq %rax, %rcx
movq 0x50(%rsp), %r15
jl 0x7e3d8
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq 0x28(%rbx), %rax
leaq 0x28(%r14), %r8
movq %rcx, (%rax)
movq %rdi, 0x8(%rax)
movq %rsi, 0x18(%r14)
movl %edx, 0x20(%r14)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%r8)
jmp 0x7e38a
movl 0x20(%r14), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
movq 0x248(%rbx), %rax
addl %ecx, 0x24(%rax)
movl $0x0, 0x20(%r14)
movq %rbx, %rdi
callq *0x10(%rax)
testl %eax, %eax
je 0x7e7c9
cmpl $0x0, 0x1b0(%rbx)
jle 0x7e7a5
xorl %eax, %eax
movl $0x0, 0x28(%r14,%rax,4)
incq %rax
movslq 0x1b0(%rbx), %rcx
cmpq %rcx, %rax
jl 0x7e78d
movl 0x170(%rbx), %eax
movl %eax, 0x38(%r14)
cmpl $0x0, 0x21c(%rbx)
jne 0x7e383
movl $0x0, 0x10(%r14)
jmp 0x7e383
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq