// File: /workspace/github_cpp_makefile_star2_O2/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, 0x4(%rsp)
movl %esi, %r12d
movq %rdi, 0x38(%rsp)
leaq 0xb0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x19288
leaq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x19288
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x19288
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
leaq 0x48(%rsp), %rdi
xorl %ebx, %ebx
leaq 0x8(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x19288
movl %r12d, %eax
shll $0x3, %r12d
movq %r12, 0x28(%rsp)
shlq $0x3, %rax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
cmpl 0x4(%rsp), %ebx
je 0x15096
movq %rbx, 0x30(%rsp)
xorl %ebx, %ebx
cmpq %rbx, 0x40(%rsp)
je 0x15085
leal (%r15,%rbx), %ecx
movq 0x38(%rsp), %rax
movq (%rax), %rax
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r15,%rbx), %edx
incl %edx
movzbl (%rax,%rdx), %r14d
orq %rcx, %r14
leal (%r15,%rbx), %ecx
addl $0x2, %ecx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r15,%rbx), %edx
addl $0x3, %edx
movzbl (%rax,%rdx), %r13d
orq %rcx, %r13
leal (%r15,%rbx), %ecx
addl $0x4, %ecx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r15,%rbx), %edx
addl $0x5, %edx
movzbl (%rax,%rdx), %ebp
orq %rcx, %rbp
leal (%r15,%rbx), %ecx
addl $0x6, %ecx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
leal (%r15,%rbx), %edx
addl $0x7, %edx
movzbl (%rax,%rdx), %r12d
orq %rcx, %r12
movl %r13d, %eax
shll $0x10, %eax
orl %r14d, %eax
movl %r12d, %ecx
shll $0x10, %ecx
orl %ebp, %ecx
movl %eax, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x192c2
incq (%rax)
movq 0x90(%rsp), %rax
movb $0x1, %cl
movb %cl, (%rax,%r14)
movq 0x78(%rsp), %rax
movb %cl, (%rax,%r13)
movq 0x60(%rsp), %rax
movb %cl, (%rax,%rbp)
movq 0x48(%rsp), %rax
movb %cl, (%rax,%r12)
addq $0x8, %rbx
jmp 0x14fa4
movq 0x30(%rsp), %rbx
incl %ebx
addq 0x28(%rsp), %r15
jmp 0x14f93
movq 0x110(%rsp), %r14
andq $0x0, (%r14)
movq 0x20(%rsp), %r10
andq $0x0, (%r10)
movq 0x18(%rsp), %r11
andq $0x0, (%r11)
movq 0x10(%rsp), %rbx
andq $0x0, (%rbx)
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
subq %rax, %rcx
movq 0x78(%rsp), %rdx
movq 0x60(%rsp), %rsi
xorl %edi, %edi
movq 0x48(%rsp), %r8
cmpq %rdi, %rcx
je 0x1510b
movzbl (%rax,%rdi), %r9d
addq %r9, (%rbx)
movzbl (%rdx,%rdi), %r9d
addq %r9, (%r11)
movzbl (%rsi,%rdi), %r9d
addq %r9, (%r10)
movzbl (%r8,%rdi), %r9d
addq %r9, (%r14)
incq %rdi
jmp 0x150e1
movq 0xd0(%rsp), %rbx
leaq 0x48(%rsp), %rdi
callq 0xea4c
leaq 0x60(%rsp), %rdi
callq 0xea4c
leaq 0x78(%rsp), %rdi
callq 0xea4c
leaq 0x90(%rsp), %rdi
callq 0xea4c
leaq 0xa8(%rsp), %rdi
callq 0x1960c
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15177
jmp 0x15172
jmp 0x1516d
jmp 0x15168
movq %rax, %rbx
jmp 0x15189
movq %rax, %rbx
jmp 0x15193
movq %rax, %rbx
jmp 0x1519d
movq %rax, %rbx
jmp 0x151aa
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xea4c
leaq 0x60(%rsp), %rdi
callq 0xea4c
leaq 0x78(%rsp), %rdi
callq 0xea4c
leaq 0x90(%rsp), %rdi
callq 0xea4c
leaq 0xa8(%rsp), %rdi
callq 0x1960c
movq %rbx, %rdi
callq 0x23a0
movq %rax, %rdi
callq 0xe69c