// File: /workspace/github_c_makefile_star2_O2/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, 0x2de8(%rip)      # 0x4154
jne 0x153b
movq %rsi, %r15
movl 0x1c(%rsi), %ecx
movl 0x1c(%rbx), %eax
testb $0x1, %cl
jne 0x138d
testb $0x1, %al
je 0x139e
movl $0x1, (%rsp)
jmp 0x1398
testb $0x1, %al
jne 0x139e
movl $0x16, (%rsp)
pushq $0x1
popq %r14
jmp 0x13a1
xorl %r14d, %r14d
testb $0x6, %cl
je 0x13ae
testb $0x6, %al
jne 0x13be
pushq $0x18
jmp 0x13b4
testb $0x6, %al
je 0x13be
pushq $0x4
popq %rdx
movl %r14d, %esi
incl %r14d
movl %edx, (%rsp,%rsi,4)
testb $0x8, %cl
jne 0x13cb
testb $0x8, %al
je 0x13db
pushq $0x3
jmp 0x13d1
testb $0x8, %al
jne 0x13db
pushq $0x17
popq %rdx
movl %r14d, %esi
incl %r14d
movl %edx, (%rsp,%rsi,4)
testb $0x10, %cl
jne 0x13e8
testb $0x10, %al
je 0x13f8
pushq $0x5
jmp 0x13ee
testb $0x10, %al
jne 0x13f8
pushq $0x19
popq %rdx
movl %r14d, %esi
incl %r14d
movl %edx, (%rsp,%rsi,4)
testb $0x20, %cl
jne 0x1405
testb $0x20, %al
je 0x1415
pushq $0x7
jmp 0x140b
testb $0x20, %al
jne 0x1415
pushq $0x1b
popq %rdx
movl %r14d, %esi
incl %r14d
movl %edx, (%rsp,%rsi,4)
testb $0x40, %cl
jne 0x1422
testb $0x40, %al
je 0x1432
pushq $0x8
jmp 0x1428
testb $0x40, %al
jne 0x1432
pushq $0x1c
popq %rdx
movl %r14d, %esi
incl %r14d
movl %edx, (%rsp,%rsi,4)
testb %cl, %cl
js 0x143e
testb %al, %al
jns 0x144e
pushq $0x9
jmp 0x1444
testb %al, %al
js 0x144e
pushq $0x1d
popq %rdx
movl %r14d, %esi
incl %r14d
movl %edx, (%rsp,%rsi,4)
testw $0xf00, %cx             # imm = 0xF00
je 0x1460
testw $0xf00, %ax             # imm = 0xF00
jne 0x1474
pushq $0xa
popq %rax
jmp 0x146b
shrl $0x8, %eax
andl $0xf, %eax
je 0x1474
addl $0xa, %eax
movl %r14d, %ecx
incl %r14d
movl %eax, (%rsp,%rcx,4)
leaq 0x20(%r15), %rdi
leaq 0x20(%rbx), %r12
movq %r12, %rsi
callq 0x1080
testl %eax, %eax
jne 0x149c
movq %rsp, %rdx
pushq $0x1
popq %rcx
movq %r12, %rdi
movl %r14d, %esi
callq 0x1857
movl %eax, %r14d
addq $0x24, %r15
leaq 0x24(%rbx), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x1080
testl %eax, %eax
jne 0x14c6
movq %rsp, %rdx
movq %r12, %rdi
movl %r14d, %esi
xorl %ecx, %ecx
callq 0x1857
movl %eax, %r14d
testl %r14d, %r14d
je 0x153b
movq %rbx, 0x50(%rsp)
leaq 0xb85(%rip), %rdi       # 0x205c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1090
testl %r14d, %r14d
cmovlel %ebx, %r14d
movl (%rsp), %ebp
leaq 0xb6f(%rip), %r15       # 0x2060
leaq 0xb6b(%rip), %r12       # 0x2063
leaq 0xb60(%rip), %r13       # 0x205f
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x152e
movl %ebp, %esi
movq %r15, %rdi
testq %rbx, %rbx
je 0x151c
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
jmp 0x1501
pushq $0x6d
popq %rdi
callq 0x1040
movq 0x50(%rsp), %rbx
pushq $0x1
popq %rbp
leaq 0xabf(%rip), %r13       # 0x2004
leaq 0xb1b(%rip), %r14       # 0x2067
movq %rsp, %r15
xorl %r12d, %r12d
cmpq $0x6, %r12
je 0x1607
movl (%rbx,%r12,4), %eax
testq %rax, %rax
je 0x1607
movl %ebp, %ecx
cmpl $0x80, %eax
jb 0x159b
pushq $0x2
popq %rcx
cmpl $0x800, %eax            # imm = 0x800
jb 0x159b
pushq $0x3
popq %rcx
cmpl $0x10000, %eax          # imm = 0x10000
jb 0x159b
pushq $0x4
popq %rcx
cmpl $0x200000, %eax         # imm = 0x200000
jb 0x159b
cmpl $0x4000000, %eax        # imm = 0x4000000
pushq $0x6
popq %rcx
sbbl $0x0, %ecx
movl %ecx, %ecx
movq %rcx, %rdx
cmpq $0x2, %rdx
jl 0x15be
movl %eax, %esi
andb $0x3f, %sil
orb $-0x80, %sil
movb %sil, -0x1(%rsp,%rdx)
decq %rdx
shrq $0x6, %rax
jmp 0x15a0
leal -0x1(%rcx), %edx
movslq (%r13,%rdx,4), %rdx
addq %r13, %rdx
jmpq *%rdx
andb $0x7f, %al
jmp 0x15eb
andb $0x3, %al
orb $-0x8, %al
jmp 0x15eb
andb $0xf, %al
orb $-0x20, %al
jmp 0x15eb
andb $0x7, %al
orb $-0x10, %al
jmp 0x15eb
andb $0x1f, %al
orb $-0x40, %al
jmp 0x15eb
andb $0x1, %al
orb $-0x4, %al
movb %al, (%rsp)
movb $0x0, (%rsp,%rcx)
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1090
incq %r12
jmp 0x1552
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq