// File: /workspace/github_cpp_makefile_star2_O3/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), %ebp
movl 0x210(%rdi), %eax
testl %ebp, %ebp
je 0x7e898
cmpl %eax, %ebp
setg %cl
cmpl $0x40, %eax
setge %dl
orb %cl, %dl
cmpl $0x1, 0x1b0(%rbx)
setne %al
orb %dl, %al
jmp 0x7e89d
testl %eax, %eax
setne %al
movq 0x250(%rbx), %r13
movl 0x214(%rbx), %edx
movl 0x218(%rbx), %esi
addl $-0x1, %edx
setb %cl
cmpl %edx, %esi
setne %dl
cmpl $0xd, %esi
jg 0x7e8c8
andb %dl, %cl
jne 0x7e8c8
testb %al, %al
je 0x7e901
movq (%rbx), %rax
movl $0x10, 0x28(%rax)
movl %ebp, 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 0x7ea92
movq %r13, 0x10(%rsp)
xorl %r12d, %r12d
movl %ebp, 0xc(%rsp)
movq 0x1b8(%rbx,%r12,8), %rax
movslq 0x4(%rax), %r15
movq %r15, %r13
shlq $0x8, %r13
addq 0xc0(%rbx), %r13
testl %ebp, %ebp
je 0x7e965
cmpl $0x0, (%r13)
jns 0x7e965
movq (%rbx), %rax
movl $0x73, 0x28(%rax)
movl %r15d, 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), %ebp
cmpl 0x210(%rbx), %ebp
jg 0x7e9ce
movslq %ebp, %r14
decq %r14
movl 0x4(%r13,%r14,4), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
cmpl %eax, 0x214(%rbx)
je 0x7e9b2
movq (%rbx), %rax
movl $0x73, 0x28(%rax)
movl %r15d, 0x2c(%rax)
movq (%rbx), %rax
movl %ebp, 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 %ebp
cmpq %rax, %r14
jl 0x7e979
incq %r12
movslq 0x1b0(%rbx), %rax
cmpq %rax, %r12
movl 0xc(%rsp), %ebp
jl 0x7e91a
testl %ebp, %ebp
leaq 0x108(%rip), %rcx       # 0x7eaf6
leaq 0x33d(%rip), %rdx       # 0x7ed32
cmoveq %rcx, %rdx
leaq 0x58b(%rip), %rcx       # 0x7ef8b
leaq 0x674(%rip), %rsi       # 0x7f07b
cmoveq %rcx, %rsi
cmpl $0x0, 0x214(%rbx)
cmoveq %rdx, %rsi
movq 0x10(%rsp), %r13
movq %rsi, 0x8(%r13)
testl %eax, %eax
jle 0x7eac7
leaq 0x40(%r13), %r15
xorl %r12d, %r12d
movq 0x1b8(%rbx,%r12,8), %rax
testl %ebp, %ebp
je 0x7ea5a
movslq 0x18(%rax), %r14
leaq (%r15,%r14,8), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x7dce0
movq 0x40(%r13,%r14,8), %rax
movq %rax, 0x60(%r13)
jmp 0x7ea78
cmpl $0x0, 0x214(%rbx)
jne 0x7ea78
movslq 0x14(%rax), %rdx
leaq (%r15,%rdx,8), %rcx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7dce0
movl $0x0, 0x2c(%r13,%r12,4)
incq %r12
movslq 0x1b0(%rbx), %rax
cmpq %rax, %r12
jl 0x7ea2e
jmp 0x7eac7
testl %ebp, %ebp
leaq 0x5b(%rip), %rax        # 0x7eaf6
leaq 0x290(%rip), %rcx       # 0x7ed32
cmoveq %rax, %rcx
leaq 0x4de(%rip), %rax       # 0x7ef8b
leaq 0x5c7(%rip), %rdx       # 0x7f07b
cmoveq %rax, %rdx
cmpl $0x0, 0x214(%rbx)
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r13)
xorl %eax, %eax
movl %eax, 0x20(%r13)
movq $0x0, 0x18(%r13)
movl %eax, 0x10(%r13)
movl %eax, 0x28(%r13)
movl 0x170(%rbx), %eax
movl %eax, 0x3c(%r13)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq