// File: /workspace/github_c_makefile_star2_O1/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 0x47e4
movq %rcx, %rbp
movl %esi, %r15d
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), %rdi
movq 0x28(%rsp), %r11
cmpl 0x18(%rsp), %r9d
jge 0x477a
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 (%r11,%r11,8), %rsi
movl (%r14,%rsi,4), %esi
cmpl $-0x1, %esi
movq %rdi, 0x50(%rsp)
movq %r11, 0x48(%rsp)
je 0x475e
testl %esi, %esi
jne 0x465b
incl %ebx
jmp 0x475e
testl %ebx, %ebx
je 0x469e
testl %r15d, %r15d
je 0x4679
leaq 0x1(%r8), %rsi
testq %rdx, %rdx
je 0x4697
cmpq %rbp, %rsi
ja 0x4697
movb $0x20, (%rdx,%r8)
jmp 0x4697
testq %rdx, %rdx
je 0x4687
leaq 0x1(%r8), %rsi
cmpq %rbp, %rsi
jbe 0x468f
incq %r8
movq %r8, %rsi
jmp 0x4697
movl $0x20, (%rdx,%r8,4)
movq %rsi, %r8
decl %ebx
jne 0x465f
leaq (%rax,%rax,8), %rax
leaq (%rdi,%rax,4), %rax
addq %rax, %r12
xorl %r14d, %r14d
movq %r8, %r13
movl (%r12,%r14,4), %edi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x475b
testl %r15d, %r15d
je 0x472f
movl $0x1, %r8d
cmpl $0x80, %edi
jb 0x470b
movl $0x2, %r8d
cmpl $0x800, %edi            # imm = 0x800
jb 0x470b
movl $0x3, %r8d
cmpl $0x10000, %edi          # imm = 0x10000
jb 0x470b
movl $0x4, %r8d
cmpl $0x200000, %edi         # imm = 0x200000
jb 0x470b
cmpl $0x4000000, %edi        # imm = 0x4000000
movl $0x6, %r8d
sbbq $0x0, %r8
testq %rdx, %rdx
je 0x472a
leaq (%r8,%r13), %rax
cmpq %rbp, %rax
ja 0x472a
leaq (%rdx,%r13), %rsi
callq 0x502f
movq 0x40(%rsp), %rdx
movl %eax, %r8d
addq %r13, %r8
jmp 0x4749
testq %rdx, %rdx
je 0x473d
leaq 0x1(%r13), %r8
cmpq %rbp, %r8
jbe 0x4745
incq %r13
movq %r13, %r8
jmp 0x4749
movl %edi, (%rdx,%r13,4)
incq %r14
movq %r8, %r13
cmpq $0x6, %r14
jne 0x46af
jmp 0x475e
movq %r13, %r8
movq 0x48(%rsp), %r11
incq %r11
movq 0x50(%rsp), %rdi
addq $0x24, %rdi
cmpl 0x18(%rsp), %r11d
jl 0x461d
movl 0xc(%rsp), %eax
cmpl %eax, (%rsp)
jge 0x47a2
testl %r15d, %r15d
movq 0x10(%rsp), %r9
je 0x47ac
leaq 0x1(%r8), %rax
testq %rdx, %rdx
je 0x47cc
cmpq %rbp, %rax
ja 0x47cc
movb $0xa, (%rdx,%r8)
jmp 0x47cc
movq %r8, %rax
movq 0x10(%rsp), %r9
jmp 0x47ce
testq %rdx, %rdx
je 0x47ba
leaq 0x1(%r8), %rax
cmpq %rbp, %rax
jbe 0x47c4
incq %r8
xorl %ebx, %ebx
movq %r8, %rax
jmp 0x47ce
movl $0xa, (%rdx,%r8,4)
xorl %ebx, %ebx
movq (%rsp), %rsi
incl %esi
movq %rsi, (%rsp)
cmpl 0x30(%rsp), %esi
jne 0x4605
jmp 0x47e6
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq