// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/pngdetail.cpp
// Function: displayColorsHex(std::vector<unsigned char, std::allocator<unsigned char>> const&, unsigned int, unsigned int, bool)
void displayColorsHex(const std::vector<unsigned char>& image, unsigned w, unsigned h, bool sixteen) {
  std::ios_base::fmtflags flags = std::cout.flags();

  if(w > 0 && h > 0) {
    std::cout << "Colors (CSS RGBA hex format):" << std::endl;

    for(unsigned y = 0; y < h; y++) {
      std::cout.flags(flags); //print line numbers in hex or dec whatever it originally was
      std::cout << y << ":";
      for(unsigned x = 0; x < w; x++) {
        size_t index = y * w * 8 + x * 8;
        if (sixteen) {
          int r = image[index + 0] * 256 + image[index + 1];
          int g = image[index + 2] * 256 + image[index + 3];
          int b = image[index + 4] * 256 + image[index + 5];
          int a = image[index + 6] * 256 + image[index + 7];
          std::cout << std::hex << std::setfill('0') << " #" << std::setw(4) << r << std::setw(4) << g << std::setw(4) << b << std::setw(4) << a;
        } else {
          int r = image[index + 0];
          int g = image[index + 2];
          int b = image[index + 4];
          int a = image[index + 6];
          std::cout << std::hex << std::setfill('0') << " #" << std::setw(2) << r << std::setw(2) << g << std::setw(2) << b << std::setw(2) << a;
        }
      }
      std::cout << std::endl;
    }
  }

  std::cout.flags(flags);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0x1c(%rsp)
movl %edx, %ebp
movq %rdi, 0x40(%rsp)
movq 0x13767(%rip), %rbx     # 0x2afd0
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
movl %ecx, 0x8(%rsp)
testl %esi, %esi
sete %cl
testl %edx, %edx
sete %dl
orb %cl, %dl
jne 0x17acf
movl %esi, %r14d
leaq 0xc1e0(%rip), %rsi      # 0x23a74
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movl %ebp, %eax
movq %rax, 0x28(%rsp)
movl %r14d, %eax
movq %rax, 0x20(%rsp)
shll $0x3, %r14d
xorl %r13d, %r13d
xorl %esi, %esi
movl %r14d, 0x18(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x8(%rsp), %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %rbx, %rdi
movq %rsi, 0x30(%rsp)
callq 0x2160
movl $0x1, %edx
movq %rax, %rdi
leaq 0xc1bf(%rip), %rsi      # 0x23acf
callq 0x2290
movq 0x20(%rsp), %r12
movq %r13, 0x38(%rsp)
movl %r13d, %r13d
movq 0x40(%rsp), %rax
movq (%rax), %rax
movzbl (%rax,%r13), %r14d
cmpb $0x0, 0x1c(%rsp)
je 0x1799a
shll $0x8, %r14d
movzbl 0x1(%rax,%r13), %ecx
orl %ecx, %r14d
movzwl 0x2(%rax,%r13), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, 0xc(%rsp)
movzwl 0x4(%rax,%r13), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, 0x10(%rsp)
movzwl 0x6(%rax,%r13), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x14(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r15
movl $0x4, %ebp
jmp 0x179da
movzbl 0x2(%rax,%r13), %ecx
movl %ecx, 0xc(%rsp)
movzbl 0x4(%rax,%r13), %ecx
movl %ecx, 0x10(%rsp)
movzbl 0x6(%rax,%r13), %eax
movl %eax, 0x14(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r15
movl $0x2, %ebp
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0x179f9
movq %r15, %rdi
movl $0x20, %esi
callq 0x2220
movb $0x1, 0xe1(%r15)
movb $0x30, 0xe0(%r15)
movl $0x2, %edx
movq %rbx, %rdi
leaq 0xc082(%rip), %rsi      # 0x23a92
callq 0x2290
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbp, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2390
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq %rbp, 0x10(%rax,%rcx)
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2390
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq %rbp, 0x10(%rax,%rcx)
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x2390
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq %rbp, 0x10(%rax,%rcx)
movq %rax, %rdi
movl 0x14(%rsp), %esi
callq 0x2390
addl $0x8, %r13d
decq %r12
jne 0x1791f
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq 0x30(%rsp), %rsi
incq %rsi
movl 0x18(%rsp), %r14d
movq 0x38(%rsp), %r13
addl %r14d, %r13d
cmpq 0x28(%rsp), %rsi
jne 0x178e5
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x8(%rsp), %ecx
movl %ecx, 0x18(%rbx,%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq