// File: 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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movq 0x270(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0xa0(%rax)
movq 0x10(%rsp), %rax
movl 0x28(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x9c(%rax)
movq 0x20(%rsp), %rax
movl 0x70(%rax), %eax
movl %eax, (%rsp)
testl %eax, %eax
je 0xf4452
jmp 0xf4437
movl (%rsp), %eax
subl $0x1, %eax
je 0xf4487
jmp 0xf4441
movl (%rsp), %eax
subl $0x2, %eax
je 0xf44f3
jmp 0xf4581
movq 0x20(%rsp), %rax
cmpl $0x3, 0x90(%rax)
jne 0xf4472
movq 0x10(%rsp), %rax
leaq 0x664(%rip), %rcx       # 0xf4ad0
movq %rcx, 0x8(%rax)
jmp 0xf4482
movq 0x10(%rsp), %rax
leaq 0x7c2(%rip), %rcx       # 0xf4c40
movq %rcx, 0x8(%rax)
jmp 0xf45a2
movq 0x20(%rsp), %rax
cmpl $0x3, 0x90(%rax)
jne 0xf44a7
movq 0x10(%rsp), %rax
leaq 0x8df(%rip), %rcx       # 0xf4d80
movq %rcx, 0x8(%rax)
jmp 0xf44b7
movq 0x10(%rsp), %rax
leaq 0xaed(%rip), %rcx       # 0xf4fa0
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x4c(%rax)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x38(%rax)
jne 0xf44d8
movq 0x20(%rsp), %rdi
callq 0xf4830
movq 0x10(%rsp), %rax
cmpq $0x0, 0x50(%rax)
jne 0xf44ee
movq 0x20(%rsp), %rdi
callq 0xf5170
jmp 0xf45a2
movq 0x10(%rsp), %rax
leaq 0xd61(%rip), %rcx       # 0xf5260
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x90(%rax)
movq 0x10(%rsp), %rax
cmpq $0x0, 0x70(%rax)
jne 0xf4528
movq 0x20(%rsp), %rdi
callq 0xf4a40
movq 0x20(%rsp), %rax
movl 0x88(%rax), %eax
addl $0x2, %eax
movl %eax, %eax
shlq %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x90(%rcx), %eax
jge 0xf457f
movq 0x10(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq 0x70(%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rsi
callq 0xf9470
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0xf4548
jmp 0xf45a2
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x30, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
addq $0x28, %rsp
retq
nopw (%rax,%rax)