// File: /workspace/github_c_makefile_star2_O3/neovim[P]libvterm/bin/unterm.c
// Function: dump_cell
static void dump_cell(const VTermScreenCell *cell, const VTermScreenCell *prevcell)
{
  switch(format) {
    case FORMAT_PLAIN:
      break;
    case FORMAT_SGR:
      {
        // If all 7 attributes change, that means 7 SGRs max
        // Each colour could consume up to 5 entries
        int sgr[7 + 2*5]; int sgri = 0;

        if(!prevcell->attrs.bold && cell->attrs.bold)
          sgr[sgri++] = 1;
        if(prevcell->attrs.bold && !cell->attrs.bold)
          sgr[sgri++] = 22;

        if(!prevcell->attrs.underline && cell->attrs.underline)
          sgr[sgri++] = 4;
        if(prevcell->attrs.underline && !cell->attrs.underline)
          sgr[sgri++] = 24;

        if(!prevcell->attrs.italic && cell->attrs.italic)
          sgr[sgri++] = 3;
        if(prevcell->attrs.italic && !cell->attrs.italic)
          sgr[sgri++] = 23;

        if(!prevcell->attrs.blink && cell->attrs.blink)
          sgr[sgri++] = 5;
        if(prevcell->attrs.blink && !cell->attrs.blink)
          sgr[sgri++] = 25;

        if(!prevcell->attrs.reverse && cell->attrs.reverse)
          sgr[sgri++] = 7;
        if(prevcell->attrs.reverse && !cell->attrs.reverse)
          sgr[sgri++] = 27;

        if(!prevcell->attrs.conceal && cell->attrs.conceal)
          sgr[sgri++] = 8;
        if(prevcell->attrs.conceal && !cell->attrs.conceal)
          sgr[sgri++] = 28;

        if(!prevcell->attrs.strike && cell->attrs.strike)
          sgr[sgri++] = 9;
        if(prevcell->attrs.strike && !cell->attrs.strike)
          sgr[sgri++] = 29;

        if(!prevcell->attrs.font && cell->attrs.font)
          sgr[sgri++] = 10 + cell->attrs.font;
        if(prevcell->attrs.font && !cell->attrs.font)
          sgr[sgri++] = 10;

        if(!vterm_color_is_equal(&prevcell->fg, &cell->fg)) {
          sgri = dump_cell_color(&cell->fg, sgri, sgr, 1);
        }

        if(!vterm_color_is_equal(&prevcell->bg, &cell->bg)) {
          sgri = dump_cell_color(&cell->bg, sgri, sgr, 0);
        }

        if(!sgri)
          break;

        printf("\x1b[");
        for(int i = 0; i < sgri; i++)
          printf(!i               ? "%d" :
              CSI_ARG_HAS_MORE(sgr[i]) ? ":%d" :
              ";%d",
              CSI_ARG(sgr[i]));
        printf("m");
      }
      break;
  }

  for(int i = 0; i < VTERM_MAX_CHARS_PER_CELL && cell->chars[i]; i++) {
    char bytes[6];
    bytes[fill_utf8(cell->chars[i], bytes)] = 0;
    printf("%s", bytes);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
cmpb $0x1, 0x2d7e(%rip)      # 0x4154
jne 0x15b4
movq %rsi, %r14
movl 0x1c(%rsi), %ecx
movl 0x1c(%rbx), %eax
testb $0x1, %cl
jne 0x13f7
testb $0x1, %al
je 0x1409
movl $0x1, (%rsp)
jmp 0x1402
testb $0x1, %al
jne 0x1409
movl $0x16, (%rsp)
movl $0x1, %ebp
jmp 0x140b
xorl %ebp, %ebp
testb $0x6, %cl
je 0x141b
testb $0x6, %al
jne 0x142b
movl $0x18, %edx
jmp 0x1424
movl $0x4, %edx
testb $0x6, %al
je 0x142b
movl %ebp, %esi
incl %ebp
movl %edx, (%rsp,%rsi,4)
testb $0x8, %cl
jne 0x143b
movl $0x3, %edx
testb $0x8, %al
jne 0x1444
jmp 0x144b
movl $0x17, %edx
testb $0x8, %al
jne 0x144b
movl %ebp, %esi
incl %ebp
movl %edx, (%rsp,%rsi,4)
testb $0x10, %cl
jne 0x145b
movl $0x5, %edx
testb $0x10, %al
jne 0x1464
jmp 0x146b
movl $0x19, %edx
testb $0x10, %al
jne 0x146b
movl %ebp, %esi
incl %ebp
movl %edx, (%rsp,%rsi,4)
testb $0x20, %cl
jne 0x147b
movl $0x7, %edx
testb $0x20, %al
jne 0x1484
jmp 0x148b
movl $0x1b, %edx
testb $0x20, %al
jne 0x148b
movl %ebp, %esi
incl %ebp
movl %edx, (%rsp,%rsi,4)
testb $0x40, %cl
jne 0x149b
movl $0x8, %edx
testb $0x40, %al
jne 0x14a4
jmp 0x14ab
movl $0x1c, %edx
testb $0x40, %al
jne 0x14ab
movl %ebp, %esi
incl %ebp
movl %edx, (%rsp,%rsi,4)
testb %cl, %cl
js 0x14ba
movl $0x9, %edx
testb %al, %al
js 0x14c3
jmp 0x14ca
movl $0x1d, %edx
testb %al, %al
js 0x14ca
movl %ebp, %esi
incl %ebp
movl %edx, (%rsp,%rsi,4)
testl $0xf00, %ecx            # imm = 0xF00
je 0x14e0
testl $0xf00, %eax            # imm = 0xF00
jne 0x14f2
movl $0xa, %eax
jmp 0x14eb
shrl $0x8, %eax
andl $0xf, %eax
je 0x14f2
addl $0xa, %eax
movl %ebp, %ecx
incl %ebp
movl %eax, (%rsp,%rcx,4)
leaq 0x20(%r14), %rdi
leaq 0x20(%rbx), %r15
movq %r15, %rsi
callq 0x1080
testl %eax, %eax
jne 0x151a
movq %rsp, %rdx
movq %r15, %rdi
movl %ebp, %esi
movl $0x1, %ecx
callq 0x18e2
movl %eax, %ebp
addq $0x24, %r14
leaq 0x24(%rbx), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1080
testl %eax, %eax
jne 0x1542
movq %rsp, %rdx
movq %r15, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
callq 0x18e2
movl %eax, %ebp
testl %ebp, %ebp
je 0x15b4
movq %rbx, 0x50(%rsp)
leaq 0xb06(%rip), %rdi       # 0x2058
xorl %eax, %eax
callq 0x1090
testl %ebp, %ebp
jle 0x15a5
movl %ebp, %r14d
movl (%rsp), %ebp
leaq 0xaf2(%rip), %r15       # 0x205c
leaq 0xaee(%rip), %r12       # 0x205f
leaq 0xae3(%rip), %r13       # 0x205b
xorl %ebx, %ebx
movl %ebp, %esi
movq %r15, %rdi
testq %rbx, %rbx
je 0x1590
movl (%rsp,%rbx,4), %esi
testl %esi, %esi
movq %r13, %rdi
cmovnsq %r12, %rdi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
xorl %eax, %eax
callq 0x1090
incq %rbx
cmpq %rbx, %r14
jne 0x157a
movl $0x6d, %edi
callq 0x1040
movq 0x50(%rsp), %rbx
leaq 0x1(%rsp), %rbp
leaq 0xaa3(%rip), %r14       # 0x2063
movq %rsp, %r15
leaq 0xa3a(%rip), %r12       # 0x2004
xorl %r13d, %r13d
movl (%rbx,%r13,4), %eax
testq %rax, %rax
je 0x16a9
cmpl $0x80, %eax
jae 0x1605
movq %rbp, %rcx
movb %al, (%rsp)
movb $0x0, (%rcx)
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1090
incq %r13
cmpq $0x6, %r13
jne 0x15cd
jmp 0x16a9
movl $0x2, %ecx
cmpl $0x800, %eax            # imm = 0x800
jb 0x1636
movl $0x3, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
jb 0x1636
movl $0x4, %ecx
cmpl $0x200000, %eax         # imm = 0x200000
jb 0x1636
cmpl $0x4000000, %eax        # imm = 0x4000000
movl $0x6, %ecx
sbbl $0x0, %ecx
movl %ecx, %edx
incq %rdx
movl %eax, %esi
andb $0x3f, %sil
orb $-0x80, %sil
movb %sil, -0x2(%rsp,%rdx)
shrq $0x6, %rax
decq %rdx
cmpq $0x2, %rdx
ja 0x163b
addl $-0x2, %ecx
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
andb $0x1f, %al
orb $-0x40, %al
leaq 0x2(%rsp), %rcx
jmp 0x15e4
andb $0x1, %al
orb $-0x4, %al
leaq 0x6(%rsp), %rcx
jmp 0x15e4
andb $0x7, %al
orb $-0x10, %al
leaq 0x4(%rsp), %rcx
jmp 0x15e4
andb $0x3, %al
orb $-0x8, %al
leaq 0x5(%rsp), %rcx
jmp 0x15e4
andb $0xf, %al
orb $-0x20, %al
leaq 0x3(%rsp), %rcx
jmp 0x15e4
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq