// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jquant2.c
// Function: update_box
LOCAL(void)
update_box (j_decompress_ptr cinfo, boxptr boxp)
/* Shrink the min/max bounds of a box to enclose only nonzero elements, */
/* and recompute its volume and population */
{
  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  hist3d histogram = cquantize->histogram;
  histptr histp;
  int c0,c1,c2;
  int c0min,c0max,c1min,c1max,c2min,c2max;
  INT32 dist0,dist1,dist2;
  long ccount;
  
  c0min = boxp->c0min;  c0max = boxp->c0max;
  c1min = boxp->c1min;  c1max = boxp->c1max;
  c2min = boxp->c2min;  c2max = boxp->c2max;
  
  if (c0max > c0min)
    for (c0 = c0min; c0 <= c0max; c0++)
      for (c1 = c1min; c1 <= c1max; c1++) {
	histp = & histogram[c0][c1][c2min];
	for (c2 = c2min; c2 <= c2max; c2++)
	  if (*histp++ != 0) {
	    boxp->c0min = c0min = c0;
	    goto have_c0min;
	  }
      }
 have_c0min:
  if (c0max > c0min)
    for (c0 = c0max; c0 >= c0min; c0--)
      for (c1 = c1min; c1 <= c1max; c1++) {
	histp = & histogram[c0][c1][c2min];
	for (c2 = c2min; c2 <= c2max; c2++)
	  if (*histp++ != 0) {
	    boxp->c0max = c0max = c0;
	    goto have_c0max;
	  }
      }
 have_c0max:
  if (c1max > c1min)
    for (c1 = c1min; c1 <= c1max; c1++)
      for (c0 = c0min; c0 <= c0max; c0++) {
	histp = & histogram[c0][c1][c2min];
	for (c2 = c2min; c2 <= c2max; c2++)
	  if (*histp++ != 0) {
	    boxp->c1min = c1min = c1;
	    goto have_c1min;
	  }
      }
 have_c1min:
  if (c1max > c1min)
    for (c1 = c1max; c1 >= c1min; c1--)
      for (c0 = c0min; c0 <= c0max; c0++) {
	histp = & histogram[c0][c1][c2min];
	for (c2 = c2min; c2 <= c2max; c2++)
	  if (*histp++ != 0) {
	    boxp->c1max = c1max = c1;
	    goto have_c1max;
	  }
      }
 have_c1max:
  if (c2max > c2min)
    for (c2 = c2min; c2 <= c2max; c2++)
      for (c0 = c0min; c0 <= c0max; c0++) {
	histp = & histogram[c0][c1min][c2];
	for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
	  if (*histp != 0) {
	    boxp->c2min = c2min = c2;
	    goto have_c2min;
	  }
      }
 have_c2min:
  if (c2max > c2min)
    for (c2 = c2max; c2 >= c2min; c2--)
      for (c0 = c0min; c0 <= c0max; c0++) {
	histp = & histogram[c0][c1min][c2];
	for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
	  if (*histp != 0) {
	    boxp->c2max = c2max = c2;
	    goto have_c2max;
	  }
      }
 have_c2max:

  /* Update box volume.
   * We use 2-norm rather than real volume here; this biases the method
   * against making long narrow boxes, and it has the side benefit that
   * a box is splittable iff norm > 0.
   * Since the differences are expressed in histogram-cell units,
   * we have to shift back to JSAMPLE units to get consistent distances;
   * after which, we scale according to the selected distance scale factors.
   */
  dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  
  /* Now scan remaining volume of box and compute population */
  ccount = 0;
  for (c0 = c0min; c0 <= c0max; c0++)
    for (c1 = c1min; c1 <= c1max; c1++) {
      histp = & histogram[c0][c1][c2min];
      for (c2 = c2min; c2 <= c2max; c2++, histp++)
	if (*histp != 0) {
	  ccount++;
	}
    }
  boxp->colorcount = ccount;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x270(%rdi), %rax
movq 0x30(%rax), %rax
movq %rax, -0x8(%rsp)
movl (%rsi), %r10d
movl 0x4(%rsi), %ecx
movl 0x8(%rsi), %edx
movslq %edx, %rax
movl 0xc(%rsi), %edi
movl 0x10(%rsi), %r8d
movslq %r8d, %r11
movl 0x14(%rsi), %r9d
cmpl %r10d, %ecx
movq %rsi, -0x20(%rsp)
jle 0x85cd0
movslq %r10d, %r14
leal 0x1(%rdi), %ebp
leal 0x1(%rcx), %esi
movl %esi, -0x18(%rsp)
movq %rax, %rbx
shlq $0x6, %rbx
leaq (%rbx,%r11,2), %rsi
movq %rsi, -0x10(%rsp)
movl %r9d, %r13d
subl %r11d, %r13d
incl %r13d
movq -0x8(%rsp), %rsi
cmpl %edi, %edx
jle 0x85c94
incq %r14
cmpl %r14d, -0x18(%rsp)
jne 0x85c81
jmp 0x86008
movq (%rsi,%r14,8), %r12
addq -0x10(%rsp), %r12
movq %rax, %rbx
cmpl %r9d, %r8d
jg 0x85cb8
xorl %r15d, %r15d
cmpw $0x0, (%r12,%r15,2)
jne 0x85cc5
incq %r15
cmpl %r15d, %r13d
jne 0x85ca8
incq %rbx
addq $0x40, %r12
cmpl %ebx, %ebp
jne 0x85ca0
jmp 0x85c85
movq -0x20(%rsp), %rsi
movl %r14d, (%rsi)
movl %r14d, %r10d
cmpl %r10d, %ecx
jle 0x85d59
movslq %ecx, %r14
leal 0x1(%rdi), %ebp
movslq %r10d, %rsi
movq %rsi, -0x18(%rsp)
movq %rax, %rbx
shlq $0x6, %rbx
leaq (%rbx,%r11,2), %rsi
movq %rsi, -0x10(%rsp)
movl %r9d, %r13d
subl %r8d, %r13d
incl %r13d
movq -0x8(%rsp), %rsi
cmpl %edi, %edx
jle 0x85d1c
leaq -0x1(%r14), %rbx
cmpq -0x18(%rsp), %r14
movq %rbx, %r14
jg 0x85d05
jmp 0x86012
movq (%rsi,%r14,8), %r12
addq -0x10(%rsp), %r12
movq %rax, %r15
cmpl %r9d, %r8d
jg 0x85d3f
xorl %ebx, %ebx
cmpw $0x0, (%r12,%rbx,2)
jne 0x85d4d
incq %rbx
cmpl %ebx, %r13d
jne 0x85d2f
incq %r15
addq $0x40, %r12
cmpl %r15d, %ebp
jne 0x85d28
jmp 0x85d09
movq -0x20(%rsp), %rsi
movl %r14d, 0x4(%rsi)
movl %r14d, %ecx
cmpl %edx, %edi
jle 0x85dd6
movslq %r10d, %rsi
movq %rsi, -0x10(%rsp)
leal 0x1(%rcx), %ebp
leal 0x1(%rdi), %esi
movl %esi, -0x18(%rsp)
movq %rax, %rbx
shlq $0x6, %rbx
leaq (%rbx,%r11,2), %r12
movl %r9d, %r13d
subl %r8d, %r13d
incl %r13d
movq -0x8(%rsp), %rsi
cmpl %r10d, %ecx
jge 0x85d9f
incq %rax
addq $0x40, %r12
cmpl %eax, -0x18(%rsp)
jne 0x85d88
jmp 0x8601c
movq -0x10(%rsp), %r15
cmpl %r9d, %r8d
jg 0x85dc2
movq (%rsi,%r15,8), %r14
addq %r12, %r14
xorl %ebx, %ebx
cmpw $0x0, (%r14,%rbx,2)
jne 0x85dcc
incq %rbx
cmpl %ebx, %r13d
jne 0x85db2
incq %r15
cmpl %r15d, %ebp
jne 0x85da4
jmp 0x85d8d
movq -0x20(%rsp), %rsi
movl %eax, 0x8(%rsi)
movl %eax, %edx
cmpl %edx, %edi
jle 0x85e60
movslq %edi, %rbx
movslq %r10d, %rax
movq %rax, -0x10(%rsp)
leal 0x1(%rcx), %ebp
movslq %edx, %rax
movq %rax, -0x18(%rsp)
movq %rbx, %rax
shlq $0x6, %rax
leaq (%rax,%r11,2), %r12
movl %r9d, %r13d
subl %r8d, %r13d
incl %r13d
movq -0x8(%rsp), %rsi
cmpl %r10d, %ecx
jge 0x85e29
leaq -0x1(%rbx), %rax
addq $-0x40, %r12
cmpq -0x18(%rsp), %rbx
movq %rax, %rbx
jg 0x85e0d
jmp 0x86026
movq -0x10(%rsp), %rax
cmpl %r9d, %r8d
jg 0x85e4d
movq (%rsi,%rax,8), %r14
addq %r12, %r14
xorl %r15d, %r15d
cmpw $0x0, (%r14,%r15,2)
jne 0x85e56
incq %r15
cmpl %r15d, %r13d
jne 0x85e3d
incq %rax
cmpl %eax, %ebp
jne 0x85e2e
jmp 0x85e12
movq -0x20(%rsp), %rsi
movl %ebx, 0xc(%rsi)
movl %ebx, %edi
cmpl %r8d, %r9d
jle 0x85ed7
movslq %edx, %rbx
movslq %r10d, %rax
movq %rax, -0x18(%rsp)
leal 0x1(%rcx), %ebp
leal 0x1(%r9), %r15d
movl %edi, %r14d
subl %edx, %r14d
incl %r14d
shlq $0x6, %rbx
movq -0x8(%rsp), %rsi
cmpl %r10d, %ecx
jge 0x85e9b
incq %r11
cmpl %r11d, %r15d
jne 0x85e89
jmp 0x86030
movq -0x18(%rsp), %r13
cmpl %edx, %edi
jl 0x85ec1
movq (%rsi,%r13,8), %rax
addq %rbx, %rax
leaq (%rax,%r11,2), %rax
movl %r14d, %r12d
cmpw $0x0, (%rax)
jne 0x85ecb
addq $0x40, %rax
decl %r12d
jne 0x85eb2
incq %r13
cmpl %r13d, %ebp
jne 0x85ea0
jmp 0x85e8e
movq -0x20(%rsp), %rsi
movl %r11d, 0x10(%rsi)
movl %r11d, %r8d
movslq %r8d, %r11
cmpl %r8d, %r9d
jle 0x85f53
movslq %r9d, %rbx
movslq %edx, %r14
movslq %r10d, %rax
movq %rax, -0x18(%rsp)
leal 0x1(%rcx), %ebp
movl %edi, %r15d
subl %edx, %r15d
incl %r15d
shlq $0x6, %r14
movq -0x8(%rsp), %rsi
cmpl %r10d, %ecx
jge 0x85f18
leaq -0x1(%rbx), %rax
cmpq %r11, %rbx
movq %rax, %rbx
jg 0x85f02
jmp 0x8603a
movq -0x18(%rsp), %r13
cmpl %edx, %edi
jl 0x85f3e
movq (%rsi,%r13,8), %rax
addq %r14, %rax
leaq (%rax,%rbx,2), %rax
movl %r15d, %r12d
cmpw $0x0, (%rax)
jne 0x85f48
addq $0x40, %rax
decl %r12d
jne 0x85f2f
incq %r13
cmpl %r13d, %ebp
jne 0x85f1d
jmp 0x85f07
movq -0x20(%rsp), %rsi
movl %ebx, 0x14(%rsi)
movl %ebx, %r9d
movl %ecx, %eax
subl %r10d, %eax
shll $0x4, %eax
cltq
movl %edi, %ebx
subl %edx, %ebx
shll $0x2, %ebx
leal (%rbx,%rbx,2), %ebx
movslq %ebx, %r14
movl %r9d, %ebx
subl %r8d, %ebx
leal (,%rbx,8), %ebp
movslq %ebp, %r15
imulq %rax, %rax
imulq %r14, %r14
imulq %r15, %r15
addq %rax, %r15
addq %r14, %r15
movq %r15, 0x18(%rsi)
cmpl %r10d, %ecx
jge 0x85f9a
xorl %r11d, %r11d
jmp 0x85ff4
movslq %r10d, %r10
movslq %edx, %r14
leal 0x1(%rdi), %ebp
incl %ecx
movq %r14, %rax
shlq $0x6, %rax
leaq (%rax,%r11,2), %r15
incl %ebx
xorl %r11d, %r11d
movq -0x8(%rsp), %rsi
cmpl %edx, %edi
jl 0x85fec
movq (%rsi,%r10,8), %r12
addq %r15, %r12
movq %r14, %r13
cmpl %r8d, %r9d
jl 0x85fe0
xorl %eax, %eax
cmpw $0x1, (%r12,%rax,2)
sbbq $-0x1, %r11
incq %rax
cmpl %eax, %ebx
jne 0x85fcf
incq %r13
addq $0x40, %r12
cmpl %r13d, %ebp
jne 0x85fc8
incq %r10
cmpl %r10d, %ecx
jne 0x85fba
movq -0x20(%rsp), %rax
movq %r11, 0x20(%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x20(%rsp), %rsi
jmp 0x85cd0
movq -0x20(%rsp), %rsi
jmp 0x85d59
movq -0x20(%rsp), %rsi
jmp 0x85dd6
movq -0x20(%rsp), %rsi
jmp 0x85e60
movq -0x20(%rsp), %rsi
jmp 0x85ed7
movq -0x20(%rsp), %rsi
jmp 0x85f53