// File: /workspace/github_cpp_makefile_star2_O2/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 0x779d8
movl $0x2, 0x70(%rbx)
testl %esi, %esi
jne 0x779dc
leaq 0x5b7(%rip), %rax       # 0x77f8d
jmp 0x77a34
testl %esi, %esi
je 0x77a2d
leaq 0x194(%rip), %rax       # 0x77b77
movq %rax, 0x8(%r15)
leaq 0x1f8(%rip), %rax       # 0x77be6
movq %rax, 0x10(%r15)
pushq $0x1
popq %rbp
pushq $0x38
popq %r14
movl %ebp, (%r15,%r14)
cmpl $0x0, 0x38(%r15)
je 0x77a24
xorl %ebx, %ebx
cmpq $0x20, %rbx
je 0x77a1f
movq (%r12,%rbx,8), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x791cd
incq %rbx
jmp 0x77a06
andl $0x0, 0x38(%r15)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x895(%rip), %rax       # 0x782c9
movq %rax, 0x8(%r15)
leaq 0x963(%rip), %rax       # 0x783a2
movq %rax, 0x10(%r15)
movl 0x9c(%rbx), %eax
testl %eax, %eax
jle 0x77a5e
cmpl $0x101, %eax            # imm = 0x101
jb 0x77a75
movsd 0x23f54(%rip), %xmm0    # 0x9b9b0
jmp 0x77a66
movsd 0x23f5a(%rip), %xmm0    # 0x9b9c0
movq (%rbx), %rax
movlps %xmm0, 0x28(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
cmpl $0x2, 0x70(%rbx)
jne 0x779fd
movl 0x88(%rbx), %eax
addl $0x2, %eax
imulq $0x6, %rax, %r14
movq 0x40(%r15), %rdi
testq %rdi, %rdi
jne 0x77aa8
movq 0x8(%rbx), %rax
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq *0x8(%rax)
movq %rax, %rdi
movq %rax, 0x40(%r15)
movq %r14, %rsi
callq 0x791cd
xorl %ebp, %ebp
pushq $0x48
popq %r14
cmpq $0x0, 0x50(%r15)
jne 0x779f9
movq %rbx, %rdi
callq 0x77add
jmp 0x779f9