// File: lvandeve[P]lodepng/pngdetail.cpp
// Function: displayPalettePixels(std::vector<unsigned char, std::allocator<unsigned char>> const&, Options const&)
void displayPalettePixels(const std::vector<unsigned char>& buffer, const Options& options) {
  unsigned w, h;
  lodepng::State state;
  std::vector<unsigned char> out;
  std::cout << (options.use_hex ? std::hex: std::dec);

  state.decoder.color_convert = 0;

  lodepng::decode(out, w, h, state, buffer);

  if(state.info_png.color.colortype == LCT_PALETTE) {
    if (options.show_color_stats) {
      std::vector<size_t> count(256, 0);
      size_t outofbounds = 0;

      for(size_t i = 0; i < w * h; i++) {
        int value = lodepng::getPaletteValue(&out[0], i, state.info_raw.bitdepth);
        count[value]++;
        if(value >= (int)state.info_raw.palettesize) outofbounds++;
      }

      std::cout << "Palette count: ";
      for(size_t i = 0; i < state.info_raw.palettesize; i++) {
        std::cout << count[i] << " ";
      }
      std::cout << std::endl;

      if(outofbounds > 0) std::cout << "Out of bounds palette values: " << outofbounds << std::endl;
    }

    std::cout << "Pixel palette indices:" << std::endl;
    for(size_t i = 0; i < w * h; i++) {
      int value = lodepng::getPaletteValue(&out[0], i, state.info_raw.bitdepth);
      std::cout << value << ", ";
      if(i % w == w - 1) std::cout << std::endl;
    }
  } else {
    std::cout << "Pixel palette indices: not shown, not a palette image\n" << std::endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x380, %rsp            # imm = 0x380
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x10a40
leaq -0x2b0(%rbp), %rdi
callq 0x19410
jmp 0x2a7bd
movq -0x10(%rbp), %rax
testb $0x1, 0x24(%rax)
je 0x2a7d7
leaq 0x7482(%rip), %rax      # 0x31c50
movq %rax, -0x318(%rbp)
jmp 0x2a7e7
leaq 0x74a2(%rip), %rax      # 0x31c80
movq %rax, -0x318(%rbp)
jmp 0x2a7e7
movq -0x318(%rbp), %rsi
movq 0x1c7db(%rip), %rdi     # 0x46fd0
callq 0x20b0
jmp 0x2a7fc
movl $0x0, -0x264(%rbp)
movq -0x8(%rbp), %r8
leaq -0x2b0(%rbp), %rdi
leaq -0x14(%rbp), %rsi
leaq -0x18(%rbp), %rdx
leaq -0x298(%rbp), %rcx
callq 0x10da0
jmp 0x2a827
cmpl $0x3, -0x1b8(%rbp)
jne 0x2ac07
movq -0x10(%rbp), %rax
testb $0x1, 0x9(%rax)
je 0x2aaee
leaq -0x2d9(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x322b0
movq -0x320(%rbp), %rcx
leaq -0x2d8(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x322d0
jmp 0x2a871
leaq -0x2d9(%rbp), %rdi
callq 0x32340
movq $0x0, -0x2e8(%rbp)
movq $0x0, -0x2f0(%rbp)
movq -0x2f0(%rbp), %rax
movl -0x14(%rbp), %ecx
imull -0x18(%rbp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x2a9d5
xorl %eax, %eax
movl %eax, %esi
leaq -0x2b0(%rbp), %rdi
callq 0x19560
movq %rax, -0x328(%rbp)
jmp 0x2a8c5
movq -0x328(%rbp), %rdi
movq -0x2f0(%rbp), %rsi
movl -0x1ec(%rbp), %edx
callq 0x1cd70
movl %eax, -0x32c(%rbp)
jmp 0x2a8e6
movl -0x32c(%rbp), %eax
movl %eax, -0x2f4(%rbp)
movslq -0x2f4(%rbp), %rsi
leaq -0x2d8(%rbp), %rdi
callq 0x31dd0
movq %rax, -0x338(%rbp)
jmp 0x2a90e
movq -0x338(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl -0x2f4(%rbp), %eax
movq -0x1e0(%rbp), %rcx
cmpl %ecx, %eax
jl 0x2a9bc
movq -0x2e8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2e8(%rbp)
jmp 0x2a9bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
jmp 0x2ac6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
jmp 0x2ac5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
leaq -0x2d9(%rbp), %rdi
callq 0x32340
jmp 0x2ac5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b8(%rbp)
movl %eax, -0x2bc(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x31f90
jmp 0x2aae9
jmp 0x2a9be
movq -0x2f0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2f0(%rbp)
jmp 0x2a893
movq 0x1c5f4(%rip), %rdi     # 0x46fd0
leaq 0xfbcc(%rip), %rsi      # 0x3a5af
callq 0x2250
jmp 0x2a9ea
movq $0x0, -0x300(%rbp)
movq -0x300(%rbp), %rax
cmpq -0x1e0(%rbp), %rax
jae 0x2aa6b
movq -0x300(%rbp), %rsi
leaq -0x2d8(%rbp), %rdi
callq 0x31dd0
movq %rax, -0x340(%rbp)
jmp 0x2aa21
movq -0x340(%rbp), %rax
movq (%rax), %rsi
movq 0x1c59e(%rip), %rdi     # 0x46fd0
callq 0x2080
movq %rax, -0x348(%rbp)
jmp 0x2aa40
movq -0x348(%rbp), %rdi
leaq 0x1039f(%rip), %rsi     # 0x3aded
callq 0x2250
jmp 0x2aa55
jmp 0x2aa57
movq -0x300(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x300(%rbp)
jmp 0x2a9f5
movq 0x1c55e(%rip), %rdi     # 0x46fd0
movq 0x1c547(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2aa80
cmpq $0x0, -0x2e8(%rbp)
jbe 0x2aad9
movq 0x1c53f(%rip), %rdi     # 0x46fd0
leaq 0xfb27(%rip), %rsi      # 0x3a5bf
callq 0x2250
movq %rax, -0x350(%rbp)
jmp 0x2aaa6
movq -0x350(%rbp), %rdi
movq -0x2e8(%rbp), %rsi
callq 0x2080
movq %rax, -0x358(%rbp)
jmp 0x2aac2
movq -0x358(%rbp), %rdi
movq 0x1c4f0(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2aad7
jmp 0x2aad9
leaq -0x2d8(%rbp), %rdi
callq 0x31f90
jmp 0x2aae7
jmp 0x2aaee
jmp 0x2ac5d
movq 0x1c4db(%rip), %rdi     # 0x46fd0
leaq 0xfae2(%rip), %rsi      # 0x3a5de
callq 0x2250
movq %rax, -0x360(%rbp)
jmp 0x2ab0a
movq -0x360(%rbp), %rdi
movq 0x1c4a8(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2ab1f
movq $0x0, -0x308(%rbp)
movq -0x308(%rbp), %rax
movl -0x14(%rbp), %ecx
imull -0x18(%rbp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x2ac05
xorl %eax, %eax
movl %eax, %esi
leaq -0x2b0(%rbp), %rdi
callq 0x19560
movq %rax, -0x368(%rbp)
jmp 0x2ab5c
movq -0x368(%rbp), %rdi
movq -0x308(%rbp), %rsi
movl -0x1ec(%rbp), %edx
callq 0x1cd70
movl %eax, -0x36c(%rbp)
jmp 0x2ab7d
movl -0x36c(%rbp), %eax
movl %eax, -0x30c(%rbp)
movl -0x30c(%rbp), %esi
movq 0x1c43a(%rip), %rdi     # 0x46fd0
callq 0x2420
movq %rax, -0x378(%rbp)
jmp 0x2aba4
movq -0x378(%rbp), %rdi
leaq 0xfdcc(%rip), %rsi      # 0x3a97e
callq 0x2250
jmp 0x2abb9
movq -0x308(%rbp), %rax
movl -0x14(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
cmpq %rax, %rdx
jne 0x2abec
movq 0x1c3f4(%rip), %rdi     # 0x46fd0
movq 0x1c3dd(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2abea
jmp 0x2abec
jmp 0x2abee
movq -0x308(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x308(%rbp)
jmp 0x2ab2a
jmp 0x2ac3a
movq 0x1c3c2(%rip), %rdi     # 0x46fd0
leaq 0xf9e0(%rip), %rsi      # 0x3a5f5
callq 0x2250
movq %rax, -0x380(%rbp)
jmp 0x2ac23
movq -0x380(%rbp), %rdi
movq 0x1c38f(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x2ac38
jmp 0x2ac3a
leaq -0x2b0(%rbp), %rdi
callq 0x19430
jmp 0x2ac48
leaq -0x298(%rbp), %rdi
callq 0x10a90
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
leaq -0x2b0(%rbp), %rdi
callq 0x19430
jmp 0x2ac6b
jmp 0x2ac6d
leaq -0x298(%rbp), %rdi
callq 0x10a90
jmp 0x2ac7b
jmp 0x2ac7d
movq -0x2b8(%rbp), %rdi
callq 0x2430
movq %rax, %rdi
callq 0x19400
nopw %cs:(%rax,%rax)