// File: /workspace/github_cpp_makefile_star2_O3/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), %r15
movl %esi, 0x4(%rsp)
testl %esi, %esi
leaq 0x477(%rip), %rax       # 0x7748f
leaq 0x179(%rip), %rcx       # 0x77198
cmoveq %rax, %rcx
leaq 0xde3(%rip), %rax       # 0x77e0d
leaq 0x37a(%rip), %rdx       # 0x773ab
cmoveq %rax, %rdx
movq %rcx, 0x8(%r15)
movq %rdx, 0x10(%r15)
cmpl $0x0, 0x144(%rdi)
jle 0x7716d
leaq 0x40(%r15), %rax
movq %rax, 0x10(%rsp)
leaq 0x60(%r15), %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
movq 0x148(%rbx,%r12,8), %rax
movl 0x14(%rax), %edx
movl 0x18(%rax), %r14d
movslq %edx, %rbp
movslq %r14d, %r13
cmpl $0x0, 0x4(%rsp)
je 0x77125
cmpl $0x4, %edx
jb 0x77099
movq (%rbx), %rax
movl $0x32, 0x28(%rax)
movl %edx, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
cmpl $0x4, %r14d
jb 0x770b5
movq (%rbx), %rax
movl $0x32, 0x28(%rax)
movl %r14d, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq 0x80(%r15,%rbp,8), %rdi
testq %rdi, %rdi
jne 0x770e0
movq 0x8(%rbx), %rax
movl $0x808, %edx            # imm = 0x808
movq %rbx, %rdi
movl $0x1, %esi
callq *(%rax)
movq %rax, %rdi
movq %rax, 0x80(%r15,%rbp,8)
movl $0x808, %edx            # imm = 0x808
xorl %esi, %esi
callq 0xe260
movq 0xa0(%r15,%r13,8), %rdi
testq %rdi, %rdi
jne 0x77117
movq 0x8(%rbx), %rax
movl $0x808, %edx            # imm = 0x808
movq %rbx, %rdi
movl $0x1, %esi
callq *(%rax)
movq %rax, %rdi
movq %rax, 0xa0(%r15,%r13,8)
movl $0x808, %edx            # imm = 0x808
xorl %esi, %esi
callq 0xe260
jmp 0x77151
movq 0x10(%rsp), %rax
leaq (%rax,%rbp,8), %rcx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x76b74
movq 0x8(%rsp), %rax
leaq (%rax,%r13,8), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x76b74
movl $0x0, 0x24(%r15,%r12,4)
incq %r12
movslq 0x144(%rbx), %rax
cmpq %rax, %r12
jl 0x7705f
movq $0x0, 0x18(%r15)
xorl %eax, %eax
movl %eax, 0x20(%r15)
movl 0x118(%rbx), %ecx
movl %ecx, 0x38(%r15)
movl %eax, 0x3c(%r15)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq