// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rdi, %r14
callq 0x18e38
cmpb $0x1, 0x2dd(%r14)
jne 0x1796e
leaq 0x1b46(%rip), %rax      # 0x190b2
leaq 0x1b4f(%rip), %rcx      # 0x190c2
cmpb $0x0, 0x24(%rbx)
cmovneq %rax, %rcx
movq 0xfa4e(%rip), %rdi      # 0x26fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
callq *%rcx
movq %r14, %rdi
callq 0x19322
cmpl $0x0, 0x2d8(%r14)
jne 0x1796e
leaq 0x38(%r14), %r13
cmpb $0x1, (%rbx)
jne 0x175d6
movq 0xfa1f(%rip), %rdi      # 0x26fd0
leaq 0x7c6d(%rip), %rsi      # 0x1f225
callq 0x2210
movl 0x54(%r14), %esi
imull 0x50(%r14), %esi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x2100
movq 0xf9f3(%rip), %rbp      # 0x26fd0
leaq 0x7c4e(%rip), %rsi      # 0x1f232
movq %rbp, %rdi
callq 0x2210
movq %rax, %r15
movl 0x50(%r14), %esi
movl 0x54(%r14), %edx
leaq 0x78(%rsp), %rax
movq %rax, (%rsp)
leaq 0x90(%rsp), %r12
leaq 0x88(%rsp), %r8
leaq 0x80(%rsp), %r9
movq %r13, %rdi
movq %r12, %rcx
callq 0x14ecc
movq %r15, %rdi
movq %rax, %rsi
callq 0x2150
leaq 0x7c11(%rip), %rsi      # 0x1f246
movq %rbp, %rdi
callq 0x2210
movq (%r12), %rsi
movq %rax, %rdi
callq 0x2150
leaq 0x7a09(%rip), %rsi      # 0x1f059
movq %rax, %rdi
callq 0x2210
leaq 0x88(%rsp), %rcx
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x2150
leaq 0x79ed(%rip), %rsi      # 0x1f05f
movq %rax, %rdi
callq 0x2210
leaq 0x80(%rsp), %rcx
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x2150
leaq 0x7bb8(%rip), %rsi      # 0x1f24c
movq %rax, %rdi
callq 0x2210
leaq 0x78(%rsp), %rcx
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x2150
leaq 0x68d5(%rip), %rsi      # 0x1df88
movq %rax, %rdi
callq 0x2210
movq %rbp, %rdi
callq 0x2100
movl 0x50(%r14), %ecx
movl 0x54(%r14), %eax
testq %rcx, %rcx
sete %dl
testl %eax, %eax
sete %sil
orb %dl, %sil
jne 0x1796e
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movaps 0x7ee9(%rip), %xmm1     # 0x1f5e0
movaps %xmm1, 0x40(%rsp)
movapd 0x7ecc(%rip), %xmm1     # 0x1f5d0
movapd %xmm1, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movq (%r13), %rdx
incq %rdx
leal (,%rcx,8), %esi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl %eax, %r8d
je 0x177a0
movl %edi, %r9d
xorl %r10d, %r10d
cmpq %rcx, %r10
je 0x17799
movl %r9d, %r11d
addq %rdx, %r11
xorl %r14d, %r14d
cmpq $0x4, %r14
je 0x17790
movzwl -0x1(%r11,%r14,2), %ebp
rolw $0x8, %bp
movzwl %bp, %ebp
cvtsi2sd %ebp, %xmm0
movsd 0x50(%rsp,%r14,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp,%r14,8)
movapd %xmm0, %xmm1
minsd 0x30(%rsp,%r14,8), %xmm1
movsd %xmm1, 0x30(%rsp,%r14,8)
maxsd 0x10(%rsp,%r14,8), %xmm0
movsd %xmm0, 0x10(%rsp,%r14,8)
incq %r14
jmp 0x17742
incq %r10
addl $0x8, %r9d
jmp 0x17734
incl %r8d
addl %esi, %edi
jmp 0x17729
imull %ecx, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x6888(%rip), %xmm0     # 0x1e038
xorl %eax, %eax
movsd 0x687e(%rip), %xmm1     # 0x1e038
cmpq $0x4, %rax
je 0x177f5
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
jmp 0x177ba
cmpb $0x0, (%rbx)
je 0x17815
movq 0xf7cf(%rip), %rdi      # 0x26fd0
leaq 0x7a4a(%rip), %rsi      # 0x1f252
callq 0x2210
movq %rax, %rdi
callq 0x2100
movq 0xf7b4(%rip), %r14      # 0x26fd0
leaq 0x7a60(%rip), %rsi      # 0x1f283
movq %r14, %rdi
callq 0x2210
movsd 0x50(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
leaq 0x74a4(%rip), %rbx      # 0x1ece4
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2210
movsd 0x58(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2210
movsd 0x60(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2210
movsd 0x68(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
callq 0x2100
leaq 0x79f9(%rip), %rsi      # 0x1f293
movq %r14, %rdi
callq 0x2210
movsd 0x30(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
leaq 0x79eb(%rip), %r14      # 0x1f2a2
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movsd 0x10(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2210
movsd 0x38(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movsd 0x18(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2210
movsd 0x40(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movsd 0x20(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2210
movsd 0x48(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movsd 0x28(%rsp), %xmm0
movq %rax, %rdi
callq 0x2330
movq %rax, %rdi
callq 0x2100
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq