// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movl %esi, 0x4(%rsp)
movq %rdi, 0x30(%rsp)
movq %r8, %rax
shrq $0x20, %rax
movq %r9, 0x20(%rsp)
shrq $0x20, %r9
movq %r9, 0x38(%rsp)
movq %rax, 0x28(%rsp)
decl %eax
movl %eax, 0x14(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %rcx, 0x8(%rsp)
cmpl 0x28(%rsp), %r14d
jge 0x4144
movq 0x20(%rsp), %rax
movl %eax, %edx
movq %r14, 0x18(%rsp)
cmpl 0x38(%rsp), %edx
jge 0x40ed
movq 0x30(%rsp), %rdi
movl %r14d, %esi
movl %edx, %ebp
callq 0x42cb
movq %rax, 0x40(%rsp)
movl (%rax), %eax
cmpl $-0x1, %eax
je 0x4019
testl %eax, %eax
jne 0x4020
incl %ebx
movl %ebp, %edx
jmp 0x40e6
movl %ebp, %edx
subl $0x1, %ebx
jb 0x406c
testq %r12, %r12
sete %sil
leaq 0x1(%r13), %rax
cmpq %r15, %rax
seta %cl
orb %sil, %cl
cmpl $0x0, 0x4(%rsp)
je 0x405b
testb %cl, %cl
jne 0x4067
leaq (%r12,%r13), %rsi
pushq $0x20
popq %rdi
callq 0x48e1
movl %ebp, %edx
movl %eax, %eax
addq %r13, %rax
jmp 0x4067
testb %cl, %cl
jne 0x4067
movl $0x20, (%r12,%r13,4)
movq %rax, %r13
jmp 0x4022
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpq $0x6, %r15
je 0x40dc
movq 0x40(%rsp), %rax
movl (%rax,%r15,4), %r14d
testq %r14, %r14
je 0x40dc
cmpl $0x0, 0x4(%rsp)
je 0x40bc
movq %r14, %rdi
callq 0x489f
movl %eax, %eax
addq %r13, %rax
testq %r12, %r12
je 0x40d2
cmpq 0x8(%rsp), %rax
movl %ebp, %edx
ja 0x40d4
leaq (%r12,%r13), %rsi
movq %r14, %rdi
callq 0x48e1
movl %ebp, %edx
movl %eax, %eax
addq %r13, %rax
jmp 0x40d4
leaq 0x1(%r13), %rax
testq %r12, %r12
je 0x40d4
cmpq 0x8(%rsp), %rax
ja 0x40d4
movl %r14d, (%r12,%r13,4)
jmp 0x40d4
movl %ebp, %edx
incq %r15
movq %rax, %r13
jmp 0x406f
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %r15
incl %edx
jmp 0x3fee
cmpl 0x14(%rsp), %r14d
jge 0x4126
testq %r12, %r12
sete %dl
leaq 0x1(%r13), %rax
cmpq %r15, %rax
seta %cl
orb %dl, %cl
cmpl $0x0, 0x4(%rsp)
je 0x4134
xorl %ebx, %ebx
testb %cl, %cl
jne 0x4129
leaq (%r12,%r13), %rsi
pushq $0xa
popq %rdi
callq 0x48e1
movl %eax, %eax
addq %r13, %rax
jmp 0x4129
movq %r13, %rax
incl %r14d
movq %rax, %r13
jmp 0x3fd7
xorl %ebx, %ebx
testb %cl, %cl
jne 0x4129
movl $0xa, (%r12,%r13,4)
jmp 0x4129
movq %r13, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq