// File: /workspace/github_c_makefile_star2_O2/termbox[P]termbox/termbox.c
// Function: send_attr
static void send_attr(uint16_t fg, uint16_t bg) {
#define LAST_ATTR_INIT 0xFFFF
    static uint16_t lastfg = LAST_ATTR_INIT, lastbg = LAST_ATTR_INIT;
    if (fg != lastfg || bg != lastbg) {
        bytebuffer_puts(&output_buffer, funcs[T_SGR0]);

        uint16_t fgcol;
        uint16_t bgcol;

        switch (outputmode) {
        case TB_OUTPUT_256:
            fgcol = fg & 0xFF;
            bgcol = bg & 0xFF;
            break;

        case TB_OUTPUT_216:
            fgcol = fg & 0xFF;
            if (fgcol > 215)
                fgcol = 7;
            bgcol = bg & 0xFF;
            if (bgcol > 215)
                bgcol = 0;
            fgcol += 0x10;
            bgcol += 0x10;
            break;

        case TB_OUTPUT_GRAYSCALE:
            fgcol = fg & 0xFF;
            if (fgcol > 23)
                fgcol = 23;
            bgcol = bg & 0xFF;
            if (bgcol > 23)
                bgcol = 0;
            fgcol += 0xe8;
            bgcol += 0xe8;
            break;

        case TB_OUTPUT_NORMAL:
        default:
            fgcol = fg & 0x0F;
            bgcol = bg & 0x0F;
        }

        if (fg & TB_BOLD)
            bytebuffer_puts(&output_buffer, funcs[T_BOLD]);
        if (bg & TB_BOLD)
            bytebuffer_puts(&output_buffer, funcs[T_BLINK]);
        if (fg & TB_UNDERLINE)
            bytebuffer_puts(&output_buffer, funcs[T_UNDERLINE]);
        if ((fg & TB_REVERSE) || (bg & TB_REVERSE))
            bytebuffer_puts(&output_buffer, funcs[T_REVERSE]);

        write_sgr(fgcol, bgcol);

        lastfg = fg;
        lastbg = bg;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebx
movl %edi, %ebp
cmpw %bp, 0x57ce(%rip)       # 0x9880
jne 0x40c1
cmpw %bx, 0x57c7(%rip)       # 0x9882
je 0x42fe
movq 0x5830(%rip), %rax      # 0x98f8
movq 0x28(%rax), %rdi
callq 0x3ba5
movl 0x5085(%rip), %eax      # 0x915c
cmpl $0x4, %eax
je 0x4126
cmpl $0x3, %eax
je 0x40f7
cmpl $0x2, %eax
jne 0x4155
movl $0xff, %r13d
movl %ebp, %r12d
andl %r13d, %r12d
andl %ebx, %r13d
jmp 0x4163
movl $0xff, %eax
movl %ebp, %ecx
andl %eax, %ecx
movl %ecx, %edx
addl $0x10, %edx
andl %ebx, %eax
leal 0x10(%rax), %esi
movw $0xd8, %di
cmpw %di, %cx
pushq $0x17
popq %r12
cmovbl %edx, %r12d
cmpw %di, %ax
pushq $0x10
popq %r13
cmovbl %esi, %r13d
jmp 0x4163
movl $0xff, %eax
movl %ebp, %ecx
andl %eax, %ecx
cmpw $0x17, %cx
pushq $0x17
popq %r12
cmovbl %ecx, %r12d
andl %ebx, %eax
movl $0xe8, %ecx
movl %eax, %r13d
addl %ecx, %r13d
addl %ecx, %r12d
cmpw $0x18, %ax
cmovael %ecx, %r13d
jmp 0x4163
movl %ebp, %r12d
andl $0xf, %r12d
movl %ebx, %r13d
andl $0xf, %r13d
btl $0x8, %ebp
jae 0x4179
movq 0x5788(%rip), %rax      # 0x98f8
movq 0x38(%rax), %rdi
callq 0x3ba5
movzwl %bx, %r14d
btl $0x8, %r14d
jae 0x4194
movq 0x576d(%rip), %rax      # 0x98f8
movq 0x40(%rax), %rdi
callq 0x3ba5
btl $0x9, %ebp
jae 0x41aa
movq 0x5757(%rip), %rax      # 0x98f8
movq 0x30(%rax), %rdi
callq 0x3ba5
orl %ebp, %r14d
btl $0xa, %r14d
jae 0x41c4
movq 0x573d(%rip), %rax      # 0x98f8
movq 0x48(%rax), %rdi
callq 0x3ba5
movl %r13d, %eax
orw %r12w, %ax
je 0x42f0
movzwl %r12w, %r15d
movzwl %r13w, %eax
movl %eax, 0xc(%rsp)
movl 0x4f78(%rip), %r14d     # 0x915c
addl $-0x2, %r14d
leaq 0x2179(%rip), %rdi      # 0x6368
pushq $0x2
popq %rsi
callq 0x4a1c
cmpl $0x2, %r14d
ja 0x424b
testw %r12w, %r12w
je 0x4294
leaq 0x21a0(%rip), %rdi      # 0x63ae
pushq $0x5
popq %rsi
callq 0x4a1c
leaq 0x10(%rsp), %r12
movl %r15d, %edi
movq %r12, %rsi
callq 0x4a63
movq %r12, %rdi
movl %eax, %esi
callq 0x4a1c
testw %r13w, %r13w
je 0x42e1
leaq 0x2171(%rip), %rdi      # 0x63b2
pushq $0x1
popq %rsi
callq 0x4a1c
jmp 0x429a
testw %r12w, %r12w
je 0x42af
leaq 0x2162(%rip), %rdi      # 0x63ba
pushq $0x1
popq %rsi
callq 0x4a1c
decl %r15d
leaq 0x10(%rsp), %r12
movl %r15d, %edi
movq %r12, %rsi
callq 0x4a63
movq %r12, %rdi
movl %eax, %esi
callq 0x4a1c
testw %r13w, %r13w
je 0x42e1
leaq 0x2128(%rip), %rdi      # 0x63b2
pushq $0x1
popq %rsi
callq 0x4a1c
jmp 0x42b5
testw %r13w, %r13w
je 0x42e1
leaq 0x2113(%rip), %rdi      # 0x63b4
pushq $0x5
popq %rsi
callq 0x4a1c
movl 0xc(%rsp), %edi
jmp 0x42ca
testw %r13w, %r13w
je 0x42e1
leaq 0x2100(%rip), %rdi      # 0x63bc
pushq $0x1
popq %rsi
callq 0x4a1c
movl 0xc(%rsp), %edi
decl %edi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x4a63
movq %r15, %rdi
movl %eax, %esi
callq 0x4a1c
leaq 0x2072(%rip), %rdi      # 0x635a
pushq $0x1
popq %rsi
callq 0x4a1c
movw %bp, 0x5589(%rip)       # 0x9880
movw %bx, 0x5584(%rip)       # 0x9882
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq