// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdhuff.c
// Function: start_pass_huff_decoder
METHODDEF(void)
start_pass_huff_decoder (j_decompress_ptr cinfo)
{
  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  int ci, blkn, dctbl, actbl;
  jpeg_component_info * compptr;

  /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
   * This ought to be an error condition, but we make it a warning because
   * there are some baseline files out there with all zeroes in these bytes.
   */
  if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
      cinfo->Ah != 0 || cinfo->Al != 0)
    WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);

  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
    compptr = cinfo->cur_comp_info[ci];
    dctbl = compptr->dc_tbl_no;
    actbl = compptr->ac_tbl_no;
    /* Compute derived values for Huffman tables */
    /* We may do this more than once for a table, but it's not expensive */
    jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
			    & entropy->dc_derived_tbls[dctbl]);
    jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
			    & entropy->ac_derived_tbls[actbl]);
    /* Initialize DC predictions to 0 */
    entropy->saved.last_dc_val[ci] = 0;
  }

  /* Precalculate decoding info for each block in an MCU of this scan */
  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
    ci = cinfo->MCU_membership[blkn];
    compptr = cinfo->cur_comp_info[ci];
    /* Precalculate which table to use for each block */
    entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
    entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
    /* Decide whether we really care about the coefficient values */
    if (compptr->component_needed) {
      entropy->dc_needed[blkn] = TRUE;
      /* we don't need the ACs if producing a 1/8th-size image */
      entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
    } else {
      entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
    }
  }

  /* 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 restart counter */
  entropy->restarts_to_go = cinfo->restart_interval;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x250(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
cmpl $0x0, 0x20c(%rax)
jne 0xe9d42
movq 0x20(%rsp), %rax
cmpl $0x3f, 0x210(%rax)
jne 0xe9d42
movq 0x20(%rsp), %rax
cmpl $0x0, 0x214(%rax)
jne 0xe9d42
movq 0x20(%rsp), %rax
cmpl $0x0, 0x218(%rax)
je 0xe9d69
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x7a, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x1b0(%rcx), %eax
jge 0xe9e21
movq 0x20(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq 0x1b8(%rax,%rcx,8), %rax
movq %rax, (%rsp)
movq (%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, 0xc(%rsp)
movq (%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rcx
addq $0x40, %rcx
movslq 0xc(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movl $0x1, %esi
callq 0xe9190
movq 0x20(%rsp), %rdi
movl 0x8(%rsp), %edx
movq 0x18(%rsp), %rcx
addq $0x60, %rcx
movslq 0x8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rcx
xorl %esi, %esi
callq 0xe9190
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movl $0x0, 0x28(%rax,%rcx,4)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xe9d71
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x1e0(%rcx), %eax
jge 0xe9f2f
movq 0x20(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl 0x1e4(%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
movq 0x20(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq 0x1b8(%rax,%rcx,8), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
movslq 0x14(%rcx), %rcx
movq 0x40(%rax,%rcx,8), %rdx
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movq %rdx, 0x80(%rax,%rcx,8)
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
movslq 0x18(%rcx), %rcx
movq 0x60(%rax,%rcx,8), %rdx
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movq %rdx, 0xd0(%rax,%rcx,8)
movq (%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0xe9ef3
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl $0x1, 0x120(%rax,%rcx,4)
movq (%rsp), %rax
cmpl $0x1, 0x24(%rax)
setg %al
andb $0x1, %al
movzbl %al, %edx
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl %edx, 0x148(%rax,%rcx,4)
jmp 0xe9f1d
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl $0x0, 0x148(%rax,%rcx,4)
movq 0x18(%rsp), %rax
movslq 0x10(%rsp), %rcx
movl $0x0, 0x120(%rax,%rcx,4)
jmp 0xe9f1f
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xe9e29
movq 0x18(%rsp), %rax
movl $0x0, 0x20(%rax)
movq 0x18(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x18(%rsp), %rax
movl $0x0, 0x10(%rax)
movq 0x20(%rsp), %rax
movl 0x170(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x38(%rax)
addq $0x28, %rsp
retq
nopl (%rax)