// File: /workspace/github_c_makefile_star2_O1/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, 0x55ad(%rip)       # 0x9880
jne 0x42e2
cmpw %bx, 0x55a6(%rip)       # 0x9882
je 0x456f
movq 0x560f(%rip), %rax      # 0x98f8
movq 0x28(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4d36
movl 0x4e57(%rip), %eax      # 0x915c
cmpl $0x4, %eax
je 0x4355
cmpl $0x3, %eax
je 0x4325
cmpl $0x2, %eax
jne 0x4386
movl $0xff, %r13d
movl %ebp, %r12d
andl %r13d, %r12d
andl %ebx, %r13d
jmp 0x4394
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 0x4394
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 0x4394
movl %ebp, %r12d
andl $0xf, %r12d
movl %ebx, %r13d
andl $0xf, %r13d
btl $0x8, %ebp
jae 0x43b7
movq 0x5557(%rip), %rax      # 0x98f8
movq 0x38(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4d36
movzwl %bx, %r15d
btl $0x8, %r15d
jae 0x43df
movq 0x552f(%rip), %rax      # 0x98f8
movq 0x40(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4d36
btl $0x9, %ebp
jae 0x4402
movq 0x550c(%rip), %rax      # 0x98f8
movq 0x30(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4d36
orl %ebp, %r15d
btl $0xa, %r15d
jae 0x4429
movq 0x54e5(%rip), %rax      # 0x98f8
movq 0x48(%rax), %r14
movq %r14, %rdi
callq 0x30c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4d36
movl %r13d, %eax
orw %r12w, %ax
je 0x4561
movzwl %r12w, %r15d
movzwl %r13w, %eax
movl %eax, 0xc(%rsp)
movl 0x4d13(%rip), %r14d     # 0x915c
addl $-0x2, %r14d
leaq 0x1f14(%rip), %rdi      # 0x6368
movl $0x2, %esi
callq 0x4d36
cmpl $0x2, %r14d
ja 0x44d1
testw %r12w, %r12w
je 0x44b0
leaq 0x1f3d(%rip), %rdi      # 0x63ae
movl $0x5, %esi
callq 0x4d36
leaq 0x10(%rsp), %r12
movl %r15d, %edi
movq %r12, %rsi
callq 0x4da4
movq %r12, %rdi
movl %eax, %esi
callq 0x4d36
testw %r13w, %r13w
je 0x4550
leaq 0x1f0c(%rip), %rdi      # 0x63b2
movl $0x1, %esi
callq 0x4d36
testw %r13w, %r13w
je 0x4550
leaq 0x1ef3(%rip), %rdi      # 0x63b4
movl $0x5, %esi
callq 0x4d36
movl 0xc(%rsp), %edi
jmp 0x4539
testw %r12w, %r12w
je 0x451c
leaq 0x1edc(%rip), %rdi      # 0x63ba
movl $0x1, %esi
callq 0x4d36
decl %r15d
leaq 0x10(%rsp), %r12
movl %r15d, %edi
movq %r12, %rsi
callq 0x4da4
movq %r12, %rdi
movl %eax, %esi
callq 0x4d36
testw %r13w, %r13w
je 0x4550
leaq 0x1ea0(%rip), %rdi      # 0x63b2
movl $0x1, %esi
callq 0x4d36
testw %r13w, %r13w
je 0x4550
leaq 0x1e93(%rip), %rdi      # 0x63bc
movl $0x1, %esi
callq 0x4d36
movl 0xc(%rsp), %edi
decl %edi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x4da4
movq %r15, %rdi
movl %eax, %esi
callq 0x4d36
leaq 0x1e03(%rip), %rdi      # 0x635a
movl $0x1, %esi
callq 0x4d36
movw %bp, 0x5318(%rip)       # 0x9880
movw %bx, 0x5313(%rip)       # 0x9882
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq