// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jchuff.c
// Function: start_pass_huff
METHODDEF(void)
start_pass_huff (j_compress_ptr cinfo, jboolean gather_statistics)
{
  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  int ci, dctbl, actbl;
  jpeg_component_info * compptr;

  if (gather_statistics) {
#ifdef ENTROPY_OPT_SUPPORTED
    entropy->pub.encode_mcu = encode_mcu_gather;
    entropy->pub.finish_pass = finish_pass_gather;
#else
    ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
  } else {
    entropy->pub.encode_mcu = encode_mcu_huff;
    entropy->pub.finish_pass = finish_pass_huff;
  }

  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;
    if (gather_statistics) {
#ifdef ENTROPY_OPT_SUPPORTED
      /* Check for invalid table indexes */
      /* (make_c_derived_tbl does this in the other path) */
      if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
	ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
      if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
	ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
      /* Allocate and zero the statistics tables */
      /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
      if (entropy->dc_count_ptrs[dctbl] == NULL)
	entropy->dc_count_ptrs[dctbl] = (long *)
	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				      257 * SIZEOF(long));
      MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
      if (entropy->ac_count_ptrs[actbl] == NULL)
	entropy->ac_count_ptrs[actbl] = (long *)
	  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				      257 * SIZEOF(long));
      MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
#endif
    } else {
      /* Compute derived values for Huffman tables */
      /* We may do this more than once for a table, but it's not expensive */
      jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
			      & entropy->dc_derived_tbls[dctbl]);
      jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
			      & entropy->ac_derived_tbls[actbl]);
    }
    /* Initialize DC predictions to 0 */
    entropy->saved.last_dc_val[ci] = 0;
  }

  /* Initialize bit buffer to empty */
  entropy->saved.put_buffer = 0;
  entropy->saved.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
movq %rdi, %rbx
movq 0x1f0(%rdi), %r12
movl %esi, 0x4(%rsp)
testl %esi, %esi
leaq 0x3e9(%rip), %rax       # 0x6ccb3
leaq 0x16d(%rip), %rcx       # 0x6ca3e
cmoveq %rax, %rcx
leaq 0x73a(%rip), %rax       # 0x6d016
leaq 0x2f4(%rip), %rdx       # 0x6cbd7
cmoveq %rax, %rdx
movq %rcx, 0x8(%r12)
movq %rdx, 0x10(%r12)
leaq 0x40(%r12), %rax
movq %rax, 0x10(%rsp)
leaq 0x60(%r12), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movslq 0x144(%rbx), %rax
cmpq %rax, %r13
jge 0x6ca12
movq 0x148(%rbx,%r13,8), %rax
movl 0x14(%rax), %edx
movl 0x18(%rax), %r15d
movslq %edx, %rbp
movslq %r15d, %r14
cmpl $0x0, 0x4(%rsp)
je 0x6c9da
cmpl $0x4, %edx
jb 0x6c952
movq (%rbx), %rax
movl $0x32, 0x28(%rax)
movl %edx, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
cmpl $0x4, %r15d
jb 0x6c96e
movq (%rbx), %rax
movl $0x32, 0x28(%rax)
movl %r15d, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq 0x80(%r12,%rbp,8), %rdi
testq %rdi, %rdi
jne 0x6c997
movq 0x8(%rbx), %rax
movl $0x808, %edx            # imm = 0x808
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq *(%rax)
movq %rax, %rdi
movq %rax, 0x80(%r12,%rbp,8)
movl $0x808, %edx            # imm = 0x808
xorl %esi, %esi
callq 0xe270
movq 0xa0(%r12,%r14,8), %rdi
testq %rdi, %rdi
jne 0x6c9cc
movq 0x8(%rbx), %rax
movl $0x808, %edx            # imm = 0x808
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq *(%rax)
movq %rax, %rdi
movq %rax, 0xa0(%r12,%r14,8)
movl $0x808, %edx            # imm = 0x808
xorl %esi, %esi
callq 0xe270
jmp 0x6ca04
movq 0x10(%rsp), %rax
leaq (%rax,%rbp,8), %rcx
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x6c40c
movq 0x8(%rsp), %rax
leaq (%rax,%r14,8), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x6c40c
andl $0x0, 0x24(%r12,%r13,4)
incq %r13
jmp 0x6c908
andq $0x0, 0x18(%r12)
andl $0x0, 0x20(%r12)
movl 0x118(%rbx), %eax
movl %eax, 0x38(%r12)
andl $0x0, 0x3c(%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq