// File: 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
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x324b0
leaq -0x71(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x1af10
movq -0x118(%rbp), %rcx
leaq -0x70(%rbp), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x324d0
jmp 0x2b3b7
leaq -0x71(%rbp), %rdi
callq 0x1af60
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x1af10
movq -0x120(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x324d0
jmp 0x2b3ef
leaq -0xa1(%rbp), %rdi
callq 0x1af60
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x1af10
movq -0x128(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x324d0
jmp 0x2b42a
leaq -0xc1(%rbp), %rdi
callq 0x1af60
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x1af10
movq -0x130(%rbp), %rcx
leaq -0xe0(%rbp), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %edx, %edx
callq 0x324d0
jmp 0x2b465
leaq -0xe1(%rbp), %rdi
callq 0x1af60
movl $0x0, -0xe8(%rbp)
movl -0xe8(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x2b8d1
movl $0x0, -0xec(%rbp)
movl -0xec(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x2b8bb
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x138(%rbp)
jmp 0x2b4d3
movq -0x138(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movl %eax, -0x144(%rbp)
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x1(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x140(%rbp)
jmp 0x2b517
movl -0x144(%rbp), %eax
movq -0x140(%rbp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
movw %ax, -0xee(%rbp)
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x2(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x150(%rbp)
jmp 0x2b561
movq -0x150(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movl %eax, -0x15c(%rbp)
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x3(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x158(%rbp)
jmp 0x2b5a5
movl -0x15c(%rbp), %eax
movq -0x158(%rbp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
movw %ax, -0xf0(%rbp)
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x4(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x168(%rbp)
jmp 0x2b5ef
movq -0x168(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movl %eax, -0x174(%rbp)
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x5(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x170(%rbp)
jmp 0x2b633
movl -0x174(%rbp), %eax
movq -0x170(%rbp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
movw %ax, -0xf2(%rbp)
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x6(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x180(%rbp)
jmp 0x2b67d
movq -0x180(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movl %eax, -0x18c(%rbp)
movq -0x8(%rbp), %rdi
movl -0xe8(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0xec(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x7(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0x188(%rbp)
jmp 0x2b6c1
movl -0x18c(%rbp), %eax
movq -0x188(%rbp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
movw %ax, -0xf4(%rbp)
movzwl -0xee(%rbp), %edi
movzwl -0xf0(%rbp), %esi
callq 0x32540
movl %eax, -0x190(%rbp)
jmp 0x2b6f5
movl -0x190(%rbp), %eax
movl %eax, -0x100(%rbp)
movzwl -0xf2(%rbp), %edi
movzwl -0xf4(%rbp), %esi
callq 0x32540
movl %eax, -0x194(%rbp)
jmp 0x2b71c
movl -0x194(%rbp), %eax
movl %eax, -0x104(%rbp)
leaq -0xfc(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x104(%rbp), %rdx
callq 0x32570
jmp 0x2b744
leaq -0x58(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
callq 0x325a0
movq %rax, -0x1a0(%rbp)
jmp 0x2b75d
movq -0x1a0(%rbp), %rax
movq (%rax), %rcx
incq %rcx
movq %rcx, (%rax)
movzwl -0xee(%rbp), %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdi
callq 0x19560
movq %rax, -0x1a8(%rbp)
jmp 0x2b788
movq -0x1a8(%rbp), %rax
movb $0x1, (%rax)
movzwl -0xf0(%rbp), %eax
movl %eax, %esi
leaq -0xa0(%rbp), %rdi
callq 0x19560
movq %rax, -0x1b0(%rbp)
jmp 0x2b7b0
movq -0x1b0(%rbp), %rax
movb $0x1, (%rax)
movzwl -0xf2(%rbp), %eax
movl %eax, %esi
leaq -0xc0(%rbp), %rdi
callq 0x19560
movq %rax, -0x1b8(%rbp)
jmp 0x2b7d8
movq -0x1b8(%rbp), %rax
movb $0x1, (%rax)
movzwl -0xf4(%rbp), %eax
movl %eax, %esi
leaq -0xe0(%rbp), %rdi
callq 0x19560
movq %rax, -0x1c0(%rbp)
jmp 0x2b800
movq -0x1c0(%rbp), %rax
movb $0x1, (%rax)
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x2b494
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x1af60
jmp 0x2baf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xa1(%rbp), %rdi
callq 0x1af60
jmp 0x2baea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x1af60
jmp 0x2bab0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0x1af60
jmp 0x2ba84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x19430
jmp 0x2ba63
jmp 0x2b8bd
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x2b47b
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x110(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x19370
movq %rax, -0x1c8(%rbp)
jmp 0x2b928
movq -0x1d0(%rbp), %rax
movq -0x1c8(%rbp), %rcx
cmpq %rcx, %rax
jae 0x2ba24
movq -0x110(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x19560
movq %rax, -0x1d8(%rbp)
jmp 0x2b958
movq -0x1d8(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x110(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x19560
movq %rax, -0x1e0(%rbp)
jmp 0x2b98d
movq -0x1e0(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x110(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x19560
movq %rax, -0x1e8(%rbp)
jmp 0x2b9c2
movq -0x1e8(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %edx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x110(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x19560
movq %rax, -0x1f0(%rbp)
jmp 0x2b9f7
movq -0x1f0(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
movq 0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x110(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x110(%rbp)
jmp 0x2b908
leaq -0x58(%rbp), %rdi
callq 0x32680
movq %rax, -0x1f8(%rbp)
jmp 0x2ba36
leaq -0xe0(%rbp), %rdi
callq 0x19430
jmp 0x2ba44
leaq -0xc0(%rbp), %rdi
callq 0x19430
jmp 0x2ba65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2ba84
jmp 0x2ba84
leaq -0xa0(%rbp), %rdi
callq 0x19430
jmp 0x2ba94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2bab0
leaq -0xc0(%rbp), %rdi
callq 0x19430
jmp 0x2ba92
jmp 0x2bab0
leaq -0x70(%rbp), %rdi
callq 0x19430
jmp 0x2bac0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2baea
leaq -0xa0(%rbp), %rdi
callq 0x19430
jmp 0x2babe
jmp 0x2baea
leaq -0x58(%rbp), %rdi
callq 0x326a0
movq -0x1f8(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x2baf7
leaq -0x70(%rbp), %rdi
callq 0x19430
jmp 0x2baf5
jmp 0x2baf7
leaq -0x58(%rbp), %rdi
callq 0x326a0
jmp 0x2bb02
jmp 0x2bb04
movq -0x80(%rbp), %rdi
callq 0x2430
movq %rax, %rdi
callq 0x19400
nopw %cs:(%rax,%rax)