// File: /workspace/github_cpp_makefile_star2_O2/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 $0x958, %rsp            # imm = 0x958
movq 0x270(%rdi), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rsp)
movq %rsi, -0x50(%rsp)
leal (,%rsi,8), %eax
movslq %eax, %rbx
movq %rbx, %r8
andq $-0x20, %r8
orq $0x4, %r8
movq %rdx, -0x58(%rsp)
leal (,%rdx,4), %eax
movslq %eax, %r14
movq %r14, %r9
andq $-0x20, %r9
orq $0x2, %r9
movq %rcx, -0x48(%rsp)
leal (,%rcx,8), %eax
movslq %eax, %r15
movq %r15, %r10
andq $-0x20, %r10
orq $0x4, %r10
movq %rdi, -0x60(%rsp)
movl 0x9c(%rdi), %r11d
orq $0x1c, %rbx
leal (%r8,%rbx), %eax
shrl %eax
movl %eax, -0x70(%rsp)
orq $0x1e, %r14
leal (%r9,%r14), %eax
shrl %eax
movl %eax, -0x78(%rsp)
orq $0x1c, %r15
leal (%r10,%r15), %eax
shrl %eax
movl %eax, -0x80(%rsp)
xorl %ecx, %ecx
testl %r11d, %r11d
cmovlel %ecx, %r11d
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq %rbx, -0x68(%rsp)
cmpq %rcx, %r11
je 0x78934
movq -0x60(%rsp), %rax
movq 0xa0(%rax), %rbp
movq (%rbp), %rax
movzbl (%rax,%rcx), %edx
cmpl %r8d, %edx
jge 0x78843
movq %rdx, %rsi
subq %r8, %rsi
addq %rsi, %rsi
imulq %rsi, %rsi
movl %ebx, %r13d
jmp 0x78867
cmpl %ebx, %edx
jle 0x78859
movq %rdx, %rsi
subq %rbx, %rsi
addq %rsi, %rsi
imulq %rsi, %rsi
movl %r8d, %r13d
jmp 0x78867
movl %r8d, %r13d
cmpl %edx, -0x70(%rsp)
jb 0x78865
movl %ebx, %r13d
xorl %esi, %esi
movq 0x8(%rbp), %rax
movzbl (%rax,%rcx), %eax
cmpl %r9d, %eax
jge 0x7888a
movq %rax, %rdi
subq %r9, %rdi
leaq (%rdi,%rdi,2), %rdi
imulq %rdi, %rdi
addq %rdi, %rsi
movl %r14d, %ebx
jmp 0x788ae
cmpl %r14d, %eax
jle 0x788a5
movq %rax, %rdi
subq %r14, %rdi
leaq (%rdi,%rdi,2), %rdi
imulq %rdi, %rdi
addq %rdi, %rsi
movl %r9d, %ebx
jmp 0x788ae
movl %r9d, %ebx
cmpl %eax, -0x78(%rsp)
jae 0x78885
movq 0x10(%rbp), %rdi
movzbl (%rdi,%rcx), %edi
cmpl %r10d, %edi
jge 0x788cd
movq %rdi, %rbp
subq %r10, %rbp
imulq %rbp, %rbp
addq %rbp, %rsi
movl %r15d, %ebp
jmp 0x788ed
cmpl %r15d, %edi
jle 0x788e4
movq %rdi, %rbp
subq %r15, %rbp
imulq %rbp, %rbp
addq %rbp, %rsi
movl %r10d, %ebp
jmp 0x788ed
movl %r10d, %ebp
cmpl %edi, -0x80(%rsp)
jae 0x788c8
movslq %r13d, %r13
subq %r13, %rdx
addq %rdx, %rdx
imulq %rdx, %rdx
movslq %ebx, %rbx
subq %rbx, %rax
leaq (%rax,%rax,2), %rax
imulq %rax, %rax
addq %rdx, %rax
movslq %ebp, %rdx
subq %rdx, %rdi
imulq %rdi, %rdi
addq %rax, %rdi
movq %rsi, 0x150(%rsp,%rcx,8)
cmpq %r12, %rdi
cmovlq %rdi, %r12
incq %rcx
movq -0x68(%rsp), %rbx
jmp 0x7880f
xorl %eax, %eax
xorl %esi, %esi
cmpq %rax, %r11
je 0x78955
cmpq %r12, 0x150(%rsp,%rax,8)
jg 0x78950
movslq %esi, %rcx
incl %esi
movb %al, 0x50(%rsp,%rcx)
incq %rax
jmp 0x78938
leaq 0x150(%rsp), %rax
movl $0x7f, %ecx
testl %ecx, %ecx
js 0x78975
movq $0x7fffffff, (%rax)     # imm = 0x7FFFFFFF
addq $0x8, %rax
decl %ecx
jmp 0x78962
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movslq %r8d, %rcx
movq %rcx, -0x78(%rsp)
movslq %r9d, %rcx
movq %rcx, -0x80(%rsp)
movslq %r10d, %rcx
movq %rcx, -0x40(%rsp)
movl $0x3, %edx
movq %rsi, -0x70(%rsp)
cmpq %rsi, %rax
je 0x78aa2
movq %rax, -0x68(%rsp)
movzbl 0x50(%rsp,%rax), %esi
movq -0x60(%rsp), %rax
movq 0xa0(%rax), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdi
movzbl (%rcx,%rsi), %ecx
movq -0x78(%rsp), %r15
subq %rcx, %r15
leaq (%r15,%r15), %rcx
imulq %rcx, %rcx
movzbl (%rdi,%rsi), %edi
movq -0x80(%rsp), %r8
subq %rdi, %r8
leaq (%r8,%r8,2), %r9
imulq %r9, %r9
addq %rcx, %r9
movq 0x10(%rax), %rax
movzbl (%rax,%rsi), %eax
movq -0x40(%rsp), %rcx
subq %rax, %rcx
movq %rcx, %rdi
imulq %rcx, %rdi
addq %r9, %rdi
shlq $0x6, %r15
addq $0x100, %r15            # imm = 0x100
imulq $0x48, %r8, %r9
addq $0x90, %r9
shlq $0x4, %rcx
addq $0x40, %rcx
leaq 0x150(%rsp), %r14
leaq -0x30(%rsp), %r11
movl %edx, %ebx
testl %ebx, %ebx
js 0x78a90
movl $0x7, %ebp
movq %rdi, %r8
movq %r9, %rax
testl %ebp, %ebp
js 0x78a82
movl %edx, %r10d
movq %r8, %r13
movq %rcx, %r12
testl %r10d, %r10d
js 0x78a75
cmpq (%r14), %r13
jge 0x78a62
movq %r13, (%r14)
movb %sil, (%r11)
addq %r12, %r13
subq $-0x80, %r12
addq $0x8, %r14
incq %r11
decl %r10d
jmp 0x78a52
addq %rax, %r8
addq $0x120, %rax            # imm = 0x120
decl %ebp
jmp 0x78a45
addq %r15, %rdi
addq $0x200, %r15            # imm = 0x200
decl %ebx
jmp 0x78a36
movq -0x68(%rsp), %rax
incq %rax
movq -0x70(%rsp), %rsi
jmp 0x7899e
movq -0x50(%rsp), %rax
andl $-0x4, %eax
movq -0x58(%rsp), %rcx
andl $-0x8, %ecx
movslq %ecx, %rcx
cltq
shlq $0x6, %rcx
movq -0x48(%rsp), %rdx
shrl $0x2, %edx
leaq (%rcx,%rdx,8), %rcx
leaq -0x30(%rsp), %rdx
xorl %esi, %esi
cmpq $0x4, %rsi
je 0x78b1b
movq %rsi, %rdi
orq %rax, %rdi
movq -0x38(%rsp), %r8
movq (%r8,%rdi,8), %rdi
addq %rcx, %rdi
xorl %r8d, %r8d
cmpq $0x8, %r8
je 0x78b16
xorl %r9d, %r9d
cmpl $0x4, %r9d
je 0x78b0a
movzbl (%rdx,%r9), %r10d
incl %r10d
movw %r10w, (%rdi,%r9,2)
incq %r9
jmp 0x78af2
incq %r8
addq %r9, %rdx
addq $0x40, %rdi
jmp 0x78ae9
incq %rsi
jmp 0x78ace
addq $0x958, %rsp            # imm = 0x958
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)