// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/jpeg/jquant2.c
// Function: fill_inverse_cmap
LOCAL(void)
fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
/* Fill the inverse-colormap entries in the update box that contains */
/* histogram cell c0/c1/c2.  (Only that one cell MUST be filled, but */
/* we can fill as many others as we wish.) */
{
  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  hist3d histogram = cquantize->histogram;
  int minc0, minc1, minc2;	/* lower left corner of update box */
  int ic0, ic1, ic2;
  register JSAMPLE * cptr;	/* pointer into bestcolor[] array */
  register histptr cachep;	/* pointer into main cache array */
  /* This array lists the candidate colormap indexes. */
  JSAMPLE colorlist[MAXNUMCOLORS];
  int numcolors;		/* number of candidate colors */
  /* This array holds the actually closest colormap index for each cell. */
  JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];

  /* Convert cell coordinates to update box ID */
  c0 >>= BOX_C0_LOG;
  c1 >>= BOX_C1_LOG;
  c2 >>= BOX_C2_LOG;

  /* Compute true coordinates of update box's origin corner.
   * Actually we compute the coordinates of the center of the corner
   * histogram cell, which are the lower bounds of the volume we care about.
   */
  minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  
  /* Determine which colormap entries are close enough to be candidates
   * for the nearest entry to some cell in the update box.
   */
  numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);

  /* Determine the actually nearest colors. */
  find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
		   bestcolor);

  /* Save the best color numbers (plus 1) in the main cache array */
  c0 <<= BOX_C0_LOG;		/* convert ID back to base cell indexes */
  c1 <<= BOX_C1_LOG;
  c2 <<= BOX_C2_LOG;
  cptr = bestcolor;
  for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
    for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
      cachep = & histogram[c0+ic0][c1+ic1][c2];
      for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
	*cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x968, %rsp            # imm = 0x968
movq 0x270(%rdi), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rsp)
movq %rsi, -0x40(%rsp)
leal (,%rsi,8), %eax
movslq %eax, %r14
movq %r14, %r8
andq $-0x20, %r8
orq $0x4, %r8
movq %rdx, -0x48(%rsp)
leal (,%rdx,4), %eax
movslq %eax, %r15
movq %r15, %r9
andq $-0x20, %r9
orq $0x2, %r9
movq %rcx, -0x38(%rsp)
leal (,%rcx,8), %eax
movslq %eax, %r12
movq %r12, %rsi
andq $-0x20, %rsi
leaq 0x4(%rsi), %r10
movslq 0x9c(%rdi), %rbx
testq %rbx, %rbx
movq %rdi, -0x28(%rsp)
jle 0x8546e
movq %rsi, -0x50(%rsp)
orq $0x1c, %r14
leal (%r8,%r14), %eax
shrl %eax
movl %eax, -0x80(%rsp)
orq $0x1e, %r15
leal (%r9,%r15), %eax
shrl %eax
movl %eax, -0x54(%rsp)
orq $0x1c, %r12
leal (%r10,%r12), %eax
shrl %eax
movl %eax, -0x58(%rsp)
movq 0xa0(%rdi), %rax
movq (%rax), %rcx
movq %rcx, -0x68(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, -0x70(%rsp)
movq 0x10(%rax), %rax
movq %rax, -0x78(%rsp)
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movq %r14, -0x60(%rsp)
movq %r13, %rdi
movq -0x68(%rsp), %rax
movzbl (%rax,%rbp), %r11d
cmpl %r8d, %r11d
jge 0x8534d
movq %r11, %rax
subq %r8, %rax
addq %rax, %rax
imulq %rax, %rax
movl %r14d, %ecx
jmp 0x85373
cmpl %r14d, %r11d
jle 0x85364
movq %r11, %rax
subq %r14, %rax
addq %rax, %rax
imulq %rax, %rax
movl %r8d, %ecx
jmp 0x85373
movl %r8d, %ecx
cmpl %r11d, -0x80(%rsp)
jb 0x85371
movl %r14d, %ecx
xorl %eax, %eax
movq -0x70(%rsp), %rdx
movzbl (%rdx,%rbp), %edx
cmpl %r9d, %edx
jge 0x85397
movq %rdx, %rsi
subq %r9, %rsi
leaq (%rsi,%rsi,2), %rsi
imulq %rsi, %rsi
addq %rsi, %rax
movl %r15d, %esi
jmp 0x853bb
cmpl %r15d, %edx
jle 0x853b2
movq %rdx, %rsi
subq %r15, %rsi
leaq (%rsi,%rsi,2), %rsi
imulq %rsi, %rsi
addq %rsi, %rax
movl %r9d, %esi
jmp 0x853bb
movl %r9d, %esi
cmpl %edx, -0x54(%rsp)
jae 0x85392
movq -0x78(%rsp), %r14
movzbl (%r14,%rbp), %r13d
cmpl %r10d, %r13d
jge 0x853dc
movq %r13, %r14
subq %r10, %r14
imulq %r14, %r14
addq %r14, %rax
movl %r12d, %r14d
jmp 0x853fd
cmpl %r12d, %r13d
jle 0x853f3
movq %r13, %r14
subq %r12, %r14
imulq %r14, %r14
addq %r14, %rax
movl %r10d, %r14d
jmp 0x853fd
movl %r10d, %r14d
cmpl %r13d, -0x58(%rsp)
jae 0x853d7
movslq %ecx, %rcx
subq %rcx, %r11
addq %r11, %r11
imulq %r11, %r11
movslq %esi, %rcx
subq %rcx, %rdx
leaq (%rdx,%rdx,2), %rcx
imulq %rcx, %rcx
addq %r11, %rcx
movslq %r14d, %rdx
subq %rdx, %r13
imulq %r13, %r13
addq %rcx, %r13
movq %rax, 0x160(%rsp,%rbp,8)
cmpq %rdi, %r13
cmovgeq %rdi, %r13
incq %rbp
cmpq %rbp, %rbx
movq -0x60(%rsp), %r14
jne 0x85329
xorl %ecx, %ecx
xorl %eax, %eax
movq -0x50(%rsp), %rsi
cmpq %r13, 0x160(%rsp,%rcx,8)
jg 0x85464
movslq %eax, %rdx
incl %eax
movb %cl, 0x60(%rsp,%rdx)
incq %rcx
cmpq %rcx, %rbx
jne 0x85451
jmp 0x85470
xorl %eax, %eax
xorl %ecx, %ecx
movaps 0x25837(%rip), %xmm0    # 0xaacb0
movaps %xmm0, 0x160(%rsp,%rcx,8)
addq $0x2, %rcx
cmpq $0x80, %rcx
jne 0x85479
testl %eax, %eax
jle 0x855b9
movl %eax, %eax
movq %rax, -0x60(%rsp)
movslq %esi, %rax
shlq $0x4, %rax
subq $-0x80, %rax
movq %rax, -0x68(%rsp)
xorl %esi, %esi
movslq %r8d, %rax
movq %rax, -0x70(%rsp)
movslq %r9d, %rax
movq %rax, -0x78(%rsp)
movslq %r10d, %rax
movq %rax, -0x80(%rsp)
movzbl 0x60(%rsp,%rsi), %eax
movq -0x28(%rsp), %rcx
movq 0xa0(%rcx), %rcx
movq (%rcx), %rdi
movq 0x8(%rcx), %r8
movzbl (%rdi,%rax), %edi
movq -0x70(%rsp), %r14
subq %rdi, %r14
leaq (%r14,%r14), %rdi
imulq %rdi, %rdi
movzbl (%r8,%rax), %r8d
movq -0x78(%rsp), %r9
subq %r8, %r9
leaq (%r9,%r9,2), %r10
imulq %r10, %r10
addq %rdi, %r10
movq 0x10(%rcx), %rcx
movzbl (%rcx,%rax), %edi
movq -0x80(%rsp), %r8
subq %rdi, %r8
imulq %r8, %r8
addq %r10, %r8
shlq $0x6, %r14
addq $0x100, %r14            # imm = 0x100
leaq (%r9,%r9,8), %rcx
leaq 0x90(,%rcx,8), %rcx
shll $0x4, %edi
movq -0x68(%rsp), %r12
subq %rdi, %r12
movl $0x3, %ebp
leaq -0x20(%rsp), %r13
leaq 0x160(%rsp), %r11
movl $0x7, %ebx
movq %rcx, %r15
movq %r8, %r10
xorl %r9d, %r9d
movq %r10, %rdi
cmpq (%r11), %rdi
jge 0x85573
movq %rdi, (%r11)
movb %al, (%r13)
addq %r12, %rdi
addq %r9, %rdi
addq $0x8, %r11
incq %r13
subq $-0x80, %r9
cmpl $0x200, %r9d            # imm = 0x200
jne 0x85567
addq %r15, %r10
addq $0x120, %r15            # imm = 0x120
subl $0x1, %ebx
jae 0x85561
addq %r14, %r8
addq $0x200, %r14            # imm = 0x200
subl $0x1, %ebp
jae 0x85556
incq %rsi
cmpq -0x60(%rsp), %rsi
jne 0x854c7
movq -0x40(%rsp), %rax
andl $-0x4, %eax
movq -0x48(%rsp), %rcx
andl $-0x8, %ecx
movslq %ecx, %rcx
cltq
shlq $0x6, %rcx
movq -0x38(%rsp), %rdx
shrl $0x2, %edx
leaq (%rcx,%rdx,8), %rcx
leaq -0x20(%rsp), %r10
xorl %edx, %edx
movq -0x30(%rsp), %r11
movq %rdx, %rsi
orq %rax, %rsi
movq (%r11,%rsi,8), %rsi
addq %rcx, %rsi
xorl %r8d, %r8d
movq %r10, %rdi
xorl %r9d, %r9d
movzbl (%rdi,%r9), %r10d
incl %r10d
movw %r10w, (%rsi,%r9,2)
incq %r9
cmpq $0x4, %r9
jne 0x85600
incq %r8
addq $0x40, %rsi
leaq (%rdi,%r9), %r10
cmpq $0x8, %r8
jne 0x855fa
incq %rdx
addq %r9, %rdi
movq %rdi, %r10
cmpq $0x4, %rdx
jne 0x855ea
addq $0x968, %rsp            # imm = 0x968
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq