// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x58, %edx
movl $0x1, %esi
callq *(%rax)
movq %rax, %r14
movq %rax, 0x270(%rbx)
leaq 0x13d(%rip), %rax       # 0x85174
movq %rax, (%r14)
leaq 0x27c(%rip), %rax       # 0x852bd
movq %rax, 0x18(%r14)
xorl %eax, %eax
movq %rax, 0x40(%r14)
movq %rax, 0x50(%r14)
cmpl $0x3, 0x90(%rbx)
je 0x85067
movq (%rbx), %rax
movl $0x2f, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
movq 0x8(%rbx), %rax
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movl $0x1, %esi
callq *(%rax)
movq %rax, 0x30(%r14)
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
movl $0x1, %esi
callq *0x8(%rax)
movq 0x30(%r14), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq $0x20, %r15
jne 0x85081
movl $0x1, 0x38(%r14)
cmpl $0x0, 0x84(%rbx)
je 0x85119
movl 0x78(%rbx), %ebp
cmpl $0x7, %ebp
jg 0x850d8
movq (%rbx), %rax
movabsq $0x800000038, %rcx      # imm = 0x800000038
movq %rcx, 0x28(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
cmpl $0x101, %ebp            # imm = 0x101
jl 0x850f9
movq (%rbx), %rax
movabsq $0x10000000039, %rcx    # imm = 0x10000000039
movq %rcx, 0x28(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movq 0x8(%rbx), %rax
movq %rbx, %rdi
movl $0x1, %esi
movl %ebp, %edx
movl $0x3, %ecx
callq *0x10(%rax)
movq %rax, 0x20(%r14)
movl %ebp, 0x28(%r14)
jmp 0x85121
movq $0x0, 0x20(%r14)
cmpl $0x0, 0x70(%rbx)
je 0x8512e
movl $0x2, 0x70(%rbx)
cmpl $0x2, 0x70(%rbx)
jne 0x85169
movq 0x8(%rbx), %rax
movl 0x88(%rbx), %ecx
addl $0x2, %ecx
addq %rcx, %rcx
leaq (%rcx,%rcx,2), %rdx
movq %rbx, %rdi
movl $0x1, %esi
callq *0x8(%rax)
movq %rax, 0x40(%r14)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x852cc
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq