// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movl %edx, %r15d
movl %esi, %r12d
movl %edi, %r13d
movb 0x60(%rsp), %al
cmpl $0xff, %ecx
je 0x16eea
movzbl %cl, %ecx
movzbl %r13b, %edx
imull %ecx, %edx
imulq $0x1010102, %rdx, %r13  # imm = 0x1010102
shrq $0x20, %r13
movzbl %r12b, %edx
imull %ecx, %edx
imulq $0x1010102, %rdx, %r12  # imm = 0x1010102
shrq $0x20, %r12
movzbl %r15b, %edx
imull %ecx, %edx
imulq $0x1010102, %rdx, %r15  # imm = 0x1010102
shrq $0x20, %r15
movb 0x68(%rsp), %bl
testb %al, %al
je 0x17014
movq %r8, 0x18(%rsp)
movq %r9, 0x20(%rsp)
movzbl %r13b, %ebp
movzbl %r12b, %r14d
movzbl %r15b, %edx
movl %edx, 0x14(%rsp)
leaq 0x13(%rsp), %rcx
leaq 0x12(%rsp), %r8
leaq 0x11(%rsp), %r9
movl %ebp, %edi
movl %r14d, %esi
callq 0x16d63
cmpb %r12b, %r13b
movl %ebx, %ecx
movl %r14d, %ebx
cmoval %ebp, %ebx
cmpb %r15b, %bl
movl 0x14(%rsp), %eax
cmovbel %eax, %ebx
cmpb %r13b, %r12b
cmovbl %r14d, %ebp
cmpb %bpl, %r15b
cmovbl %eax, %ebp
movl $0xff, %eax
andl %eax, %ebp
andl %eax, %ebx
addl %ebp, %ebx
shrl %ebx
testb %cl, %cl
je 0x16f66
xorl $0xff, %ebx
notb 0x11(%rsp)
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %r12
andl $0x3, %r12d
andl $0x3, %r15d
leal (%r12,%r15,4), %eax
leaq 0xc0fd(%rip), %r14      # 0x23080
movl (%r14,%rax,4), %eax
movl %eax, %ecx
shll $0x4, %ecx
addl %ecx, %eax
addl $-0x80, %eax
movl %eax, %edx
shll $0x8, %edx
subl %eax, %edx
subl %eax, %edx
leal 0xff(%rdx), %ecx
testl %edx, %edx
cmovnsl %edx, %ecx
movzbl 0x12(%rsp), %edx
sarl $0x8, %ecx
addl %edx, %ecx
cmpl $0x80, %ecx
jl 0x170c1
leal (%rax,%rax,4), %ecx
leal (%rax,%rcx,4), %edx
leal (%rax,%rcx,4), %eax
addl $0xff, %eax
testl %edx, %edx
cmovnsl %edx, %eax
shrl $0x8, %eax
addb 0x13(%rsp), %al
movzbl %al, %edi
callq 0x16dd1
leal (%r12,%r15,4), %ecx
xorl $0xa, %ecx
imull $0x440, (%r14,%rcx,4), %edx # imm = 0x440
movl %eax, %ecx
leal -0x2000(%rdx), %eax
addl $0xffffe0ff, %edx       # imm = 0xFFFFE0FF
testl %eax, %eax
cmovnsl %eax, %edx
sarl $0x8, %edx
addl %ebx, %edx
cmpl $0x50, %edx
setl %al
shlb $0x5, %al
orb %cl, %al
jmp 0x17125
movzbl %r13b, %edi
movzbl %r12b, %esi
movzbl %r15b, %edx
leaq 0x10(%rsp), %rcx
leaq 0xf(%rsp), %r8
leaq 0xe(%rsp), %r9
callq 0x16c96
testb %bl, %bl
je 0x1703c
notb 0xe(%rsp)
movb 0xe(%rsp), %bl
leal 0x17(%rbx), %eax
cmpb $0x2f, %al
jb 0x1706a
cmpb $0x3f, 0xf(%rsp)
jbe 0x1706a
movzbl 0x10(%rsp), %edi
callq 0x16dd1
movzbl %al, %ecx
orb $0x20, %al
testb %bl, %bl
movzbl %al, %eax
cmovsl %ecx, %eax
jmp 0x17125
movb $0x20, %al
cmpb $0x10, %bl
jb 0x17125
movb $0x2e, %al
cmpb $0x30, %bl
jb 0x17125
movb $0x3a, %al
cmpb $0x50, %bl
jb 0x17125
movb $0x2d, %al
cmpb $0x70, %bl
jb 0x17125
movb $0x21, %al
cmpb $-0x70, %bl
jb 0x17125
movb $0x2a, %al
cmpb $-0x50, %bl
jb 0x17125
movb $0x2b, %al
cmpb $-0x30, %bl
jb 0x17125
cmpb $-0x10, %bl
movl $0x3d, %ecx
movl $0x23, %eax
cmovbl %ecx, %eax
jmp 0x17125
movl %eax, %edx
shll $0x5, %edx
subl %eax, %edx
leal 0xff(%rdx), %ecx
testl %edx, %edx
cmovnsl %edx, %ecx
sarl $0x8, %ecx
addl %ebx, %ecx
movb $0x20, %al
cmpl $0x10, %ecx
jl 0x17125
movb $0x2e, %al
cmpl $0x30, %ecx
jl 0x17125
movb $0x3a, %al
cmpl $0x50, %ecx
jl 0x17125
movb $0x2d, %al
cmpl $0x70, %ecx
jl 0x17125
movb $0x21, %al
cmpl $0x90, %ecx
jl 0x17125
movb $0x2a, %al
cmpl $0xb0, %ecx
jl 0x17125
movb $0x2b, %al
cmpl $0xd0, %ecx
jl 0x17125
cmpl $0xf0, %ecx
movl $0x3d, %ecx
movl $0x23, %eax
cmovll %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq