// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jquant2.c
// Function: start_pass_2_quant
METHODDEF(void)
start_pass_2_quant (j_decompress_ptr cinfo, jboolean is_pre_scan)
{
  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  hist3d histogram = cquantize->histogram;
  int i;

  /* 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;

  if (is_pre_scan) {
    /* Set up method pointers */
    cquantize->pub.color_quantize = prescan_quantize;
    cquantize->pub.finish_pass = finish_pass1;
    cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  } else {
    /* Set up method pointers */
    if (cinfo->dither_mode == JDITHER_FS)
      cquantize->pub.color_quantize = pass2_fs_dither;
    else
      cquantize->pub.color_quantize = pass2_no_dither;
    cquantize->pub.finish_pass = finish_pass2;

    /* Make sure color count is acceptable */
    i = cinfo->actual_number_of_colors;
    if (i < 1)
      ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
    if (i > MAXNUMCOLORS)
      ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);

    if (cinfo->dither_mode == JDITHER_FS) {
      size_t arraysize = (size_t) ((cinfo->output_width + 2) *
				   (3 * SIZEOF(FSERROR)));
      /* Allocate Floyd-Steinberg workspace if we didn't already. */
      if (cquantize->fserrors == NULL)
	cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
	  ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
      /* Initialize the propagated errors to zero. */
      jzero_far((void FAR *) cquantize->fserrors, arraysize);
      /* Make the error-limit table if we didn't already. */
      if (cquantize->error_limiter == NULL)
	init_error_limit(cinfo);
      cquantize->on_odd_row = FALSE;
    }

  }
  /* Zero the histogram or inverse color map, if necessary */
  if (cquantize->needs_zeroed) {
    for (i = 0; i < HIST_C0_ELEMS; i++) {
      jzero_far((void FAR *) histogram[i],
		HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
    }
    cquantize->needs_zeroed = FALSE;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x270(%rdi), %r15
movq 0x30(%r15), %r12
cmpl $0x0, 0x70(%rdi)
je 0x85197
movl $0x2, 0x70(%rbx)
testl %esi, %esi
je 0x851f1
leaq 0x1bb(%rip), %rax       # 0x8535d
movq %rax, 0x8(%r15)
leaq 0x21f(%rip), %rax       # 0x853cc
movq %rax, 0x10(%r15)
movl $0x1, %ebp
movl $0x38, %r14d
movl %ebp, (%r15,%r14)
cmpl $0x0, 0x38(%r15)
je 0x851e8
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x86b1f
incq %rbx
cmpq $0x20, %rbx
jne 0x851c9
movl $0x0, 0x38(%r15)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, 0x70(%rbx)
leaq 0x59a(%rip), %rax       # 0x85796
leaq 0x91f(%rip), %rcx       # 0x85b22
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
leaq 0xa05(%rip), %rax       # 0x85c17
movq %rax, 0x10(%r15)
movl 0x9c(%rbx), %ebp
testl %ebp, %ebp
jg 0x85239
movq (%rbx), %rax
movabsq $0x100000038, %rcx      # imm = 0x100000038
movq %rcx, 0x28(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
cmpl $0x101, %ebp            # imm = 0x101
jl 0x8525a
movq (%rbx), %rax
movabsq $0x10000000039, %rcx    # imm = 0x10000000039
movq %rcx, 0x28(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
cmpl $0x2, 0x70(%rbx)
jne 0x851c0
movl 0x88(%rbx), %eax
addl $0x2, %eax
addq %rax, %rax
leaq (%rax,%rax,2), %r14
cmpq $0x0, 0x40(%r15)
jne 0x85291
movq 0x8(%rbx), %rax
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq *0x8(%rax)
movq %rax, 0x40(%r15)
movq 0x40(%r15), %rdi
movq %r14, %rsi
callq 0x86b1f
xorl %ebp, %ebp
movl $0x48, %r14d
cmpq $0x0, 0x50(%r15)
jne 0x851bc
movq %rbx, %rdi
callq 0x852cc
jmp 0x851bc