// File: /workspace/github_cpp_makefile_star2_O2/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
movl (%rsi), %r9d
movl 0x4(%rsi), %r8d
movslq %r8d, %r15
movl 0x8(%rsi), %ebp
movslq %ebp, %r10
movl 0xc(%rsi), %edi
movslq %edi, %rbx
movl 0x10(%rsi), %ecx
movslq %ecx, %rdx
movq %rdx, -0x10(%rsp)
movl 0x14(%rsi), %edx
cmpl %r9d, %r15d
movq %rsi, -0x20(%rsp)
jle 0x78458
movl %r9d, -0x24(%rsp)
movslq %r9d, %r12
movq %r10, %r13
shlq $0x6, %r13
movl %r8d, -0x14(%rsp)
cmpq %r15, %r12
jg 0x7871b
movl %ebp, %r8d
movq %r13, %rbp
movq %r10, %r14
cmpq %rbx, %r14
jg 0x78438
movq (%rax,%r12,8), %r9
addq %rbp, %r9
movq -0x10(%rsp), %r11
cmpl %edx, %r11d
jg 0x7842f
cmpw $0x0, (%r9,%r11,2)
jne 0x78445
incq %r11
jmp 0x7841d
incq %r14
addq $0x40, %rbp
jmp 0x7840c
incq %r12
movl %r8d, %ebp
movl -0x14(%rsp), %r8d
jmp 0x783fa
movq -0x20(%rsp), %rsi
movl %r12d, (%rsi)
movl %r12d, %r9d
movl %r8d, %ebp
movl -0x14(%rsp), %r8d
cmpl %r9d, %r8d
movl %r9d, -0x24(%rsp)
jle 0x784c5
movl %ebp, -0x4(%rsp)
movslq %r9d, %r12
movq %r10, %r13
shlq $0x6, %r13
cmpq %r12, %r15
jl 0x7872a
movq %r13, %rbp
movq %r10, %r14
cmpq %rbx, %r14
jg 0x784ab
movq (%rax,%r15,8), %r9
addq %rbp, %r9
movq -0x10(%rsp), %r11
cmpl %edx, %r11d
jg 0x784a2
cmpw $0x0, (%r9,%r11,2)
jne 0x784b0
incq %r11
jmp 0x78490
incq %r14
addq $0x40, %rbp
jmp 0x7847f
decq %r15
jmp 0x78470
movq -0x20(%rsp), %rsi
movl %r15d, 0x4(%rsi)
movl %r15d, %r8d
movl -0x4(%rsp), %ebp
movl -0x24(%rsp), %r9d
cmpl %ebp, %edi
jle 0x78524
movslq %r9d, %r15
movslq %r8d, %r12
movq %r10, %r13
shlq $0x6, %r13
cmpq %rbx, %r10
jg 0x78738
movq %r15, %r14
cmpq %r12, %r14
jg 0x7850a
movq (%rax,%r14,8), %r9
addq %r13, %r9
movq -0x10(%rsp), %r11
cmpl %edx, %r11d
jg 0x78505
cmpw $0x0, (%r9,%r11,2)
jne 0x78513
incq %r11
jmp 0x784f3
incq %r14
jmp 0x784e2
incq %r10
addq $0x40, %r13
jmp 0x784d6
movq -0x20(%rsp), %rsi
movl %r10d, 0x8(%rsi)
movl %r10d, %ebp
movl -0x24(%rsp), %r9d
cmpl %ebp, %edi
jle 0x78584
movslq %r9d, %r14
movslq %r8d, %r15
movslq %ebp, %r12
movq %rbx, %r13
shlq $0x6, %r13
cmpq %r12, %rbx
jl 0x78742
movq %r14, %r10
cmpq %r15, %r10
jg 0x7856c
movq (%rax,%r10,8), %r9
addq %r13, %r9
movq -0x10(%rsp), %r11
cmpl %edx, %r11d
jg 0x78567
cmpw $0x0, (%r9,%r11,2)
jne 0x78575
incq %r11
jmp 0x78555
incq %r10
jmp 0x78544
decq %rbx
addq $-0x40, %r13
jmp 0x78538
movq -0x20(%rsp), %rsi
movl %ebx, 0xc(%rsi)
movl %ebx, %edi
movl -0x24(%rsp), %r9d
movslq %edx, %r12
cmpl %ecx, %edx
jle 0x78604
movslq %ebp, %rbx
movslq %r9d, %r14
movslq %r8d, %r15
shlq $0x6, %rbx
cmpq %r12, -0x10(%rsp)
jg 0x78604
movl %r8d, %r11d
movq %r14, %r13
cmpq %r15, %r13
jg 0x785d8
movq (%rax,%r13,8), %r9
addq %rbx, %r9
movq -0x10(%rsp), %rsi
leaq (%r9,%rsi,2), %r10
movl %ebp, %r8d
cmpl %edi, %ebp
jg 0x785d0
cmpw $0x0, (%r10)
jne 0x785ec
incl %ebp
addq $0x40, %r10
jmp 0x785bd
incq %r13
movl %r8d, %ebp
jmp 0x785a5
incq -0x10(%rsp)
movq -0x20(%rsp), %rsi
movl %r11d, %r8d
movl -0x24(%rsp), %r9d
jmp 0x78598
movq -0x20(%rsp), %rsi
movq -0x10(%rsp), %rcx
movl %ecx, 0x10(%rsi)
movl %r8d, %ebp
movl %r11d, %r8d
movl -0x24(%rsp), %r9d
cmpl %ecx, %edx
jle 0x78669
movslq %ebp, %rbx
movslq %r9d, %r11
movslq %r8d, %r14
movslq %ecx, %r15
movq %rbx, %r13
shlq $0x6, %r13
movl %r8d, -0x14(%rsp)
cmpq %r15, %r12
jl 0x7874c
movl %ebp, %r8d
movq %r11, %rbp
cmpq %r14, %rbp
jg 0x7865c
movq (%rax,%rbp,8), %r9
addq %r13, %r9
leaq (%r9,%r12,2), %r10
movl %r8d, %r9d
cmpl %edi, %r9d
jg 0x78657
cmpw $0x0, (%r10)
jne 0x78677
incl %r9d
addq $0x40, %r10
jmp 0x78642
incq %rbp
jmp 0x7862f
decq %r12
movl %r8d, %ebp
movl -0x14(%rsp), %r8d
jmp 0x78620
movslq %r9d, %r11
movslq %r8d, %r14
movslq %ebp, %rbx
movslq %ecx, %r15
jmp 0x78690
movq -0x20(%rsp), %rsi
movl %r12d, 0x14(%rsi)
movl %r12d, %edx
movl %r8d, %ebp
movl -0x14(%rsp), %r8d
movl -0x24(%rsp), %r9d
subl %r9d, %r8d
shll $0x4, %r8d
movslq %r8d, %r8
movl %edi, %r9d
subl %ebp, %r9d
imull $0xc, %r9d, %r9d
movslq %r9d, %r9
movl %edx, %r10d
subl %ecx, %r10d
shll $0x3, %r10d
movslq %r10d, %r10
imulq %r8, %r8
imulq %r9, %r9
imulq %r10, %r10
addq %r8, %r10
addq %r9, %r10
movq %r10, 0x18(%rsi)
movslq %edi, %r8
xorl %edi, %edi
cmpq %r14, %r11
jg 0x7870c
movq %rbx, %r9
cmpq %r8, %r9
jg 0x78707
movq %r9, %r10
shlq $0x6, %r10
addq (%rax,%r11,8), %r10
leaq (%r10,%r15,2), %r10
movl %ecx, %ebp
cmpl %edx, %ebp
jg 0x78702
cmpw $0x1, (%r10)
sbbq $-0x1, %rdi
incl %ebp
addq $0x2, %r10
jmp 0x786ed
incq %r9
jmp 0x786d7
incq %r11
jmp 0x786cf
movq %rdi, 0x20(%rsi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x20(%rsp), %rsi
movl -0x24(%rsp), %r9d
jmp 0x78458
movl -0x4(%rsp), %ebp
movq -0x20(%rsp), %rsi
jmp 0x784c0
movq -0x20(%rsp), %rsi
jmp 0x7851f
movq -0x20(%rsp), %rsi
jmp 0x7857f
movq -0x20(%rsp), %rsi
jmp 0x7868b