// File: /workspace/github_c_makefile_star2_O2/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 0x8335
testb %al, %al
je 0x80cc
testq %rbx, %rbx
je 0x803c
movb $0x0, (%rbx)
cmpl $0x2, %ebp
je 0x8146
cmpl $0x1, %ebp
je 0x80d3
testl %ebp, %ebp
jne 0x80cc
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
pushq $0x27
popq %r11
cmovnel %esi, %r11d
leal 0x5c(%rcx), %eax
leal 0x28(%rcx), %esi
cmpl $0x8, %ecx
cmovael %eax, %esi
andl %edx, %esi
cmpl %edi, %ecx
pushq $0x31
popq %r14
cmovnel %esi, %r14d
subq $0x8, %rsp
leaq 0x1f91(%rip), %r8       # 0xa034
leaq 0x1f96(%rip), %r9       # 0xa040
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
movq %rbx, %rdi
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x2040
addq $0x20, %rsp
jmp 0x81ec
xorl %eax, %eax
jmp 0x81f1
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 0x1f2d(%rip), %r8       # 0xa043
leaq 0x1f23(%rip), %r9       # 0xa040
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
movq %rbx, %rdi
movl $0x0, %eax
pushq %r15
pushq %r12
pushq %r11
pushq %r14
pushq %r10
callq 0x2040
addq $0x30, %rsp
jmp 0x81ec
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 0x1ea3(%rip), %r8       # 0xa059
leaq 0x1e83(%rip), %r9       # 0xa040
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
movq %rbx, %rdi
movl $0x0, %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