// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/pngdetail.cpp
// Function: showColorStats(Data&, Options const&)
void showColorStats(Data& data, const Options& options) {
  data.loadInspect();
  if(!data.is_png) return;
  std::cout << (options.use_hex ? std::hex: std::dec);
  std::vector<unsigned char>& image = data.pixels;
  unsigned& w = data.w;
  unsigned& h = data.h;

  data.loadPixels();
  if(data.error) return;
  // TODO: move to show color stats function
  if(options.verbose) std::cout << "Num pixels: " << w * h << std::endl;
  size_t rc, gc, bc, ac;
  std::cout << "Num unique colors: " << countColors(image, w, h, &rc, &gc, &bc, &ac);
  std::cout << " (r: " << rc << ", g: " << gc << ", b: " << bc << ", a: " << ac << ")";
  std::cout << std::endl;
  if(w > 0 && h > 0) {
    double avg[4] = {0, 0, 0, 0};
    double min[4] = {999999, 999999, 999999, 999999};
    double max[4] = {0, 0, 0, 0};
    for(unsigned y = 0; y < h; y++) {
      for(unsigned x = 0; x < w; x++) {
        for(int c = 0; c < 4; c++) {
          double v = 256 * image[y * 8 * w + x * 8 + c * 2] + image[y * 8 * w + x * 8 + c * 2 + 1];
          avg[c] += v;
          min[c] = std::min(min[c], v);
          max[c] = std::max(max[c], v);
        }
      }
    }
    for(int c = 0; c < 4; c++) {
      avg[c] /= (w * h * 257.0);
      min[c] /= 257.0;
      max[c] /= 257.0;
    }
    if(options.verbose) std::cout << "Ranges shown as 0.0-255.0, even for 16-bit data:" << std::endl;
    std::cout << "Average color: " << avg[0] << ", " << avg[1] << ", " << avg[2] << ", " << avg[3] << std::endl;
    std::cout << "Color ranges: " << min[0] << "-" << max[0] << ", " << min[1] << "-" << max[1] << ", " << min[2] << "-" << max[2] << ", " << min[3] << "-" << max[3] << std::endl;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
movq %rdi, %r15
callq 0x1df4c
cmpb $0x1, 0x2dd(%r15)
jne 0x1c48b
leaq 0x22b5(%rip), %rax      # 0x1e1e9
leaq 0x22be(%rip), %rcx      # 0x1e1f9
cmpb $0x0, 0x24(%r14)
cmovneq %rax, %rcx
movq 0xf085(%rip), %rbx      # 0x2afd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
callq *%rcx
movq 0x38(%r15), %rax
cmpq 0x40(%r15), %rax
jne 0x1bf69
movq %r15, %rdi
callq 0x1e4e8
cmpl $0x0, 0x2d8(%r15)
jne 0x1c48b
leaq 0x38(%r15), %rax
movq %rax, 0x8(%rsp)
cmpb $0x1, (%r14)
jne 0x1bfdc
movq 0xf043(%rip), %r13      # 0x2afd0
leaq 0x844d(%rip), %rsi      # 0x243e1
movl $0xc, %edx
movq %r13, %rdi
callq 0x2290
movl 0x54(%r15), %esi
imull 0x50(%r15), %esi
movq %r13, %rdi
callq 0x2160
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
leaq 0x840b(%rip), %rsi      # 0x243ee
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2290
movl 0x50(%r15), %esi
movl 0x54(%r15), %edx
leaq 0x78(%rsp), %rax
movq %rax, (%rsp)
leaq 0x90(%rsp), %r12
leaq 0x88(%rsp), %rbp
leaq 0x80(%rsp), %r13
movq 0x8(%rsp), %rdi
movq %r12, %rcx
movq %rbp, %r8
movq %r13, %r9
callq 0x18758
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2160
leaq 0x83c4(%rip), %rsi      # 0x24402
movl $0x5, %edx
movq %rbx, %rdi
callq 0x2290
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x2160
movq %rax, %r12
leaq 0x81b4(%rip), %rsi      # 0x24215
movl $0x5, %edx
movq %rax, %rdi
callq 0x2290
movq (%rbp), %rsi
movq %r12, %rdi
callq 0x2160
movq %rax, %r12
leaq 0x8197(%rip), %rsi      # 0x2421b
movl $0x5, %edx
movq %rax, %rdi
callq 0x2290
movq (%r13), %rsi
movq %r12, %rdi
callq 0x2160
movq %rax, %r12
leaq 0x8361(%rip), %rsi      # 0x24408
movl $0x5, %edx
movq %rax, %rdi
callq 0x2290
leaq 0x78(%rsp), %rax
movq (%rax), %rsi
movq %r12, %rdi
callq 0x2160
leaq 0x700b(%rip), %rsi      # 0x230d6
movl $0x1, %edx
movq %rax, %rdi
callq 0x2290
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movl 0x50(%r15), %ecx
movl 0x54(%r15), %eax
testq %rcx, %rcx
sete %dl
testl %eax, %eax
sete %sil
orb %dl, %sil
jne 0x1c48b
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps 0x8660(%rip), %xmm1     # 0x24790
movaps %xmm1, 0x40(%rsp)
movapd 0x8643(%rip), %xmm1     # 0x24780
movapd %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
leal (,%rcx,8), %esi
xorl %edi, %edi
movq 0x706a(%rip), %xmm0     # 0x231d0
xorl %r8d, %r8d
movl %edi, %r9d
xorl %r10d, %r10d
movl %r9d, %r11d
addq %rdx, %r11
xorl %r15d, %r15d
movd (%r11,%r15,2), %xmm1
pshuflw $0xd4, %xmm1, %xmm2     # xmm2 = xmm1[0,1,1,3,4,5,6,7]
pand %xmm0, %xmm2
pslld $0x8, %xmm2
psrld $0x8, %xmm1
pshuflw $0xd4, %xmm1, %xmm1     # xmm1 = xmm1[0,1,1,3,4,5,6,7]
pand %xmm0, %xmm1
por %xmm2, %xmm1
cvtdq2pd %xmm1, %xmm1
movapd 0x50(%rsp,%r15,8), %xmm2
addpd %xmm1, %xmm2
movapd %xmm2, 0x50(%rsp,%r15,8)
movapd %xmm1, %xmm2
minpd 0x30(%rsp,%r15,8), %xmm2
maxpd 0x10(%rsp,%r15,8), %xmm1
movapd %xmm2, 0x30(%rsp,%r15,8)
movapd %xmm1, 0x10(%rsp,%r15,8)
addq $0x2, %r15
cmpq $0x4, %r15
jne 0x1c178
incq %r10
addl $0x8, %r9d
cmpq %rcx, %r10
jne 0x1c16f
incl %r8d
addl %esi, %edi
cmpl %eax, %r8d
jne 0x1c169
imull %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x6f7d(%rip), %xmm0     # 0x23188
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
xorl %eax, %eax
movapd 0x6fc7(%rip), %xmm1     # 0x231e0
movapd 0x50(%rsp,%rax,8), %xmm2
divpd %xmm0, %xmm2
movapd %xmm2, 0x50(%rsp,%rax,8)
movapd 0x30(%rsp,%rax,8), %xmm2
divpd %xmm1, %xmm2
movapd %xmm2, 0x30(%rsp,%rax,8)
movapd 0x10(%rsp,%rax,8), %xmm2
divpd %xmm1, %xmm2
movapd %xmm2, 0x10(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x4, %rax
jne 0x1c219
cmpb $0x1, (%r14)
jne 0x1c294
leaq 0x81ae(%rip), %rsi      # 0x2440e
movl $0x30, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq 0xed35(%rip), %r14      # 0x2afd0
leaq 0x819d(%rip), %rsi      # 0x2443f
movl $0xf, %edx
movq %r14, %rdi
callq 0x2290
movsd 0x50(%rsp), %xmm0
movq %r14, %rdi
callq 0x2330
movq %rax, %r15
leaq 0x7bd9(%rip), %rbx      # 0x23ea0
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2290
movsd 0x58(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2290
movsd 0x60(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2290
movsd 0x68(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
leaq 0x80f7(%rip), %rsi      # 0x2444f
movl $0xe, %edx
movq %r14, %rdi
callq 0x2290
movsd 0x30(%rsp), %xmm0
movq %r14, %rdi
callq 0x2330
movq %rax, %r15
leaq 0x80e1(%rip), %r14      # 0x2445e
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2290
movsd 0x10(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2290
movsd 0x38(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2290
movsd 0x18(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2290
movsd 0x40(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2290
movsd 0x20(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2290
movsd 0x48(%rsp), %xmm0
movq %r15, %rdi
callq 0x2330
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2290
movsd 0x28(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2330
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq