// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, 0x60(%rsp)
movq 0x250(%rdi), %rbx
movq %rdi, 0x38(%rsp)
cmpl $0x0, 0x170(%rdi)
je 0x7efeb
cmpl $0x0, 0x38(%rbx)
je 0x7f489
cmpl $0x0, 0x10(%rbx)
jne 0x7f46b
movq 0x38(%rsp), %rdx
movq %rdx, 0x30(%rsp)
movq 0x28(%rdx), %rax
movq (%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rbx), %r15
movl 0x20(%rbx), %r13d
movups 0x28(%rbx), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x0, 0x1e0(%rdx)
jle 0x7f43d
xorl %r12d, %r12d
movq %rbx, (%rsp)
movq 0x60(%rsp), %rax
movq (%rax,%r12,8), %rax
movq %rax, 0x48(%rsp)
movq %rbx, %rax
movq 0x80(%rbx,%r12,8), %rbx
movq 0xd0(%rax,%r12,8), %rax
movq %rax, 0x40(%rsp)
cmpl $0x7, %r13d
jg 0x7f094
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x7f0f4
movq 0x20(%rsp), %r15
movl 0x28(%rsp), %r13d
movl $0x1, %r8d
cmpl $0x8, %r13d
jl 0x7f0c4
leal -0x8(%r13), %ecx
movq %r15, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%rbx,%rcx,4), %ecx
testl %ecx, %ecx
je 0x7f0be
subl %ecx, %r13d
movzbl 0x520(%rbx,%rax), %ebp
movb $0x1, %r14b
jmp 0x7f0f4
movl $0x9, %r8d
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
movq %rbx, %rcx
callq 0x7ed1e
testl %eax, %eax
js 0x7f0ec
movl %eax, %ebp
movq 0x20(%rsp), %r15
movb $0x1, %r14b
movl 0x28(%rsp), %r13d
jmp 0x7f0f4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq (%rsp), %rbx
testb %r14b, %r14b
je 0x7f162
testl %ebp, %ebp
je 0x7f171
movl $0x0, 0xc(%rsp)
cmpl %ebp, %r13d
jge 0x7f12e
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
movl %ebp, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x7f16a
movq 0x20(%rsp), %r15
movl 0x28(%rsp), %r13d
subl %ebp, %r13d
movq %r15, %rdx
movl %r13d, %ecx
sarq %cl, %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %eax
notl %eax
andl %edx, %eax
movslq %ebp, %rcx
leaq 0x2b7ef(%rip), %rdx     # 0xaa940
cmpl (%rdx,%rcx,4), %eax
jge 0x7f17b
leaq 0x2b823(%rip), %rdx     # 0xaa980
addl (%rdx,%rcx,4), %eax
jmp 0x7f17b
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
jmp 0x7f421
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x120(%rbx,%r12,4)
je 0x7f1a3
movq 0x38(%rsp), %rcx
movslq 0x1e4(%rcx,%r12,4), %rcx
addl 0x50(%rsp,%rcx,4), %eax
movl %eax, 0x50(%rsp,%rcx,4)
movq 0x48(%rsp), %rcx
movw %ax, (%rcx)
movl %eax, %ebp
cmpl $0x0, 0x148(%rbx,%r12,4)
je 0x7f312
movl $0x1, %ebx
cmpl $0x7, %r13d
jg 0x7f1f9
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x7f260
movq 0x20(%rsp), %r15
movl 0x28(%rsp), %r13d
movl $0x1, %r8d
cmpl $0x8, %r13d
movq 0x40(%rsp), %r9
jge 0x7f1fe
jmp 0x7f230
movq 0x40(%rsp), %r9
leal -0x8(%r13), %ecx
movq %r15, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%r9,%rcx,4), %ecx
testl %ecx, %ecx
je 0x7f22a
subl %ecx, %r13d
movzbl 0x520(%r9,%rax), %ebp
movb $0x1, %r14b
jmp 0x7f260
movl $0x9, %r8d
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
movq %r9, %rcx
callq 0x7ed1e
testl %eax, %eax
js 0x7f258
movl %eax, %ebp
movq 0x20(%rsp), %r15
movb $0x1, %r14b
movl 0x28(%rsp), %r13d
jmp 0x7f260
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
testb %r14b, %r14b
je 0x7f415
movl %ebp, %r14d
sarl $0x4, %r14d
andl $0xf, %ebp
je 0x7f2ed
cmpl %ebp, %r13d
jge 0x7f29e
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
movl %ebp, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x7f415
movq 0x20(%rsp), %r15
movl 0x28(%rsp), %r13d
subl %ebp, %r13d
movq %r15, %rdx
movl %r13d, %ecx
sarq %cl, %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %eax
notl %eax
andl %edx, %eax
movl %ebp, %ecx
leaq 0x2b680(%rip), %rdx     # 0xaa940
cmpl (%rdx,%rcx,4), %eax
jge 0x7f2cf
leaq 0x2b6b4(%rip), %rdx     # 0xaa980
addl (%rdx,%rcx,4), %eax
addl %ebx, %r14d
movslq %r14d, %rcx
leaq 0x2b9a4(%rip), %rdx     # 0xaac80
movslq (%rdx,%rcx,4), %rcx
movq 0x48(%rsp), %rdx
movw %ax, (%rdx,%rcx,2)
movl %eax, %ebp
jmp 0x7f2ff
cmpl $0xf, %r14d
jne 0x7f419
addl $0xf, %ebx
xorl %ebp, %ebp
movl %ebx, %r14d
leal 0x1(%r14), %ebx
cmpl $0x3f, %r14d
jl 0x7f1b9
jmp 0x7f41b
movl $0x1, %ebx
cmpl $0x7, %r13d
jg 0x7f357
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x7f3be
movq 0x20(%rsp), %r15
movl 0x28(%rsp), %r13d
movl $0x1, %r8d
cmpl $0x8, %r13d
movq 0x40(%rsp), %r9
jge 0x7f35c
jmp 0x7f38e
movq 0x40(%rsp), %r9
leal -0x8(%r13), %ecx
movq %r15, %rax
sarq %cl, %rax
movzbl %al, %eax
movl %eax, %ecx
movl 0x120(%r9,%rcx,4), %ecx
testl %ecx, %ecx
je 0x7f388
subl %ecx, %r13d
movzbl 0x520(%r9,%rax), %ebp
movb $0x1, %r14b
jmp 0x7f3be
movl $0x9, %r8d
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
movq %r9, %rcx
callq 0x7ed1e
testl %eax, %eax
js 0x7f3b6
movl %eax, %ebp
movq 0x20(%rsp), %r15
movb $0x1, %r14b
movl 0x28(%rsp), %r13d
jmp 0x7f3be
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
testb %r14b, %r14b
je 0x7f415
movl %ebp, %r14d
sarl $0x4, %r14d
andl $0xf, %ebp
je 0x7f3f9
cmpl %ebp, %r13d
jge 0x7f3f4
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
movl %ebp, %ecx
callq 0x7ebdf
testl %eax, %eax
je 0x7f415
movq 0x20(%rsp), %r15
movl 0x28(%rsp), %r13d
subl %ebp, %r13d
jmp 0x7f405
cmpl $0xf, %r14d
jne 0x7f419
movl $0xf, %r14d
addl %r14d, %ebx
incl %ebx
cmpl $0x40, %ebx
jl 0x7f317
jmp 0x7f41b
xorl %eax, %eax
jmp 0x7f41d
xorl %ebp, %ebp
movb $0x1, %al
movq (%rsp), %rbx
testb %al, %al
je 0x7f476
incq %r12
movq 0x38(%rsp), %rax
movslq 0x1e0(%rax), %rax
cmpq %rax, %r12
jl 0x7f039
leaq 0x28(%rbx), %rax
movq 0x10(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq 0x28(%rdx), %rdx
movq %rcx, (%rdx)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rdx)
movq %r15, 0x18(%rbx)
movl %r13d, 0x20(%rbx)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rax)
decl 0x38(%rbx)
movl $0x1, 0xc(%rsp)
movl 0xc(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x20(%rbx), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
movq 0x38(%rsp), %r14
movq 0x248(%r14), %rax
addl %ecx, 0x24(%rax)
movl $0x0, 0x20(%rbx)
movq %r14, %rdi
callq *0x10(%rax)
movl $0x0, 0xc(%rsp)
testl %eax, %eax
je 0x7f476
cmpl $0x0, 0x1b0(%r14)
jle 0x7f4e2
xorl %ecx, %ecx
movl $0x0, 0x28(%rbx,%rcx,4)
incq %rcx
movslq 0x1b0(%r14), %rdx
cmpq %rdx, %rcx
jl 0x7f4cb
movl 0x170(%r14), %ecx
movl %ecx, 0x38(%rbx)
cmpl $0x0, 0x21c(%r14)
jne 0x7f4fd
movl $0x0, 0x10(%rbx)
testl %eax, %eax
jne 0x7efeb
jmp 0x7f476
nop