// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jquant1.c
// Function: create_colorindex
LOCAL(void)
create_colorindex (j_decompress_ptr cinfo)
{
  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  JSAMPROW indexptr;
  int i,j,k, nci, blksize, val, pad;

  /* For ordered dither, we pad the color index tables by MAXJSAMPLE in
   * each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).
   * This is not necessary in the other dithering modes.  However, we
   * flag whether it was done in case user changes dithering mode.
   */
  if (cinfo->dither_mode == JDITHER_ORDERED) {
    pad = MAXJSAMPLE*2;
    cquantize->is_padded = TRUE;
  } else {
    pad = 0;
    cquantize->is_padded = FALSE;
  }

  cquantize->colorindex = (*cinfo->mem->alloc_sarray)
    ((j_common_ptr) cinfo, JPOOL_IMAGE,
     (JDIMENSION) (MAXJSAMPLE+1 + pad),
     (JDIMENSION) cinfo->out_color_components);

  /* blksize is number of adjacent repeated entries for a component */
  blksize = cquantize->sv_actual;

  for (i = 0; i < cinfo->out_color_components; i++) {
    /* fill in colorindex entries for i'th color component */
    nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
    blksize = blksize / nci;

    /* adjust colorindex pointers to provide padding at negative indexes. */
    if (pad)
      cquantize->colorindex[i] += MAXJSAMPLE;

    /* in loop, val = index of current output value, */
    /* and k = largest j that maps to current val */
    indexptr = cquantize->colorindex[i];
    val = 0;
    k = largest_input_value(cinfo, i, 0, nci-1);
    for (j = 0; j <= MAXJSAMPLE; j++) {
      while (j > k)		/* advance val if past boundary */
	k = largest_input_value(cinfo, i, ++val, nci-1);
      /* premultiply so that no multiplication needed in main processing */
      indexptr[j] = (JSAMPLE) (val * blksize);
    }
    /* Pad at both ends if necessary */
    if (pad)
      for (j = 1; j <= MAXJSAMPLE; j++) {
	indexptr[-j] = indexptr[0];
	indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
      }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x270(%rdi), %r14
movl 0x70(%rdi), %ebp
xorl %eax, %eax
cmpl $0x1, %ebp
movl $0x2fe, %ecx            # imm = 0x2FE
movl $0x100, %edx            # imm = 0x100
cmovel %ecx, %edx
sete %al
movl %eax, 0x38(%r14)
movq 0x8(%rdi), %rax
movl 0x90(%rdi), %ecx
movl $0x1, %esi
callq *0x10(%rax)
movq %rax, 0x30(%r14)
cmpl $0x0, 0x90(%rbx)
jle 0x84ae2
movl 0x28(%r14), %ecx
xorl %edi, %edi
movslq 0x3c(%r14,%rdi,4), %r9
movl %ecx, %eax
cltd
idivl %r9d
movl %eax, %ecx
cmpl $0x1, %ebp
jne 0x84a2c
movq 0x30(%r14), %rax
addq $0xff, (%rax,%rdi,8)
movq 0x30(%r14), %rax
movq (%rax,%rdi,8), %r8
leaq 0xfe(%r9), %rax
leal -0x2(,%r9,2), %edx
movslq %edx, %r10
cqto
idivq %r10
addq $0x2fc, %r9             # imm = 0x2FC
xorl %r11d, %r11d
xorl %r15d, %r15d
movslq %eax, %rdx
cmpq %rdx, %r11
jle 0x84a8b
movslq %r15d, %rsi
leaq (%rsi,%rsi), %rax
shlq $0x9, %rsi
subq %rax, %rsi
addq %r9, %rsi
movq %rsi, %rax
cqto
idivq %r10
movslq %eax, %rdx
incl %r15d
addq $0x1fe, %rsi            # imm = 0x1FE
cmpq %rdx, %r11
jg 0x84a71
movl %r15d, %edx
imull %ecx, %edx
movb %dl, (%r8,%r11)
incq %r11
cmpq $0x100, %r11            # imm = 0x100
jne 0x84a58
cmpl $0x1, %ebp
jne 0x84acf
leaq -0x1(%r8), %rax
movl $0x100, %edx            # imm = 0x100
movb (%r8), %sil
movb %sil, (%rax)
movb 0xff(%r8), %sil
movb %sil, (%r8,%rdx)
decq %rax
incq %rdx
cmpq $0x1ff, %rdx            # imm = 0x1FF
jne 0x84aaf
incq %rdi
movslq 0x90(%rbx), %rax
cmpq %rax, %rdi
jl 0x84a0e
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq