// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
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 0x771a3
cmpl $0x1, %eax
je 0x770ae
testl %eax, %eax
jne 0x771f4
cmpl $0x3, 0x90(%rbx)
jne 0x77211
leaq 0x31b(%rip), %rax       # 0x773c4
jmp 0x77218
cmpl $0x3, 0x90(%rbx)
leaq 0x3fb(%rip), %rax       # 0x774b7
leaq 0x4ed(%rip), %rcx       # 0x775b0
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
andl $0x0, 0x4c(%r15)
cmpl $0x0, 0x38(%r15)
jne 0x770df
movq %rbx, %rdi
callq 0x77238
cmpq $0x0, 0x50(%r15)
jne 0x7721c
movq 0x270(%rbx), %r14
xorl %r15d, %r15d
pushq $0x1
popq %rbp
leaq 0x24792(%rip), %r12     # 0x9b890
movslq 0x90(%rbx), %rax
cmpq %rax, %r15
jge 0x7721c
movslq 0x3c(%r14,%r15,4), %r13
xorl %eax, %eax
cmpq %rax, %r15
je 0x7713c
leaq 0x1(%rax), %rcx
cmpl 0x3c(%r14,%rax,4), %r13d
movq %rcx, %rax
jne 0x77115
movq 0x48(%r14,%rcx,8), %rcx
testq %rcx, %rcx
je 0x7713c
movq %rcx, 0x50(%r14,%r15,8)
incq %r15
jmp 0x770fe
movq 0x8(%rbx), %rax
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
movl %ebp, %esi
callq *(%rax)
movq %rax, %rcx
shlq $0x9, %r13
addq $-0x200, %r13           # imm = 0xFE00
movq %r12, %rsi
movq %rax, %rdi
xorl %r8d, %r8d
cmpq $0x10, %r8
je 0x77132
xorl %r9d, %r9d
cmpq $0x10, %r9
je 0x77196
movzbl (%rsi,%r9), %eax
addl %eax, %eax
movl $0xff, %edx
subq %rax, %rdx
imulq $0xff, %rdx, %rax
cqto
idivq %r13
movl %eax, (%rdi,%r9,4)
incq %r9
jmp 0x7716c
incq %r8
addq $0x40, %rdi
addq $0x10, %rsi
jmp 0x77163
leaq 0x4f9(%rip), %rax       # 0x776a3
movq %rax, 0x8(%r15)
andl $0x0, 0x90(%r15)
cmpq $0x0, 0x70(%r15)
jne 0x771c5
movq %rbx, %rdi
callq 0x77370
movl 0x88(%rbx), %r14d
addl $0x2, %r14d
addq %r14, %r14
xorl %r12d, %r12d
movslq 0x90(%rbx), %rax
cmpq %rax, %r12
jge 0x7721c
movq 0x70(%r15,%r12,8), %rdi
movq %r14, %rsi
callq 0x791cd
incq %r12
jmp 0x771d6
movq (%rbx), %rax
movl $0x30, 0x28(%rax)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *(%rax)
leaq 0x223(%rip), %rax       # 0x7743b
movq %rax, 0x8(%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq