// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, -0x8(%rsp)
movl (%rsi), %r10d
movl 0x4(%rsi), %edi
movl 0x8(%rsi), %ecx
movslq %ecx, %rbp
movl 0xc(%rsi), %edx
movl 0x10(%rsi), %r8d
movslq %r8d, %r11
movl 0x14(%rsi), %r9d
cmpl %r10d, %edi
movq %rsi, -0x20(%rsp)
jle 0x84ebc
movslq %r10d, %r14
leal 0x1(%rdx), %r15d
leal 0x1(%rdi), %eax
movl %eax, -0x18(%rsp)
movq %rbp, %rax
shlq $0x6, %rax
leaq (%rax,%r11,2), %rax
movq %rax, -0x10(%rsp)
movl %r9d, %r13d
subl %r11d, %r13d
incl %r13d
movq -0x8(%rsp), %rsi
cmpl %edx, %ecx
jle 0x84e80
incq %r14
cmpl %r14d, -0x18(%rsp)
jne 0x84e6d
jmp 0x8520c
movq (%rsi,%r14,8), %r12
addq -0x10(%rsp), %r12
movq %rbp, %rbx
cmpl %r9d, %r8d
jg 0x84ea3
xorl %eax, %eax
cmpw $0x0, (%r12,%rax,2)
jne 0x84eb1
incq %rax
cmpl %eax, %r13d
jne 0x84e93
incq %rbx
addq $0x40, %r12
cmpl %ebx, %r15d
jne 0x84e8c
jmp 0x84e71
movq -0x20(%rsp), %rsi
movl %r14d, (%rsi)
movl %r14d, %r10d
cmpl %r10d, %edi
jle 0x84f45
movslq %edi, %r14
leal 0x1(%rdx), %ebx
movslq %r10d, %rax
movq %rax, -0x18(%rsp)
movq %rbp, %rax
shlq $0x6, %rax
leaq (%rax,%r11,2), %rax
movq %rax, -0x10(%rsp)
movl %r9d, %r13d
subl %r8d, %r13d
incl %r13d
movq -0x8(%rsp), %rsi
cmpl %edx, %ecx
jle 0x84f08
leaq -0x1(%r14), %rax
cmpq -0x18(%rsp), %r14
movq %rax, %r14
jg 0x84ef1
jmp 0x85216
movq (%rsi,%r14,8), %r12
addq -0x10(%rsp), %r12
movq %rbp, %r15
cmpl %r9d, %r8d
jg 0x84f2b
xorl %eax, %eax
cmpw $0x0, (%r12,%rax,2)
jne 0x84f39
incq %rax
cmpl %eax, %r13d
jne 0x84f1b
incq %r15
addq $0x40, %r12
cmpl %r15d, %ebx
jne 0x84f14
jmp 0x84ef5
movq -0x20(%rsp), %rsi
movl %r14d, 0x4(%rsi)
movl %r14d, %edi
cmpl %ecx, %edx
jle 0x84fc2
movslq %r10d, %rax
movq %rax, -0x10(%rsp)
leal 0x1(%rdi), %r15d
leal 0x1(%rdx), %eax
movl %eax, -0x18(%rsp)
movq %rbp, %rax
shlq $0x6, %rax
leaq (%rax,%r11,2), %r12
movl %r9d, %r13d
subl %r8d, %r13d
incl %r13d
movq -0x8(%rsp), %rsi
cmpl %r10d, %edi
jge 0x84f8c
incq %rbp
addq $0x40, %r12
cmpl %ebp, -0x18(%rsp)
jne 0x84f75
jmp 0x85220
movq -0x10(%rsp), %r14
cmpl %r9d, %r8d
jg 0x84fae
movq (%rsi,%r14,8), %rbx
addq %r12, %rbx
xorl %eax, %eax
cmpw $0x0, (%rbx,%rax,2)
jne 0x84fb8
incq %rax
cmpl %eax, %r13d
jne 0x84f9f
incq %r14
cmpl %r14d, %r15d
jne 0x84f91
jmp 0x84f7a
movq -0x20(%rsp), %rsi
movl %ebp, 0x8(%rsi)
movl %ebp, %ecx
cmpl %ecx, %edx
jle 0x8504c
movslq %edx, %rbx
movslq %r10d, %rax
movq %rax, -0x10(%rsp)
leal 0x1(%rdi), %ebp
movslq %ecx, %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, %edi
jge 0x85015
leaq -0x1(%rbx), %rax
addq $-0x40, %r12
cmpq -0x18(%rsp), %rbx
movq %rax, %rbx
jg 0x84ff9
jmp 0x8522a
movq -0x10(%rsp), %r14
cmpl %r9d, %r8d
jg 0x85038
movq (%rsi,%r14,8), %r15
addq %r12, %r15
xorl %eax, %eax
cmpw $0x0, (%r15,%rax,2)
jne 0x85042
incq %rax
cmpl %eax, %r13d
jne 0x85028
incq %r14
cmpl %r14d, %ebp
jne 0x8501a
jmp 0x84ffe
movq -0x20(%rsp), %rsi
movl %ebx, 0xc(%rsi)
movl %ebx, %edx
cmpl %r8d, %r9d
jle 0x850ca
movslq %ecx, %rbx
movslq %r10d, %rax
movq %rax, -0x10(%rsp)
leal 0x1(%rdi), %ebp
leal 0x1(%r9), %eax
movl %eax, -0x18(%rsp)
movl %edx, %r15d
subl %ecx, %r15d
incl %r15d
shlq $0x6, %rbx
movq -0x8(%rsp), %rsi
cmpl %r10d, %edi
jge 0x8508d
incq %r11
cmpl %r11d, -0x18(%rsp)
jne 0x85079
jmp 0x85234
movq -0x10(%rsp), %r13
cmpl %ecx, %edx
jl 0x850b4
movq (%rsi,%r13,8), %rax
addq %rbx, %rax
leaq (%rax,%r11,2), %r14
movl %r15d, %r12d
cmpw $0x0, (%r14)
jne 0x850be
addq $0x40, %r14
decl %r12d
jne 0x850a4
incq %r13
cmpl %r13d, %ebp
jne 0x85092
jmp 0x8507e
movq -0x20(%rsp), %rsi
movl %r11d, 0x10(%rsi)
movl %r11d, %r8d
movslq %r8d, %rax
movq %rax, -0x18(%rsp)
cmpl %r8d, %r9d
jle 0x8514e
movslq %r9d, %rbx
movslq %ecx, %r14
movslq %r10d, %rax
movq %rax, -0x10(%rsp)
leal 0x1(%rdi), %ebp
movl %edx, %r11d
subl %ecx, %r11d
incl %r11d
shlq $0x6, %r14
movq -0x8(%rsp), %rsi
cmpl %r10d, %edi
jge 0x85112
leaq -0x1(%rbx), %rax
cmpq -0x18(%rsp), %rbx
movq %rax, %rbx
jg 0x850fa
jmp 0x8523e
movq -0x10(%rsp), %r13
cmpl %ecx, %edx
jl 0x85139
movq (%rsi,%r13,8), %rax
addq %r14, %rax
leaq (%rax,%rbx,2), %r15
movl %r11d, %r12d
cmpw $0x0, (%r15)
jne 0x85143
addq $0x40, %r15
decl %r12d
jne 0x85129
incq %r13
cmpl %r13d, %ebp
jne 0x85117
jmp 0x850ff
movq -0x20(%rsp), %rsi
movl %ebx, 0x14(%rsi)
movl %ebx, %r9d
movl %edi, %eax
subl %r10d, %eax
shll $0x4, %eax
cltq
movl %edx, %r11d
subl %ecx, %r11d
shll $0x2, %r11d
leal (%r11,%r11,2), %r11d
movslq %r11d, %r11
movl %r9d, %ebx
subl %r8d, %ebx
leal (,%rbx,8), %ebp
movslq %ebp, %r14
imulq %rax, %rax
imulq %r11, %r11
imulq %r14, %r14
addq %rax, %r14
addq %r11, %r14
movq %r14, 0x18(%rsi)
cmpl %r10d, %edi
jge 0x85199
xorl %r11d, %r11d
jmp 0x851f8
movslq %r10d, %r10
movslq %ecx, %r14
leal 0x1(%rdx), %ebp
incl %edi
movq %r14, %rax
shlq $0x6, %rax
movq -0x18(%rsp), %rsi
leaq (%rax,%rsi,2), %r15
incl %ebx
xorl %r11d, %r11d
movq -0x8(%rsp), %rsi
cmpl %ecx, %edx
jl 0x851f0
movq (%rsi,%r10,8), %r12
addq %r15, %r12
movq %r14, %r13
cmpl %r8d, %r9d
jl 0x851e4
xorl %eax, %eax
cmpw $0x1, (%r12,%rax,2)
sbbq $-0x1, %r11
incq %rax
cmpl %eax, %ebx
jne 0x851d3
incq %r13
addq $0x40, %r12
cmpl %r13d, %ebp
jne 0x851cc
incq %r10
cmpl %r10d, %edi
jne 0x851be
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 0x84ebc
movq -0x20(%rsp), %rsi
jmp 0x84f45
movq -0x20(%rsp), %rsi
jmp 0x84fc2
movq -0x20(%rsp), %rsi
jmp 0x8504c
movq -0x20(%rsp), %rsi
jmp 0x850ca
movq -0x20(%rsp), %rsi
jmp 0x8514e