// File: /workspace/github_c_makefile_star2_O0/comfies[P]custard/src/ipc/parsing.c
// Function: string_to_color
color_t string_to_color(char *string) {
    color_t color = {
        .red   = 255,
        .green = 255,
        .blue  = 255,
        .alpha = 255
    };

    if (!string || string[0] != '#')
        return color;

    unsigned int length = strlen(string);
    if (length <= 4 || (5 < length && length < 7) || length == 8 || length > 9)
        return color;

    unsigned int offset = 0;
    if (length < 6) offset = 4;

    char group[8] = "000000ff";
    for (unsigned int index = 0; index < (length - 1); index++)
        group[index + offset] = string[index + 1];

    unsigned int rgba;
    rgba = strtol(group, NULL, 16);

    if (offset) {
        color.alpha = (rgba & 0x000F) * 0x11;
        color.red   = ((rgba & 0xF000) / 0x1000) * 0x11;
        color.green = ((rgba & 0x0F00) / 0x100) * 0x11;
        color.blue  = ((rgba & 0x00F0) / 0x10) * 0x11;
    } else {
        color.alpha = (rgba & 0x000000FF);
        color.red   = (rgba & 0xFF000000) / 0x1000000;
        color.green = (rgba & 0x00FF0000) / 0x10000;
        color.blue  = (rgba & 0x0000FF00) / 0x100;
    }

    return color;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl 0x5366(%rip), %eax      # 0xa228
movl %eax, -0x4(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x4ed8
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x4edd
jmp 0x4ffc
movq -0x10(%rbp), %rdi
callq 0x31f0
movl %eax, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jbe 0x4f0b
movl $0x5, %eax
cmpl -0x14(%rbp), %eax
jae 0x4eff
cmpl $0x7, -0x14(%rbp)
jb 0x4f0b
cmpl $0x8, -0x14(%rbp)
je 0x4f0b
cmpl $0x9, -0x14(%rbp)
jbe 0x4f10
jmp 0x4ffc
movl $0x0, -0x18(%rbp)
cmpl $0x6, -0x14(%rbp)
jae 0x4f24
movl $0x4, -0x18(%rbp)
movq 0x5301(%rip), %rax      # 0xa22c
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x4f69
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movl -0x24(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, %eax
movb %cl, -0x20(%rbp,%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4f36
leaq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x33f0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x4fc5
movl -0x28(%rbp), %eax
andl $0xf, %eax
imull $0x11, %eax, %eax
movb %al, -0x1(%rbp)
movl -0x28(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
shrl $0xc, %eax
imull $0x11, %eax, %eax
movb %al, -0x4(%rbp)
movl -0x28(%rbp), %eax
andl $0xf00, %eax            # imm = 0xF00
shrl $0x8, %eax
imull $0x11, %eax, %eax
movb %al, -0x3(%rbp)
movl -0x28(%rbp), %eax
andl $0xf0, %eax
shrl $0x4, %eax
imull $0x11, %eax, %eax
movb %al, -0x2(%rbp)
jmp 0x4ffa
movl -0x28(%rbp), %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
movl -0x28(%rbp), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
shrl $0x18, %eax
movb %al, -0x4(%rbp)
movl -0x28(%rbp), %eax
andl $0xff0000, %eax         # imm = 0xFF0000
shrl $0x10, %eax
movb %al, -0x3(%rbp)
movl -0x28(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
shrl $0x8, %eax
movb %al, -0x2(%rbp)
jmp 0x4ffc
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop