// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/pngdetail.cpp
// Function: countColors(std::vector<unsigned char, std::allocator<unsigned char>> const&, unsigned int, unsigned int, unsigned long*, unsigned long*, unsigned long*, unsigned long*)
size_t countColors(const std::vector<unsigned char>& image, unsigned w, unsigned h,
    size_t* ro, size_t* go, size_t* bo, size_t* ao) {
  typedef std::pair<std::pair<unsigned short, unsigned short>, std::pair<unsigned short, unsigned short> > RGBA;
  std::map<RGBA, size_t> rgbam;
  //std::map<uint64_t, size_t> rgbam;
  std::vector<unsigned char> rm(65536, 0);
  std::vector<unsigned char> gm(65536, 0);
  std::vector<unsigned char> bm(65536, 0);
  std::vector<unsigned char> am(65536, 0);
  for(unsigned y = 0; y < h; y++) {
    for(unsigned x = 0; x < w; x++) {
      unsigned short r = 256 * image[y * 8 * w + x * 8 + 0] + image[y * 8 * w + x * 8 + 1];
      unsigned short g = 256 * image[y * 8 * w + x * 8 + 2] + image[y * 8 * w + x * 8 + 3];
      unsigned short b = 256 * image[y * 8 * w + x * 8 + 4] + image[y * 8 * w + x * 8 + 5];
      unsigned short a = 256 * image[y * 8 * w + x * 8 + 6] + image[y * 8 * w + x * 8 + 7];
      RGBA rgba(std::make_pair(r, g), std::make_pair(b, a));
      //uint64_t rgba = (uint64_t)r + ((uint64_t)g << 16) + ((uint64_t)b << 32) + ((uint64_t)a << 48);
      rgbam[rgba]++;
      rm[r] = 1;
      gm[g] = 1;
      bm[b] = 1;
      am[a] = 1;
    }
  }
  *ro = *go = *bo = *ao = 0;
  for(size_t i = 0; i < rm.size(); i++) {
    *ro += rm[i];
    *go += gm[i];
    *bo += bm[i];
    *ao += am[i];
  }

  return rgbam.size();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movl %edx, (%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x40(%rsp)
leaq 0xb0(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x1e40c
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x1e40c
leaq 0x48(%rsp), %rdi
leaq 0x90(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x1e40c
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x8(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x1e40c
cmpl $0x0, (%rsp)
je 0x1893a
movq 0x10(%rsp), %rcx
leal (,%rcx,8), %eax
movl %ecx, %ecx
movl %eax, %eax
movq %rax, 0x30(%rsp)
shlq $0x3, %rcx
movq %rcx, 0x38(%rsp)
xorl %r12d, %r12d
xorl %eax, %eax
movl %eax, 0x4(%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x18926
xorl %ebx, %ebx
leal (%r12,%rbx), %ecx
movq 0x40(%rsp), %rax
movq (%rax), %rax
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r12,%rbx), %edx
incl %edx
movzbl (%rax,%rdx), %r14d
orq %rcx, %r14
leal (%r12,%rbx), %ecx
addl $0x2, %ecx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r12,%rbx), %edx
addl $0x3, %edx
movzbl (%rax,%rdx), %r13d
orq %rcx, %r13
leal (%r12,%rbx), %ecx
addl $0x4, %ecx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r12,%rbx), %edx
addl $0x5, %edx
movzbl (%rax,%rdx), %r15d
orq %rcx, %r15
leal (%r12,%rbx), %ecx
addl $0x6, %ecx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r12,%rbx), %edx
addl $0x7, %edx
movzbl (%rax,%rdx), %ebp
orq %rcx, %rbp
movl %r13d, %eax
shll $0x10, %eax
orl %r14d, %eax
movl %ebp, %ecx
shll $0x10, %ecx
orl %r15d, %ecx
movl %eax, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1e446
incq (%rax)
movq 0x78(%rsp), %rax
movb $0x1, %cl
movb %cl, (%rax,%r14)
movq 0x60(%rsp), %rax
movb %cl, (%rax,%r13)
movq 0x48(%rsp), %rax
movb %cl, (%rax,%r15)
movq 0x90(%rsp), %rax
movb %cl, (%rax,%rbp)
addq $0x8, %rbx
cmpq %rbx, 0x38(%rsp)
jne 0x1884a
movl 0x4(%rsp), %eax
incl %eax
addq 0x30(%rsp), %r12
cmpl (%rsp), %eax
jne 0x18839
movq 0x110(%rsp), %rax
xorl %ecx, %ecx
movq %rcx, (%rax)
movq 0x28(%rsp), %r11
movq %rcx, (%r11)
movq 0x20(%rsp), %rbx
movq %rcx, (%rbx)
movq 0x18(%rsp), %r14
movq %rcx, (%r14)
movq 0x78(%rsp), %rcx
movq 0x80(%rsp), %rdx
movq 0x90(%rsp), %rdi
subq %rcx, %rdx
je 0x189c0
movq 0x60(%rsp), %rsi
movq 0x48(%rsp), %r8
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %r9d, %r9d
movzbl (%rcx,%r9), %r10d
addq %r10, (%r14)
movzbl (%rsi,%r9), %r10d
addq %r10, (%rbx)
movzbl (%r8,%r9), %r10d
addq %r10, (%r11)
movzbl (%rdi,%r9), %r10d
addq %r10, (%rax)
incq %r9
cmpq %r9, %rdx
jne 0x1898e
movq 0xd0(%rsp), %rbx
jmp 0x189cd
movq 0xd0(%rsp), %rbx
testq %rdi, %rdi
je 0x189d2
callq 0x2210
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x189e1
callq 0x2210
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x189f0
callq 0x2210
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x189ff
callq 0x2210
leaq 0xa8(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x1e7be
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x18a4e
movq %rax, %rbx
jmp 0x18a5d
movq %rax, %rbx
jmp 0x18a6c
movq %rax, %rbx
jmp 0x18a7b
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x18a4e
callq 0x2210
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x18a5d
callq 0x2210
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x18a6c
callq 0x2210
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x18a7b
callq 0x2210
leaq 0xa8(%rsp), %rdi
movq 0x10(%rdi), %rsi
callq 0x1e7be
movq %rbx, %rdi
callq 0x23a0
movq %rax, %rdi
callq 0x14c96