// File: /workspace/github_c_makefile_star2_O1/aremmell[P]libsir/src/sirtextstyle.c
// Function: sir_formatstyle
bool _sir_formatstyle(sir_colormode mode, const sir_textstyle* style,
    char buf[SIR_MAXSTYLE]) {
    if (!_sir_validtextstyle(mode, style))
        return false;

    _sir_resetstr(buf);

    switch (mode) {
        case SIRCM_16:
            /* \x1b[attr;fg;bgm */
            return 0 < snprintf(buf, SIR_MAXSTYLE, "%s%"PRIu8";%"PRIu8";%"PRIu8"m",
                SIR_ESC, (uint8_t)style->attr, (uint8_t)_sir_mkansifgcolor(style->fg),
                (uint8_t)_sir_mkansibgcolor(style->bg));
        case SIRCM_256: {
            /* \x1b[attr;38;5;fg;48;5;bgm */
            return 0 < snprintf(buf, SIR_MAXSTYLE,
                "%s%"PRIu8";%"PRIu8";5;%"PRIu8";%"PRIu8";5;%"PRIu8"m", SIR_ESC,
                (uint8_t)style->attr, (uint8_t)_sir_getansifgcmd(style->fg),
                (uint8_t)style->fg, (uint8_t)_sir_getansibgcmd(style->bg),
                (uint8_t)style->bg);
        }
        case SIRCM_RGB: {
            /* \x1b[attr;38;2;rrr;ggg;bbb;48;2;rrr;ggg;bbbm */
            return 0 < snprintf(buf, SIR_MAXSTYLE,
                "%s%"PRIu8";%"PRIu8";2;%"PRIu8";%"PRIu8";%"PRIu8";%"PRIu8
                ";2;%"PRIu8";%"PRIu8";%"PRIu8"m", SIR_ESC, (uint8_t)style->attr,
                (uint8_t)_sir_getansifgcmd(style->fg), _sir_getredfromcolor(style->fg),
                _sir_getgreenfromcolor(style->fg), _sir_getbluefromcolor(style->fg),
                (uint8_t)_sir_getansibgcmd(style->bg), _sir_getredfromcolor(style->bg),
                _sir_getgreenfromcolor(style->bg), _sir_getbluefromcolor(style->bg));
        }
        case SIRCM_INVALID: // GCOVR_EXCL_START
        default:
            return false;
    } // GCOVR_EXCL_STOP
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movl %edi, %ebp
callq 0x89a6
testb %al, %al
je 0x8725
testq %rbx, %rbx
je 0x8685
movb $0x0, (%rbx)
cmpl $0x2, %ebp
je 0x87a4
cmpl $0x1, %ebp
je 0x872c
testl %ebp, %ebp
jne 0x8725
movzbl (%r14), %r10d
movl 0x4(%r14), %eax
movl 0x8(%r14), %ecx
leal 0x52(%rax), %edx
leal 0x1e(%rax), %esi
cmpl $0x8, %eax
cmovael %edx, %esi
movl $0xff, %edx
andl %edx, %esi
movl $0x100, %edi            # imm = 0x100
cmpl %edi, %eax
movl $0x27, %r11d
cmovnel %esi, %r11d
leal 0x5c(%rcx), %eax
leal 0x28(%rcx), %esi
cmpl $0x8, %ecx
cmovael %eax, %esi
andl %edx, %esi
cmpl %edi, %ecx
movl $0x31, %r14d
cmovnel %esi, %r14d
subq $0x8, %rsp
leaq 0x1950(%rip), %r8       # 0xa044
leaq 0x1955(%rip), %r9       # 0xa050
movl $0x2b, %esi
movq %rbx, %rdi
movl $0x1, %edx
movq $-0x1, %rcx
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x2040
addq $0x20, %rsp
jmp 0x884f
xorl %eax, %eax
jmp 0x8854
movzbl (%r14), %r10d
movl 0x4(%r14), %r11d
movl 0x8(%r14), %r15d
movl $0x100, %eax            # imm = 0x100
xorl %r14d, %r14d
cmpl %eax, %r11d
sete %r14b
orl $0x26, %r14d
movl $0xff, %ecx
andl %ecx, %r11d
xorl %r12d, %r12d
cmpl %eax, %r15d
sete %r12b
orl $0x30, %r12d
andl %ecx, %r15d
subq $0x8, %rsp
leaq 0x18e4(%rip), %r8       # 0xa053
leaq 0x18da(%rip), %r9       # 0xa050
movl $0x2b, %esi
movq %rbx, %rdi
movl $0x1, %edx
movq $-0x1, %rcx
xorl %eax, %eax
pushq %r15
pushq %r12
pushq %r11
pushq %r14
pushq %r10
callq 0x2040
addq $0x30, %rsp
jmp 0x884f
movzbl (%r14), %eax
movq %rax, 0x10(%rsp)
movl 0x4(%r14), %r15d
movl 0x8(%r14), %r11d
movl $0x100, %eax            # imm = 0x100
xorl %ecx, %ecx
cmpl %eax, %r15d
sete %cl
orl $0x26, %ecx
movq %rcx, 0x8(%rsp)
movl %r15d, %r14d
shrl $0x10, %r14d
movl $0xff, %ecx
andl %ecx, %r14d
movl %r15d, %r12d
shrl $0x8, %r12d
andl %ecx, %r12d
andl %ecx, %r15d
xorl %ebp, %ebp
cmpl %eax, %r11d
sete %bpl
orl $0x30, %ebp
movl %r11d, %r13d
shrl $0x10, %r13d
andl %ecx, %r13d
movl %r11d, %r10d
shrl $0x8, %r10d
andl %ecx, %r10d
andl %ecx, %r11d
subq $0x8, %rsp
leaq 0x1855(%rip), %r8       # 0xa069
leaq 0x1835(%rip), %r9       # 0xa050
movl $0x2b, %esi
movq %rbx, %rdi
movl $0x1, %edx
movq $-0x1, %rcx
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r13
pushq %rbp
pushq %r15
pushq %r12
pushq %r14
pushq 0x48(%rsp)
pushq 0x58(%rsp)
callq 0x2040
addq $0x50, %rsp
testl %eax, %eax
setg %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq