// File: /workspace/github_cpp_makefile_star2_O1/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), %r15d
movl 0x210(%rdi), %eax
testl %r15d, %r15d
je 0x7f5cb
cmpl %eax, %r15d
setg %cl
cmpl $0x40, %eax
setge %dl
orb %cl, %dl
cmpl $0x1, 0x1b0(%rbx)
setne %al
orb %dl, %al
jmp 0x7f5d0
testl %eax, %eax
setne %al
movzbl %al, %eax
movl 0x214(%rbx), %ecx
testl %ecx, %ecx
je 0x7f5ed
decl %ecx
cmpl %ecx, 0x218(%rbx)
movl $0x1, %ecx
cmovnel %ecx, %eax
movq 0x250(%rbx), %rcx
movq %rcx, 0x10(%rsp)
cmpl $0xd, 0x218(%rbx)
jg 0x7f606
testl %eax, %eax
je 0x7f640
movq (%rbx), %rax
movl $0x10, 0x28(%rax)
movl %r15d, 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)
cmpl $0x0, 0x1b0(%rbx)
jle 0x7f724
xorl %r12d, %r12d
movl %r15d, 0xc(%rsp)
movq 0x1b8(%rbx,%r12,8), %rax
movslq 0x4(%rax), %rbp
movq %rbp, %r13
shlq $0x8, %r13
addq 0xc0(%rbx), %r13
testl %r15d, %r15d
je 0x7f6a0
cmpl $0x0, (%r13)
jns 0x7f6a0
movq (%rbx), %rax
movl $0x73, 0x28(%rax)
movl %ebp, 0x2c(%rax)
movq (%rbx), %rax
movl $0x0, 0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *0x8(%rax)
movl 0x20c(%rbx), %r15d
cmpl 0x210(%rbx), %r15d
jg 0x7f70c
movslq %r15d, %r14
decq %r14
movl 0x4(%r13,%r14,4), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
cmpl %eax, 0x214(%rbx)
je 0x7f6ef
movq (%rbx), %rax
movl $0x73, 0x28(%rax)
movl %ebp, 0x2c(%rax)
movq (%rbx), %rax
movl %r15d, 0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *0x8(%rax)
movl 0x218(%rbx), %eax
movl %eax, 0x4(%r13,%r14,4)
movslq 0x210(%rbx), %rax
incq %r14
incl %r15d
cmpq %rax, %r14
jl 0x7f6b6
incq %r12
movslq 0x1b0(%rbx), %rax
cmpq %rax, %r12
movl 0xc(%rsp), %r15d
jl 0x7f655
testl %r15d, %r15d
leaq 0xcf(%rip), %rax        # 0x7f7fd
leaq 0x33c(%rip), %rcx       # 0x7fa71
cmoveq %rax, %rcx
leaq 0x601(%rip), %rax       # 0x7fd41
leaq 0x6ea(%rip), %rdx       # 0x7fe31
cmoveq %rax, %rdx
cmpl $0x0, 0x214(%rbx)
cmoveq %rcx, %rdx
movq 0x10(%rsp), %rbp
movq %rdx, 0x8(%rbp)
cmpl $0x0, 0x1b0(%rbx)
jle 0x7f7d2
leaq 0x40(%rbp), %r12
xorl %r13d, %r13d
movq 0x1b8(%rbx,%r13,8), %rax
testl %r15d, %r15d
je 0x7f79c
movslq 0x18(%rax), %r14
leaq (%r12,%r14,8), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x7e950
movq 0x40(%rbp,%r14,8), %rax
movq %rax, 0x60(%rbp)
jmp 0x7f7ba
cmpl $0x0, 0x214(%rbx)
jne 0x7f7ba
movslq 0x14(%rax), %rdx
leaq (%r12,%rdx,8), %rcx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7e950
movl $0x0, 0x2c(%rbp,%r13,4)
incq %r13
movslq 0x1b0(%rbx), %rax
cmpq %rax, %r13
jl 0x7f76f
xorl %eax, %eax
movl %eax, 0x20(%rbp)
movq $0x0, 0x18(%rbp)
movl %eax, 0x10(%rbp)
movl %eax, 0x28(%rbp)
movl 0x170(%rbx), %eax
movl %eax, 0x3c(%rbp)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq