// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jquant2.c
// Function: jinit_2pass_quantizer
GLOBAL(void)
jinit_2pass_quantizer (j_decompress_ptr cinfo)
{
  my_cquantize_ptr cquantize;
  int i;

  cquantize = (my_cquantize_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_cquantizer));
  cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  cquantize->pub.start_pass = start_pass_2_quant;
  cquantize->pub.new_color_map = new_color_map_2_quant;
  cquantize->fserrors = NULL;	/* flag optional arrays not allocated */
  cquantize->error_limiter = NULL;

  /* Make sure jdmaster didn't give me a case I can't handle */
  if (cinfo->out_color_components != 3)
    ERREXIT(cinfo, JERR_NOTIMPL);

  /* Allocate the histogram/inverse colormap storage */
  cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
    ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  for (i = 0; i < HIST_C0_ELEMS; i++) {
    cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
      ((j_common_ptr) cinfo, JPOOL_IMAGE,
       HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  }
  cquantize->needs_zeroed = TRUE; /* histogram is garbage now */

  /* Allocate storage for the completed colormap, if required.
   * We do this now since it is FAR storage and may affect
   * the memory manager's space calculations.
   */
  if (cinfo->enable_2pass_quant) {
    /* Make sure color count is acceptable */
    int desired = cinfo->desired_number_of_colors;
    /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */
    if (desired < 8)
      ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
    /* Make sure colormap indexes can be represented by JSAMPLEs */
    if (desired > MAXNUMCOLORS)
      ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
    cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
      ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
    cquantize->desired = desired;
  } else
    cquantize->sv_colormap = NULL;

  /* Only F-S dithering or no dithering is supported. */
  /* If user asks for ordered dither, give him F-S. */
  if (cinfo->dither_mode != JDITHER_NONE)
    cinfo->dither_mode = JDITHER_FS;

  /* Allocate Floyd-Steinberg workspace if necessary.
   * This isn't really needed until pass 2, but again it is FAR storage.
   * Although we will cope with a later change in dither_mode,
   * we do not promise to honor max_memory_to_use if dither_mode changes.
   */
  if (cinfo->dither_mode == JDITHER_FS) {
    cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
      ((j_common_ptr) cinfo, JPOOL_IMAGE,
       (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
    /* Might as well create the error-limiting table too. */
    init_error_limit(cinfo);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rax
pushq $0x1
popq %rsi
pushq $0x58
popq %rdx
callq *(%rax)
movq %rax, %r14
movq %rax, 0x270(%rbx)
leaq 0x119(%rip), %rax       # 0x779a8
movq %rax, (%r14)
leaq 0x235(%rip), %rax       # 0x77ace
movq %rax, 0x18(%r14)
andq $0x0, 0x40(%r14)
andq $0x0, 0x50(%r14)
cmpl $0x3, 0x90(%rbx)
je 0x778bf
movq (%rbx), %rax
movl $0x2f, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
movq 0x8(%rbx), %rax
pushq $0x1
popq %rbp
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movl %ebp, %esi
callq *(%rax)
movq %rax, 0x30(%r14)
xorl %r15d, %r15d
cmpq $0x20, %r15
je 0x778fd
movq 0x8(%rbx), %rax
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
movl %ebp, %esi
callq *0x8(%rax)
movq 0x30(%r14), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x778d9
movl $0x1, 0x38(%r14)
cmpl $0x0, 0x84(%rbx)
je 0x77920
movl 0x78(%rbx), %ebp
cmpl $0x8, %ebp
jge 0x77927
movsd 0x24082(%rip), %xmm0    # 0x9b9a0
jmp 0x77937
andq $0x0, 0x20(%r14)
jmp 0x77960
cmpl $0x101, %ebp            # imm = 0x101
jb 0x77946
movsd 0x24079(%rip), %xmm0    # 0x9b9b0
movq (%rbx), %rax
movlps %xmm0, 0x28(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq 0x8(%rbx), %rax
pushq $0x1
popq %rsi
pushq $0x3
popq %rcx
movq %rbx, %rdi
movl %ebp, %edx
callq *0x10(%rax)
movq %rax, 0x20(%r14)
movl %ebp, 0x28(%r14)
cmpl $0x0, 0x70(%rbx)
je 0x7799d
movl $0x2, 0x70(%rbx)
movq 0x8(%rbx), %rax
movl 0x88(%rbx), %ecx
addl $0x2, %ecx
imulq $0x6, %rcx, %rdx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq *0x8(%rax)
movq %rax, 0x40(%r14)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x77add
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq