// File: /workspace/github_cpp_makefile_star2_O3/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 0x83b3e
cmpl $0x1, %eax
je 0x83a31
testl %eax, %eax
jne 0x83b9b
cmpl $0x3, 0x90(%rbx)
jne 0x83bb3
leaq 0x33d(%rip), %rax       # 0x83d69
jmp 0x83bba
cmpl $0x3, 0x90(%rbx)
leaq 0x42c(%rip), %rax       # 0x83e6b
leaq 0x53a(%rip), %rcx       # 0x83f80
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
movl $0x0, 0x4c(%r15)
cmpl $0x0, 0x38(%r15)
jne 0x83a65
movq %rbx, %rdi
callq 0x83bd5
cmpq $0x0, 0x50(%r15)
jne 0x83bbe
movl 0x90(%rbx), %eax
testl %eax, %eax
jle 0x83bbe
movq 0x270(%rbx), %r14
xorl %r15d, %r15d
leaq 0x270d1(%rip), %r12     # 0xaab60
movslq 0x3c(%r14,%r15,4), %r13
testq %r15, %r15
je 0x83ab6
xorl %ecx, %ecx
cmpl 0x3c(%r14,%rcx,4), %r13d
je 0x83aac
incq %rcx
cmpq %rcx, %r15
jne 0x83a9b
jmp 0x83ab6
movq 0x50(%r14,%rcx,8), %rcx
testq %rcx, %rcx
jne 0x83b25
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 0x83ae3
incq %r8
addq $0x40, %rdi
addq $0x10, %rsi
cmpq $0x10, %r8
jne 0x83ae0
movl 0x90(%rbx), %eax
movq %rcx, 0x50(%r14,%r15,8)
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x83a8f
jmp 0x83bbe
leaq 0x531(%rip), %rax       # 0x84076
movq %rax, 0x8(%r15)
movl $0x0, 0x90(%r15)
cmpq $0x0, 0x70(%r15)
jne 0x83b63
movq %rbx, %rdi
callq 0x83d0b
cmpl $0x0, 0x90(%rbx)
jle 0x83bbe
movl 0x88(%rbx), %r14d
addl $0x2, %r14d
addq %r14, %r14
xorl %r12d, %r12d
movq 0x70(%r15,%r12,8), %rdi
movq %r14, %rsi
callq 0x85d17
incq %r12
movslq 0x90(%rbx), %rax
cmpq %rax, %r12
jl 0x83b7d
jmp 0x83bbe
movq (%rbx), %rax
movl $0x30, 0x28(%rax)
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmpq *(%rax)
leaq 0x227(%rip), %rax       # 0x83de1
movq %rax, 0x8(%r15)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq