// File: /workspace/github_cpp_makefile_star2_O2/lvandeve[P]lodepng/pngdetail.cpp
// Function: RGBtoLetter(unsigned char, unsigned char, unsigned char, unsigned char, unsigned int, unsigned int, bool, bool)
char RGBtoLetter(unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned x, unsigned y, bool dither = true, bool inverted = false) {
  if(a < 255) {
    r = a * r / 255;
    g = a * g / 255;
    b = a * b / 255;
  }

  if(dither) {
    unsigned char h, c, t;
    RGBtoHCT(r, g, b, &h, &c, &t);
    int l = (std::max(std::max(r, g), b) + std::min(std::min(r, g), b)) / 2;
    if(inverted) {
      l = 255 - l;
      t = 255 - t;
    }
    if(applyDither(c, 254, x, y, false) >= 128) {
      char letter = HueToLetter(applyDither(h, 21, x, y, true));
      bool smallcaps = applyDither(l, 64, x+2, y+2, false) < 80;
      return letter + (smallcaps ? 32 : 0);
    }
    else return lightnessToLetter(applyDither(l, 31, x, y, false));
  } else {
    unsigned char h, s, l;
    RGBtoHSL(r, g, b, &h, &s, &l);
    if(inverted) l = 255 - l;

    char hl = HueToLetter(h);
    char c = ' ';
    if(l < 24 || l > 232 || s < 64) {
      c = lightnessToLetter(l);
    } else {
      if(l < 128) c = hl + 32;
      else c = hl;
    }
    return c;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movl %esi, %r15d
movl %edi, %r12d
movb 0x50(%rsp), %sil
cmpl $0xff, %ecx
je 0x13aac
movzbl %cl, %edi
movzbl %r12b, %eax
imull %edi, %eax
movw $0xff, %r10w
xorl %edx, %edx
divw %r10w
movzbl %r15b, %ecx
imull %edi, %ecx
movl %eax, %r12d
movl %ecx, %eax
xorl %edx, %edx
divw %r10w
movzbl %r14b, %ecx
imull %edi, %ecx
movl %eax, %r15d
movl %ecx, %eax
xorl %edx, %edx
divw %r10w
movl %eax, %r14d
movb 0x58(%rsp), %r13b
testb %sil, %sil
je 0x13b9a
movl %r8d, 0x10(%rsp)
movzbl %r12b, %r13d
movzbl %r15b, %ebx
movl %r9d, 0x14(%rsp)
movzbl %r14b, %ebp
leaq 0xd(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0xf(%rsp), %r9
movl %r13d, %edi
movl %ebx, %esi
movl %ebp, %edx
callq 0x13935
cmpb %r15b, %r12b
movl %ebx, %eax
cmoval %r13d, %eax
cmpb %r14b, %al
cmovbel %ebp, %eax
cmpb %r12b, %r15b
cmovbl %ebx, %r13d
cmpb %r13b, %r14b
cmovbl %ebp, %r13d
movl 0x14(%rsp), %ebp
movl $0xff, %r14d
andl %r14d, %r13d
andl %r14d, %eax
addl %r13d, %eax
movl 0x10(%rsp), %r15d
shrl %eax
xorl %eax, %r14d
movb 0x58(%rsp), %cl
testb %cl, %cl
cmovel %eax, %r14d
leaq 0xc(%rsp), %rax
movzbl (%rax), %edi
movl $0xfe, %esi
movl %r15d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x13c1b
cmpl $0x80, %eax
jl 0x13bf2
movzbl 0xd(%rsp), %edi
pushq $0x15
popq %rsi
pushq $0x1
popq %r8
movl %r15d, %edx
movl %ebp, %ecx
callq 0x13c1b
movl %eax, %edi
callq 0x13997
movl %eax, %ebx
addl $0x2, %r15d
addl $0x2, %ebp
pushq $0x40
popq %rsi
movl %r14d, %edi
movl %r15d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x13c1b
cmpl $0x50, %eax
setl %al
shlb $0x5, %al
orb %bl, %al
jmp 0x13c0c
movzbl %r12b, %edi
movzbl %r15b, %esi
movzbl %r14b, %edx
leaq 0xb(%rsp), %rcx
leaq 0xa(%rsp), %r8
leaq 0xe(%rsp), %rbx
movq %rbx, %r9
callq 0x1387f
negb %r13b
xorb (%rbx), %r13b
leal 0x17(%r13), %eax
cmpb $0x2f, %al
jb 0x13bec
cmpb $0x3f, 0xa(%rsp)
jbe 0x13bec
movzbl 0xb(%rsp), %edi
callq 0x13997
movzbl %al, %ecx
orb $0x20, %al
testb %r13b, %r13b
movzbl %al, %eax
cmovsl %ecx, %eax
jmp 0x13c0c
movzbl %r13b, %edi
jmp 0x13c07
pushq $0x1f
popq %rsi
movl %r14d, %edi
movl %r15d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x13c1b
movl %eax, %edi
callq 0x13a02
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq