// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jdphuff.c
// Function: start_pass_phuff_decoder
METHODDEF(void)
start_pass_phuff_decoder (j_decompress_ptr cinfo)
{
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  jboolean is_DC_band, bad;
  int ci, coefi, tbl;
  int *coef_bit_ptr;
  jpeg_component_info * compptr;

  is_DC_band = (cinfo->Ss == 0);

  /* Validate scan parameters */
  bad = FALSE;
  if (is_DC_band) {
    if (cinfo->Se != 0)
      bad = TRUE;
  } else {
    /* need not check Ss/Se < 0 since they came from unsigned bytes */
    if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
      bad = TRUE;
    /* AC scans may have only one component */
    if (cinfo->comps_in_scan != 1)
      bad = TRUE;
  }
  if (cinfo->Ah != 0) {
    /* Successive approximation refinement scan: must have Al = Ah-1. */
    if (cinfo->Al != cinfo->Ah-1)
      bad = TRUE;
  }
  if (cinfo->Al > 13)		/* need not check for < 0 */
    bad = TRUE;
  /* Arguably the maximum Al value should be less than 13 for 8-bit precision,
   * but the spec doesn't say so, and we try to be liberal about what we
   * accept.  Note: large Al values could result in out-of-range DC
   * coefficients during early scans, leading to bizarre displays due to
   * overflows in the IDCT math.  But we won't crash.
   */
  if (bad)
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
	     cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  /* Update progression status, and verify that scan order is legal.
   * Note that inter-scan inconsistencies are treated as warnings
   * not fatal errors ... not clear if this is right way to behave.
   */
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
    int cindex = cinfo->cur_comp_info[ci]->component_index;
    coef_bit_ptr = & cinfo->coef_bits[cindex][0];
    if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
      WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
    for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
      int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
      if (cinfo->Ah != expected)
	WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
      coef_bit_ptr[coefi] = cinfo->Al;
    }
  }

  /* Select MCU decoding routine */
  if (cinfo->Ah == 0) {
    if (is_DC_band)
      entropy->pub.decode_mcu = decode_mcu_DC_first;
    else
      entropy->pub.decode_mcu = decode_mcu_AC_first;
  } else {
    if (is_DC_band)
      entropy->pub.decode_mcu = decode_mcu_DC_refine;
    else
      entropy->pub.decode_mcu = decode_mcu_AC_refine;
  }

  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
    compptr = cinfo->cur_comp_info[ci];
    /* Make sure requested tables are present, and compute derived tables.
     * We may build same derived table more than once, but it's not expensive.
     */
    if (is_DC_band) {
      if (cinfo->Ah == 0) {	/* DC refinement needs no table */
	tbl = compptr->dc_tbl_no;
	jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
				& entropy->derived_tbls[tbl]);
      }
    } else {
      tbl = compptr->ac_tbl_no;
      jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
			      & entropy->derived_tbls[tbl]);
      /* remember the single active table */
      entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
    }
    /* Initialize DC predictions to 0 */
    entropy->saved.last_dc_val[ci] = 0;
  }

  /* Initialize bitread state variables */
  entropy->bitstate.bits_left = 0;
  entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  entropy->pub.insufficient_data = FALSE;

  /* Initialize private state variables */
  entropy->saved.EOBRUN = 0;

  /* Initialize restart counter */
  entropy->restarts_to_go = cinfo->restart_interval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x20c(%rdi), %r13d
movl 0x210(%rdi), %eax
testl %r13d, %r13d
je 0x726c6
cmpl %eax, %r13d
setg %cl
cmpl $0x40, %eax
setge %dl
orb %cl, %dl
cmpl $0x1, 0x1b0(%rbx)
setne %al
orb %dl, %al
jmp 0x726cb
testl %eax, %eax
setne %al
movq 0x250(%rbx), %rcx
movq %rcx, (%rsp)
movl 0x214(%rbx), %edx
movl 0x218(%rbx), %esi
addl $-0x1, %edx
setb %cl
cmpl %edx, %esi
setne %dl
cmpl $0xd, %esi
jg 0x726fa
andb %dl, %cl
jne 0x726fa
testb %al, %al
je 0x72734
movq (%rbx), %rax
movl $0x10, 0x28(%rax)
movl %r13d, 0x2c(%rax)
movl 0x210(%rbx), %eax
movq (%rbx), %rcx
movl %eax, 0x30(%rcx)
movl 0x214(%rbx), %eax
movq (%rbx), %rcx
movl %eax, 0x34(%rcx)
movl 0x218(%rbx), %eax
movq (%rbx), %rcx
movl %eax, 0x38(%rcx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
xorl %r14d, %r14d
pushq $-0x1
popq %rbp
xorl %ecx, %ecx
movl %r13d, 0xc(%rsp)
movslq 0x1b0(%rbx), %rax
cmpq %rax, %rcx
jge 0x72801
movq %rcx, 0x10(%rsp)
movq 0x1b8(%rbx,%rcx,8), %rax
movslq 0x4(%rax), %r12
movq %r12, %r15
shlq $0x8, %r15
addq 0xc0(%rbx), %r15
testl %r13d, %r13d
je 0x7279b
cmpl $0x0, (%r15)
jns 0x7279b
movq (%rbx), %rax
movl $0x73, 0x28(%rax)
movl %r12d, 0x2c(%rax)
movq (%rbx), %rax
andl $0x0, 0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
callq *0x8(%rax)
movslq 0x20c(%rbx), %r13
movslq 0x210(%rbx), %rax
cmpq %rax, %r13
jg 0x727ef
movl (%r15,%r13,4), %eax
testl %eax, %eax
cmovlel %r14d, %eax
cmpl %eax, 0x214(%rbx)
je 0x727e0
movq (%rbx), %rax
movl $0x73, 0x28(%rax)
movl %r12d, 0x2c(%rax)
movq (%rbx), %rax
movl %r13d, 0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
callq *0x8(%rax)
movl 0x218(%rbx), %eax
movl %eax, (%r15,%r13,4)
incq %r13
jmp 0x727a2
movq 0x10(%rsp), %rcx
incq %rcx
movl 0xc(%rsp), %r13d
jmp 0x72741
testl %r13d, %r13d
leaq 0xcf(%rip), %rcx        # 0x728da
leaq 0x2de(%rip), %rdx       # 0x72af0
cmoveq %rcx, %rdx
leaq 0x51b(%rip), %rcx       # 0x72d38
leaq 0x601(%rip), %rsi       # 0x72e25
cmoveq %rcx, %rsi
cmpl $0x0, 0x214(%rbx)
cmoveq %rdx, %rsi
movq (%rsp), %r14
movq %rsi, 0x8(%r14)
leaq 0x40(%r14), %r15
xorl %r12d, %r12d
pushq $0x1
popq %rbp
cltq
cmpq %rax, %r12
jge 0x728ad
movq 0x1b8(%rbx,%r12,8), %rax
testl %r13d, %r13d
je 0x72881
movslq 0x18(%rax), %r14
leaq (%r15,%r14,8), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x71b94
movq (%rsp), %rax
movq 0x40(%rax,%r14,8), %rax
movq (%rsp), %r14
movq %rax, 0x60(%r14)
jmp 0x7289c
cmpl $0x0, 0x214(%rbx)
jne 0x7289c
movslq 0x14(%rax), %rdx
leaq (%r15,%rdx,8), %rcx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x71b94
andl $0x0, 0x2c(%r14,%r12,4)
incq %r12
movl 0x1b0(%rbx), %eax
jmp 0x72845
andl $0x0, 0x20(%r14)
andq $0x0, 0x18(%r14)
andl $0x0, 0x10(%r14)
andl $0x0, 0x28(%r14)
movl 0x170(%rbx), %eax
movl %eax, 0x3c(%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq