// File: lvandeve[P]lodepng/pngdetail.cpp
// Function: RGBtoHSL(unsigned char, unsigned char, unsigned char, unsigned char*, unsigned char*, unsigned char*)
void RGBtoHSL(unsigned char r, unsigned char g, unsigned char b, unsigned char* h, unsigned char* s, unsigned char* l) {
  int cmax = std::max<int>(r, std::max<int>(g, b));
  int cmin = std::min<int>(r, std::min<int>(g, b));
  if(cmin == cmax) {
    *h = *s = 0;
    *l = r;
  } else {
    int sum = cmin + cmax;
    int diff = cmax - cmin;
    *l = sum / 2;
    *s = 255 * diff / ((*l < 128) ? sum : (512 - sum));
    int hi = (r == cmax) ? (255 * (g - b) / diff) : ((g == cmax) ? (512 + 255 * (b - r) / diff) : (1024 + 255 * (r - g) / diff));
    *h = ((hi / 6) & 255);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %dl, %al
movb %sil, %dl
movb %dil, %sil
movb %sil, -0x1(%rbp)
movb %dl, -0x2(%rbp)
movb %al, -0x3(%rbp)
movq %rcx, -0x10(%rbp)
movq %r8, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movzbl -0x1(%rbp), %eax
movl %eax, -0x28(%rbp)
movzbl -0x2(%rbp), %eax
movl %eax, -0x2c(%rbp)
movzbl -0x3(%rbp), %eax
movl %eax, -0x30(%rbp)
leaq -0x2c(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x32090
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x32090
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movzbl -0x1(%rbp), %eax
movl %eax, -0x38(%rbp)
movzbl -0x2(%rbp), %eax
movl %eax, -0x3c(%rbp)
movzbl -0x3(%rbp), %eax
movl %eax, -0x40(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x320d0
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x320d0
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x28810
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movb -0x1(%rbp), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
jmp 0x288fa
movl -0x34(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x24(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
imull $0xff, -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x80, %eax
jge 0x28855
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x28860
movl $0x200, %eax            # imm = 0x200
subl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl -0x54(%rbp), %ecx
cltd
idivl %ecx
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movzbl -0x1(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x28893
movzbl -0x2(%rbp), %eax
movzbl -0x3(%rbp), %ecx
subl %ecx, %eax
imull $0xff, %eax, %eax
cltd
idivl -0x48(%rbp)
movl %eax, -0x58(%rbp)
jmp 0x288dc
movzbl -0x2(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x288ba
movzbl -0x3(%rbp), %eax
movzbl -0x1(%rbp), %ecx
subl %ecx, %eax
imull $0xff, %eax, %eax
cltd
idivl -0x48(%rbp)
addl $0x200, %eax            # imm = 0x200
movl %eax, -0x5c(%rbp)
jmp 0x288d6
movzbl -0x1(%rbp), %eax
movzbl -0x2(%rbp), %ecx
subl %ecx, %eax
imull $0xff, %eax, %eax
cltd
idivl -0x48(%rbp)
addl $0x400, %eax            # imm = 0x400
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x6, %ecx
cltd
idivl %ecx
andl $0xff, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
addq $0x60, %rsp
popq %rbp
retq