// File: /workspace/github_c_makefile_star2_O3/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, 0x5601(%rip)       # 0x9880
jne 0x428e
cmpw %bx, 0x55fa(%rip)       # 0x9882
je 0x451f
movq 0x5663(%rip), %rax      # 0x98f8
movq 0x28(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4ceb
movl 0x4eab(%rip), %eax      # 0x915c
cmpl $0x4, %eax
je 0x4301
cmpl $0x3, %eax
je 0x42d1
cmpl $0x2, %eax
jne 0x4332
movl $0xff, %r13d
movl %ebp, %r12d
andl %r13d, %r12d
andl %ebx, %r13d
jmp 0x4340
movl $0xff, %eax
movl %ebp, %ecx
andl %eax, %ecx
leal 0x10(%rcx), %edx
andl %ebx, %eax
leal 0x10(%rax), %esi
movl $0xd8, %edi
cmpl %edi, %ecx
movl $0x17, %r12d
cmovbl %edx, %r12d
cmpl %edi, %eax
movl $0x10, %r13d
cmovbl %esi, %r13d
jmp 0x4340
movl $0xff, %eax
movl %ebp, %ecx
andl %eax, %ecx
cmpw $0x17, %cx
movl $0x17, %r12d
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 0x4340
movl %ebp, %r12d
andl $0xf, %r12d
movl %ebx, %r13d
andl $0xf, %r13d
btl $0x8, %ebp
jae 0x4363
movq 0x55ab(%rip), %rax      # 0x98f8
movq 0x38(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4ceb
movzwl %bx, %r15d
btl $0x8, %r15d
jae 0x438b
movq 0x5583(%rip), %rax      # 0x98f8
movq 0x40(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4ceb
btl $0x9, %ebp
jae 0x43ae
movq 0x5560(%rip), %rax      # 0x98f8
movq 0x30(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4ceb
orl %ebp, %r15d
btl $0xa, %r15d
jae 0x43d5
movq 0x5539(%rip), %rax      # 0x98f8
movq 0x48(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4ceb
movl %r13d, %eax
orw %r12w, %ax
je 0x4511
movzwl %r12w, %r15d
movzwl %r13w, %eax
movl %eax, 0xc(%rsp)
movl 0x4d67(%rip), %r14d     # 0x915c
addl $-0x2, %r14d
leaq 0x1f68(%rip), %rdi      # 0x6368
movl $0x2, %esi
callq 0x4ceb
cmpl $0x2, %r14d
ja 0x4462
testw %r12w, %r12w
je 0x44af
leaq 0x1f8d(%rip), %rdi      # 0x63ae
movl $0x5, %esi
callq 0x4ceb
leaq 0x10(%rsp), %r12
movl %r15d, %edi
movq %r12, %rsi
callq 0x4d5b
movq %r12, %rdi
movl %eax, %esi
callq 0x4ceb
testw %r13w, %r13w
je 0x4500
leaq 0x1f5c(%rip), %rdi      # 0x63b2
movl $0x1, %esi
callq 0x4ceb
jmp 0x44b5
testw %r12w, %r12w
je 0x44cc
leaq 0x1f4b(%rip), %rdi      # 0x63ba
movl $0x1, %esi
callq 0x4ceb
decl %r15d
leaq 0x10(%rsp), %r12
movl %r15d, %edi
movq %r12, %rsi
callq 0x4d5b
movq %r12, %rdi
movl %eax, %esi
callq 0x4ceb
testw %r13w, %r13w
je 0x4500
leaq 0x1f0f(%rip), %rdi      # 0x63b2
movl $0x1, %esi
callq 0x4ceb
jmp 0x44d2
testw %r13w, %r13w
je 0x4500
leaq 0x1ef8(%rip), %rdi      # 0x63b4
movl $0x5, %esi
callq 0x4ceb
movl 0xc(%rsp), %edi
jmp 0x44e9
testw %r13w, %r13w
je 0x4500
leaq 0x1ee3(%rip), %rdi      # 0x63bc
movl $0x1, %esi
callq 0x4ceb
movl 0xc(%rsp), %edi
decl %edi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x4d5b
movq %r15, %rdi
movl %eax, %esi
callq 0x4ceb
leaq 0x1e53(%rip), %rdi      # 0x635a
movl $0x1, %esi
callq 0x4ceb
movw %bp, 0x5368(%rip)       # 0x9880
movw %bx, 0x5363(%rip)       # 0x9882
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq