// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jcphuff.c
// Function: start_pass_phuff
METHODDEF(void)
start_pass_phuff (j_compress_ptr cinfo, jboolean gather_statistics)
{  
  phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  jboolean is_DC_band;
  int ci, tbl;
  jpeg_component_info * compptr;

  entropy->cinfo = cinfo;
  entropy->gather_statistics = gather_statistics;

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

  /* We assume jcmaster.c already validated the scan parameters. */

  /* Select execution routines */
  if (cinfo->Ah == 0) {
    if (is_DC_band)
      entropy->pub.encode_mcu = encode_mcu_DC_first;
    else
      entropy->pub.encode_mcu = encode_mcu_AC_first;
  } else {
    if (is_DC_band)
      entropy->pub.encode_mcu = encode_mcu_DC_refine;
    else {
      entropy->pub.encode_mcu = encode_mcu_AC_refine;
      /* AC refinement needs a correction bit buffer */
      if (entropy->bit_buffer == NULL)
	entropy->bit_buffer = (char *)
	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				      MAX_CORR_BITS * SIZEOF(char));
    }
  }
  if (gather_statistics)
    entropy->pub.finish_pass = finish_pass_gather_phuff;
  else
    entropy->pub.finish_pass = finish_pass_phuff;

  /* Only DC coefficients may be interleaved, so cinfo->comps_in_scan = 1
   * for AC coefficients.
   */
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
    compptr = cinfo->cur_comp_info[ci];
    /* Initialize DC predictions to 0 */
    entropy->last_dc_val[ci] = 0;
    /* Get table index */
    if (is_DC_band) {
      if (cinfo->Ah != 0)	/* DC refinement needs no table */
	continue;
      tbl = compptr->dc_tbl_no;
    } else {
      entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
    }
    if (gather_statistics) {
      /* Check for invalid table index */
      /* (make_c_derived_tbl does this in the other path) */
      if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
        ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
      /* Allocate and zero the statistics tables */
      /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
      if (entropy->count_ptrs[tbl] == NULL)
	entropy->count_ptrs[tbl] = (long *)
	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				      257 * SIZEOF(long));
      MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
    } else {
      /* Compute derived values for Huffman table */
      /* We may do this more than once for a table, but it's not expensive */
      jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
			      & entropy->derived_tbls[tbl]);
    }
  }

  /* Initialize AC stuff */
  entropy->EOBRUN = 0;
  entropy->BE = 0;

  /* Initialize bit buffer to empty */
  entropy->put_buffer = 0;
  entropy->put_bits = 0;

  /* Initialize restart stuff */
  entropy->restarts_to_go = cinfo->restart_interval;
  entropy->next_restart_num = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x1f0(%rdi), %r12
movq %rdi, 0x40(%r12)
movl %esi, 0x18(%r12)
movl 0x19c(%rdi), %r13d
movl $0x0, 0xc(%rsp)
testl %r13d, %r13d
sete %r14b
cmpl $0x0, 0x1a4(%rdi)
je 0x6d27e
testl %r13d, %r13d
je 0x6d28c
leaq 0x52c(%rip), %rax       # 0x6d785
movq %rax, 0x8(%r12)
cmpq $0x0, 0x68(%r12)
jne 0x6d2a1
movq 0x8(%rbx), %rax
pushq $0x1
popq %rsi
movl $0x3e8, %edx            # imm = 0x3E8
movq %rbx, %rdi
callq *(%rax)
movq %rax, 0x68(%r12)
jmp 0x6d2a1
testl %r13d, %r13d
je 0x6d295
leaq 0x279(%rip), %rax       # 0x6d503
jmp 0x6d29c
leaq 0x430(%rip), %rax       # 0x6d6c3
jmp 0x6d29c
leaq 0x116(%rip), %rax       # 0x6d3b2
movq %rax, 0x8(%r12)
movl 0xc(%rsp), %eax
movb %r14b, %al
movl %eax, 0xc(%rsp)
testl %ebp, %ebp
leaq 0x7e3(%rip), %rax       # 0x6da98
leaq 0x711(%rip), %rcx       # 0x6d9cd
cmoveq %rax, %rcx
movq %rcx, 0x10(%r12)
leaq 0x78(%r12), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movslq 0x144(%rbx), %rax
cmpq %rax, %r14
jge 0x6d380
movq 0x148(%rbx,%r14,8), %rax
andl $0x0, 0x48(%r12,%r14,4)
testl %r13d, %r13d
je 0x6d355
movl 0x18(%rax), %edx
movl %edx, 0x58(%r12)
movslq %edx, %r15
testl %ebp, %ebp
je 0x6d363
cmpl $0x4, %edx
jb 0x6d31e
movq (%rbx), %rax
movl $0x32, 0x28(%rax)
movl %edx, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq 0x98(%r12,%r15,8), %rdi
testq %rdi, %rdi
jne 0x6d347
movq 0x8(%rbx), %rax
movl $0x808, %edx            # imm = 0x808
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq *(%rax)
movq %rax, %rdi
movq %rax, 0x98(%r12,%r15,8)
movl $0x808, %edx            # imm = 0x808
xorl %esi, %esi
callq 0xe270
jmp 0x6d378
cmpl $0x0, 0x1a4(%rbx)
jne 0x6d378
movl 0x14(%rax), %edx
jmp 0x6d2fd
movq 0x10(%rsp), %rax
leaq (%rax,%r15,8), %rcx
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x6c40c
incq %r14
jmp 0x6d2d2
andq $0x0, 0x5c(%r12)
andq $0x0, 0x30(%r12)
andl $0x0, 0x38(%r12)
movl 0x118(%rbx), %eax
movl %eax, 0x70(%r12)
andl $0x0, 0x74(%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq