// File: /workspace/github_cpp_makefile_star2_O1/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 0x1e094
cmpb $0x1, 0x2dd(%r15)
jne 0x1c629
leaq 0x220d(%rip), %rax      # 0x1e2ff
leaq 0x2216(%rip), %rcx      # 0x1e30f
cmpb $0x0, 0x24(%r14)
cmovneq %rax, %rcx
movq 0xeec7(%rip), %rbx      # 0x2afd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
callq *%rcx
movq 0x38(%r15), %rax
cmpq 0x40(%r15), %rax
jne 0x1c127
movq %r15, %rdi
callq 0x1e5f4
cmpl $0x0, 0x2d8(%r15)
jne 0x1c629
leaq 0x38(%r15), %rax
movq %rax, 0x8(%rsp)
cmpb $0x1, (%r14)
jne 0x1c19a
movq 0xee85(%rip), %r13      # 0x2afd0
leaq 0x80a5(%rip), %rsi      # 0x241f7
movl $0xc, %edx
movq %r13, %rdi
callq 0x2280
movl 0x54(%r15), %esi
imull 0x50(%r15), %esi
movq %r13, %rdi
callq 0x2150
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
leaq 0x8063(%rip), %rsi      # 0x24204
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2280
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 0x1893e
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2150
leaq 0x801c(%rip), %rsi      # 0x24218
movl $0x5, %edx
movq %rbx, %rdi
callq 0x2280
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x2150
movq %rax, %r12
leaq 0x7e0c(%rip), %rsi      # 0x2402b
movl $0x5, %edx
movq %rax, %rdi
callq 0x2280
movq (%rbp), %rsi
movq %r12, %rdi
callq 0x2150
movq %rax, %r12
leaq 0x7def(%rip), %rsi      # 0x24031
movl $0x5, %edx
movq %rax, %rdi
callq 0x2280
movq (%r13), %rsi
movq %r12, %rdi
callq 0x2150
movq %rax, %r12
leaq 0x7fb9(%rip), %rsi      # 0x2421e
movl $0x5, %edx
movq %rax, %rdi
callq 0x2280
leaq 0x78(%rsp), %rax
movq (%rax), %rsi
movq %r12, %rdi
callq 0x2150
leaq 0x6c65(%rip), %rsi      # 0x22eee
movl $0x1, %edx
movq %rax, %rdi
callq 0x2280
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
movl 0x50(%r15), %ecx
movl 0x54(%r15), %eax
testq %rcx, %rcx
sete %dl
testl %eax, %eax
sete %sil
orb %dl, %sil
jne 0x1c629
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movaps 0x82bf(%rip), %xmm1     # 0x245b0
movaps %xmm1, 0x40(%rsp)
movapd 0x82a2(%rip), %xmm1     # 0x245a0
movapd %xmm1, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
incq %rdx
leal (,%rcx,8), %esi
xorl %edi, %edi
xorl %r8d, %r8d
movl %edi, %r9d
xorl %r10d, %r10d
movl %r9d, %r11d
addq %rdx, %r11
xorl %r15d, %r15d
movzwl -0x1(%r11,%r15,2), %ebp
rolw $0x8, %bp
movzwl %bp, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd 0x50(%rsp,%r15,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp,%r15,8)
movapd %xmm0, %xmm1
minsd 0x30(%rsp,%r15,8), %xmm1
maxsd 0x10(%rsp,%r15,8), %xmm0
movsd %xmm1, 0x30(%rsp,%r15,8)
movsd %xmm0, 0x10(%rsp,%r15,8)
incq %r15
cmpq $0x4, %r15
jne 0x1c336
incq %r10
addl $0x8, %r9d
cmpq %rcx, %r10
jne 0x1c32d
incl %r8d
addl %esi, %edi
cmpl %eax, %r8d
jne 0x1c327
imull %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x6bea(%rip), %xmm0     # 0x22f98
xorl %eax, %eax
movsd 0x6be0(%rip), %xmm1     # 0x22f98
movsd 0x50(%rsp,%rax,8), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x50(%rsp,%rax,8)
movsd 0x30(%rsp,%rax,8), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x30(%rsp,%rax,8)
movsd 0x10(%rsp,%rax,8), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp,%rax,8)
incq %rax
cmpq $0x4, %rax
jne 0x1c3b8
cmpb $0x0, (%r14)
je 0x1c432
leaq 0x7e26(%rip), %rsi      # 0x24224
movl $0x30, %edx
movq %rbx, %rdi
callq 0x2280
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
movq 0xeb97(%rip), %r14      # 0x2afd0
leaq 0x7e15(%rip), %rsi      # 0x24255
movl $0xf, %edx
movq %r14, %rdi
callq 0x2280
movsd 0x50(%rsp), %xmm0
movq %r14, %rdi
callq 0x2320
movq %rax, %r15
leaq 0x7851(%rip), %rbx      # 0x23cb6
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2280
movsd 0x58(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2280
movsd 0x60(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2280
movsd 0x68(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
leaq 0x7d6f(%rip), %rsi      # 0x24265
movl $0xe, %edx
movq %r14, %rdi
callq 0x2280
movsd 0x30(%rsp), %xmm0
movq %r14, %rdi
callq 0x2320
movq %rax, %r15
leaq 0x7d59(%rip), %r14      # 0x24274
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2280
movsd 0x10(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2280
movsd 0x38(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2280
movsd 0x18(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2280
movsd 0x40(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2280
movsd 0x20(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2280
movsd 0x48(%rsp), %xmm0
movq %r15, %rdi
callq 0x2320
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2280
movsd 0x28(%rsp), %xmm0
movq %rbx, %rdi
callq 0x2320
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq