// File: /workspace/github_c_makefile_star2_O3/neovim[P]libvterm/src/screen.c
// Function: get_chars
static size_t _get_chars(const VTermScreen *screen, const int utf8, void *buffer, size_t len, const VTermRect rect)
{
  size_t outpos = 0;
  int padding = 0;

#define PUT(c)                                             \
  if(utf8) {                                               \
    size_t thislen = utf8_seqlen(c);                       \
    if(buffer && outpos + thislen <= len)                  \
      outpos += fill_utf8((c), (char *)buffer + outpos);   \
    else                                                   \
      outpos += thislen;                                   \
  }                                                        \
  else {                                                   \
    if(buffer && outpos + 1 <= len)                        \
      ((uint32_t*)buffer)[outpos++] = (c);                 \
    else                                                   \
      outpos++;                                            \
  }

  for(int row = rect.start_row; row < rect.end_row; row++) {
    for(int col = rect.start_col; col < rect.end_col; col++) {
      ScreenCell *cell = getcell(screen, row, col);

      if(cell->chars[0] == 0)
        // Erased cell, might need a space
        padding++;
      else if(cell->chars[0] == (uint32_t)-1)
        // Gap behind a double-width char, do nothing
        ;
      else {
        while(padding) {
          PUT(UNICODE_SPACE);
          padding--;
        }
        for(int i = 0; i < VTERM_MAX_CHARS_PER_CELL && cell->chars[i]; i++) {
          PUT(cell->chars[i]);
        }
      }
    }

    if(row < rect.end_row - 1) {
      PUT(UNICODE_LINEFEED);
      padding = 0;
    }
  }

  return outpos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, 0x38(%rsp)
movq %r8, %rax
shrq $0x20, %rax
xorl %ebx, %ebx
movq %r8, (%rsp)
cmpl %eax, %r8d
jge 0x4afd
movq %rcx, %rbp
movl %esi, %r10d
movq %r9, %rsi
shrq $0x20, %rsi
movq %rsi, 0x18(%rsp)
movq %rax, 0x30(%rsp)
decl %eax
movl %eax, 0xc(%rsp)
movl %r9d, %eax
movq %rax, 0x28(%rsp)
leaq (,%rax,4), %rax
leaq (%rax,%rax,8), %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movq %r9, 0x10(%rsp)
movq %rdx, 0x40(%rsp)
movq %rax, %r8
movq 0x20(%rsp), %r11
movq 0x28(%rsp), %rdi
cmpl 0x18(%rsp), %r9d
jge 0x4a98
movq 0x38(%rsp), %rax
movq 0x70(%rax), %r12
movl 0x54(%rax), %eax
imull (%rsp), %eax
leaq (%rax,%rax,8), %rsi
leaq (%r12,%rsi,4), %r14
leaq (%rdi,%rdi,8), %rsi
movl (%r14,%rsi,4), %esi
cmpl $-0x1, %esi
movq %r11, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
je 0x4a7d
testl %esi, %esi
jne 0x4983
incl %ebx
jmp 0x4a7d
testl %ebx, %ebx
je 0x49c0
movq %r8, %r14
testq %rdx, %rdx
sete %dil
incq %r8
cmpq %rbp, %r8
seta %sil
orb %dil, %sil
testl %r10d, %r10d
je 0x49af
testb %sil, %sil
jne 0x49bc
movb $0x20, (%rdx,%r14)
jmp 0x49bc
testb %sil, %sil
jne 0x49bc
movl $0x20, (%rdx,%r14,4)
decl %ebx
jne 0x4987
leaq (%rax,%rax,8), %rax
leaq (%r11,%rax,4), %rax
addq %rax, %r12
xorl %r15d, %r15d
movq %r8, %r13
movl (%r12,%r15,4), %edi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x4a7a
testl %r10d, %r10d
je 0x4a56
movl $0x1, %r8d
cmpl $0x80, %edi
jb 0x4a2d
movl $0x2, %r8d
cmpl $0x800, %edi            # imm = 0x800
jb 0x4a2d
movl $0x3, %r8d
cmpl $0x10000, %edi          # imm = 0x10000
jb 0x4a2d
movl $0x4, %r8d
cmpl $0x200000, %edi         # imm = 0x200000
jb 0x4a2d
cmpl $0x4000000, %edi        # imm = 0x4000000
movl $0x6, %r8d
sbbq $0x0, %r8
addq %r13, %r8
testq %rdx, %rdx
je 0x4a68
cmpq %rbp, %r8
ja 0x4a68
leaq (%rdx,%r13), %rsi
movl %r10d, %r14d
callq 0x5376
movl %r14d, %r10d
movq 0x40(%rsp), %rdx
movl %eax, %r8d
addq %r13, %r8
jmp 0x4a68
leaq 0x1(%r13), %r8
testq %rdx, %rdx
je 0x4a68
cmpq %rbp, %r8
ja 0x4a68
movl %edi, (%rdx,%r13,4)
incq %r15
movq %r8, %r13
cmpq $0x6, %r15
jne 0x49d1
jmp 0x4a7d
movq %r13, %r8
movq 0x48(%rsp), %rdi
incq %rdi
movq 0x50(%rsp), %r11
addq $0x24, %r11
cmpl 0x18(%rsp), %edi
jl 0x4945
movl 0xc(%rsp), %eax
cmpl %eax, (%rsp)
jge 0x4ace
testq %rdx, %rdx
sete %sil
leaq 0x1(%r8), %rax
cmpq %rbp, %rax
seta %dil
orb %sil, %dil
testl %r10d, %r10d
movq 0x10(%rsp), %r9
je 0x4aec
xorl %ebx, %ebx
testb %dil, %dil
jne 0x4ad6
movb $0xa, (%rdx,%r8)
jmp 0x4ad6
movq %r8, %rax
movq 0x10(%rsp), %r9
movq (%rsp), %rsi
incl %esi
movq %rsi, (%rsp)
cmpl 0x30(%rsp), %esi
jne 0x492d
jmp 0x4aff
xorl %ebx, %ebx
testb %dil, %dil
jne 0x4ad6
movl $0xa, (%rdx,%r8,4)
jmp 0x4ad6
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq