// File: /workspace/github_cpp_makefile_star2_O3/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 0x843c1
movl $0x2, 0x70(%rbx)
testl %esi, %esi
jne 0x843c5
leaq 0x600(%rip), %rax       # 0x849bf
jmp 0x84422
testl %esi, %esi
je 0x8441b
leaq 0x197(%rip), %rax       # 0x84563
movq %rax, 0x8(%r15)
leaq 0x1fb(%rip), %rax       # 0x845d2
movq %rax, 0x10(%r15)
movl $0x1, %ebp
movl $0x38, %r14d
movl %ebp, (%r15,%r14)
cmpl $0x0, 0x38(%r15)
je 0x84412
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x85d17
incq %rbx
cmpq $0x20, %rbx
jne 0x843f3
movl $0x0, 0x38(%r15)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x904(%rip), %rax       # 0x84d26
movq %rax, 0x8(%r15)
leaq 0x9e0(%rip), %rax       # 0x84e0d
movq %rax, 0x10(%r15)
movl 0x9c(%rbx), %eax
testl %eax, %eax
jle 0x8444c
cmpl $0x101, %eax            # imm = 0x101
jb 0x84463
movsd 0x26836(%rip), %xmm0    # 0xaac80
jmp 0x84454
movsd 0x2683c(%rip), %xmm0    # 0xaac90
movq (%rbx), %rax
movlps %xmm0, 0x28(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
cmpl $0x2, 0x70(%rbx)
jne 0x843ea
movl 0x88(%rbx), %eax
addl $0x2, %eax
addq %rax, %rax
leaq (%rax,%rax,2), %r14
movq 0x40(%r15), %rdi
testq %rdi, %rdi
jne 0x8449b
movq 0x8(%rbx), %rax
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq *0x8(%rax)
movq %rax, %rdi
movq %rax, 0x40(%r15)
movq %r14, %rsi
callq 0x85d17
xorl %ebp, %ebp
movl $0x48, %r14d
cmpq $0x0, 0x50(%r15)
jne 0x843e6
movq %rbx, %rdi
callq 0x844d2
jmp 0x843e6