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

  /* Install my colormap. */
  cinfo->colormap = cquantize->sv_colormap;
  cinfo->actual_number_of_colors = cquantize->sv_actual;

  /* Initialize for desired dithering mode. */
  switch (cinfo->dither_mode) {
  case JDITHER_NONE:
    if (cinfo->out_color_components == 3)
      cquantize->pub.color_quantize = color_quantize3;
    else
      cquantize->pub.color_quantize = color_quantize;
    break;
  case JDITHER_ORDERED:
    if (cinfo->out_color_components == 3)
      cquantize->pub.color_quantize = quantize3_ord_dither;
    else
      cquantize->pub.color_quantize = quantize_ord_dither;
    cquantize->row_index = 0;	/* initialize state for ordered dither */
    /* If user changed to ordered dither from another mode,
     * we must recreate the color index table with padding.
     * This will cost extra space, but probably isn't very likely.
     */
    if (! cquantize->is_padded)
      create_colorindex(cinfo);
    /* Create ordered-dither tables if we didn't already. */
    if (cquantize->odither[0] == NULL)
      create_odither_tables(cinfo);
    break;
  case JDITHER_FS:
    cquantize->pub.color_quantize = quantize_fs_dither;
    cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
    /* Allocate Floyd-Steinberg workspace if didn't already. */
    if (cquantize->fserrors[0] == NULL)
      alloc_fs_workspace(cinfo);
    /* Initialize the propagated errors to zero. */
    arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
    for (i = 0; i < cinfo->out_color_components; i++)
      jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
    break;
  default:
    ERREXIT(cinfo, JERR_NOT_COMPILED);
    break;
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x270(%rdi), %r15
movq 0x20(%r15), %rax
movq %rax, 0xa0(%rdi)
movl 0x28(%r15), %eax
movl %eax, 0x9c(%rdi)
movl 0x70(%rdi), %eax
cmpl $0x2, %eax
je 0x84921
cmpl $0x1, %eax
je 0x84815
testl %eax, %eax
jne 0x8497e
cmpl $0x3, 0x90(%rbx)
jne 0x84996
leaq 0x33b(%rip), %rax       # 0x84b4b
jmp 0x8499d
cmpl $0x3, 0x90(%rbx)
leaq 0x429(%rip), %rax       # 0x84c4c
leaq 0x536(%rip), %rcx       # 0x84d60
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
movl $0x0, 0x4c(%r15)
cmpl $0x0, 0x38(%r15)
jne 0x84849
movq %rbx, %rdi
callq 0x849b8
cmpq $0x0, 0x50(%r15)
jne 0x849a1
cmpl $0x0, 0x90(%rbx)
jle 0x849a1
movq 0x270(%rbx), %r14
xorl %r15d, %r15d
leaq 0x262de(%rip), %r12     # 0xaab50
movslq 0x3c(%r14,%r15,4), %r13
testq %r15, %r15
je 0x8488d
xorl %eax, %eax
cmpl 0x3c(%r14,%rax,4), %r13d
je 0x84891
incq %rax
cmpq %rax, %r15
jne 0x8487e
xorl %ecx, %ecx
jmp 0x84896
movq 0x50(%r14,%rax,8), %rcx
testq %rcx, %rcx
jne 0x84904
movq 0x8(%rbx), %rax
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
movl $0x1, %esi
callq *(%rax)
movq %rax, %rcx
shlq $0x9, %r13
addq $-0x200, %r13           # imm = 0xFE00
movq %r12, %rsi
movq %rax, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movzbl (%rsi,%r9), %eax
addl %eax, %eax
movl $0xff, %edx
subq %rax, %rdx
movq %rdx, %rax
shlq $0x8, %rax
subq %rdx, %rax
cqto
idivq %r13
movl %eax, (%rdi,%r9,4)
incq %r9
cmpq $0x10, %r9
jne 0x848c8
incq %r8
addq $0x40, %rdi
addq $0x10, %rsi
cmpq $0x10, %r8
jne 0x848c5
movq %rcx, 0x50(%r14,%r15,8)
incq %r15
movslq 0x90(%rbx), %rax
cmpq %rax, %r15
jl 0x84872
jmp 0x849a1
leaq 0x51c(%rip), %rax       # 0x84e44
movq %rax, 0x8(%r15)
movl $0x0, 0x90(%r15)
cmpq $0x0, 0x70(%r15)
jne 0x84946
movq %rbx, %rdi
callq 0x84aed
cmpl $0x0, 0x90(%rbx)
jle 0x849a1
movl 0x88(%rbx), %r14d
addl $0x2, %r14d
addq %r14, %r14
xorl %r12d, %r12d
movq 0x70(%r15,%r12,8), %rdi
movq %r14, %rsi
callq 0x86b1f
incq %r12
movslq 0x90(%rbx), %rax
cmpq %rax, %r12
jl 0x84960
jmp 0x849a1
movq (%rbx), %rax
movl $0x30, 0x28(%rax)
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmpq *(%rax)
leaq 0x226(%rip), %rax       # 0x84bc3
movq %rax, 0x8(%r15)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq