// File: lvandeve[P]lodepng/pngdetail.cpp
// Function: displayAsciiArt(std::vector<unsigned char, std::allocator<unsigned char>> const&, unsigned int, unsigned int, unsigned int)
void displayAsciiArt(const std::vector<unsigned char>& image, unsigned w, unsigned h, unsigned asciiw) {
  const std::vector<unsigned char>* imagep = &image;
  std::vector<unsigned char> image2;
  if(asciiw < w) {
    unsigned w2 = asciiw;
    unsigned h2 = h * w2 / w;
    image2 = rescale(image, w, h, w2, h2, true);
    imagep = &image2;
    w = w2;
    h = h2;
  }
  if(w > 0 && h > 0) {
    std::cout << "ASCII Art Preview: " << std::endl;
    unsigned h2 = 1 + ((h - 1) * 4) / 7; //compensate for non-square characters in terminal
    std::cout << '+';
    for(unsigned x = 0; x < w; x++) std::cout << '-';
    std::cout << '+' << std::endl;
    for(unsigned y = 0; y < h2; y++) {
      std::cout << "|";
      unsigned y2 = y * h / h2;
      for(unsigned x = 0; x < w; x++) {
        int r = (*imagep)[y2 * w * 8 + x * 8 + 0];
        int g = (*imagep)[y2 * w * 8 + x * 8 + 2];
        int b = (*imagep)[y2 * w * 8 + x * 8 + 4];
        int a = (*imagep)[y2 * w * 8 + x * 8 + 6];
        char symbol = RGBtoLetter(r, g, b, a, x, y, true, false);
        std::cout << (char)symbol;
      }
      std::cout << "|";
      std::cout << std::endl;
    }
    std::cout << '+';
    for(unsigned x = 0; x < w; x++) std::cout << '-';
    std::cout << '+' << std::endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x19410
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x29991
movl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
imull %ecx, %eax
movl -0xc(%rbp), %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
movl -0x3c(%rbp), %r8d
movl -0x40(%rbp), %r9d
movq %rsp, %rax
movl $0x1, (%rax)
leaq -0x58(%rbp), %rdi
callq 0x28f40
jmp 0x29934
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x22490
jmp 0x29943
leaq -0x58(%rbp), %rdi
callq 0x19430
jmp 0x2994e
leaq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x29991
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x29cd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x19430
jmp 0x2998c
jmp 0x29cd4
cmpl $0x0, -0xc(%rbp)
jbe 0x29cc2
cmpl $0x0, -0x10(%rbp)
jbe 0x29cc2
movq 0x1d624(%rip), %rdi     # 0x46fd0
leaq 0x10b53(%rip), %rsi     # 0x3a506
callq 0x2250
movq %rax, -0x98(%rbp)
jmp 0x299c1
movq -0x98(%rbp), %rdi
movq 0x1d5f1(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x299d6
movl -0x10(%rbp), %ecx
movl %ecx, %eax
leal -0x4(,%rax,4), %eax
movl %eax, %ecx
imulq $0x24924925, %rcx, %rcx # imm = 0x24924925
shrq $0x20, %rcx
subl %ecx, %eax
shrl %eax
addl %ecx, %eax
shrl $0x2, %eax
incl %eax
movl %eax, -0x68(%rbp)
movq 0x1d5cc(%rip), %rdi     # 0x46fd0
movl $0x2b, %esi
callq 0x22f0
jmp 0x29a10
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x29a3f
movq 0x1d5aa(%rip), %rdi     # 0x46fd0
movl $0x2d, %esi
callq 0x22f0
jmp 0x29a32
jmp 0x29a34
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x29a17
movq 0x1d58a(%rip), %rdi     # 0x46fd0
movl $0x2b, %esi
callq 0x22f0
movq %rax, -0xa0(%rbp)
jmp 0x29a59
movq -0xa0(%rbp), %rdi
movq 0x1d559(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x29a6e
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x68(%rbp), %eax
jae 0x29c43
movq 0x1d548(%rip), %rdi     # 0x46fd0
leaq 0x10a8b(%rip), %rsi     # 0x3a51a
callq 0x2250
jmp 0x29a96
movl -0x70(%rbp), %eax
imull -0x10(%rbp), %eax
xorl %edx, %edx
divl -0x68(%rbp)
movl %eax, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x29c09
movq -0x20(%rbp), %rdi
movl -0x74(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0x78(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0xa8(%rbp)
jmp 0x29ae2
movq -0xa8(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x20(%rbp), %rdi
movl -0x74(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0x78(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x2(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0xb0(%rbp)
jmp 0x29b1a
movq -0xb0(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x80(%rbp)
movq -0x20(%rbp), %rdi
movl -0x74(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0x78(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x4(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0xb8(%rbp)
jmp 0x29b52
movq -0xb8(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x20(%rbp), %rdi
movl -0x74(%rbp), %eax
movl -0xc(%rbp), %ecx
imull %ecx, %eax
movl -0x78(%rbp), %edx
shll $0x3, %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x6(%rax,%rcx,8), %eax
movl %eax, %esi
callq 0x19350
movq %rax, -0xc0(%rbp)
jmp 0x29b8d
movq -0xc0(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x88(%rbp)
movzbl -0x7c(%rbp), %edi
movzbl -0x80(%rbp), %esi
movzbl -0x84(%rbp), %edx
movzbl -0x88(%rbp), %ecx
movl -0x78(%rbp), %r8d
movl -0x70(%rbp), %r9d
movq %rsp, %rax
movl $0x0, 0x8(%rax)
movl $0x1, (%rax)
callq 0x28bf0
movb %al, -0xc1(%rbp)
jmp 0x29bd8
movb -0xc1(%rbp), %al
movb %al, -0x89(%rbp)
movsbl -0x89(%rbp), %esi
movq 0x1d3de(%rip), %rdi     # 0x46fd0
callq 0x22f0
jmp 0x29bf9
jmp 0x29bfb
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x29aac
movq 0x1d3c0(%rip), %rdi     # 0x46fd0
leaq 0x10903(%rip), %rsi     # 0x3a51a
callq 0x2250
jmp 0x29c1e
movq 0x1d3ab(%rip), %rdi     # 0x46fd0
movq 0x1d394(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x29c33
jmp 0x29c35
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x29a75
movq 0x1d386(%rip), %rdi     # 0x46fd0
movl $0x2b, %esi
callq 0x22f0
jmp 0x29c56
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x29c91
movq 0x1d35e(%rip), %rdi     # 0x46fd0
movl $0x2d, %esi
callq 0x22f0
jmp 0x29c7e
jmp 0x29c80
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x29c60
movq 0x1d338(%rip), %rdi     # 0x46fd0
movl $0x2b, %esi
callq 0x22f0
movq %rax, -0xd0(%rbp)
jmp 0x29cab
movq -0xd0(%rbp), %rdi
movq 0x1d307(%rip), %rsi     # 0x46fc0
callq 0x22a0
jmp 0x29cc0
jmp 0x29cc2
leaq -0x38(%rbp), %rdi
callq 0x19430
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x19430
jmp 0x29cdf
jmp 0x29ce1
movq -0x60(%rbp), %rdi
callq 0x2430
movq %rax, %rdi
callq 0x19400
nopw %cs:(%rax,%rax)