// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/state.c
// Function: vterm_state_send_selection
void vterm_state_send_selection(VTermState *state, VTermSelectionMask mask, VTermStringFragment frag)
{
  VTerm *vt = state->vt;

  if(frag.initial) {
    /* TODO: support sending more than one mask bit */
    const static char selection_chars[] = "cpqs";
    int idx;
    for(idx = 0; idx < 4; idx++)
      if(mask & (1 << idx))
        break;

    vterm_push_output_sprintf_str(vt, C1_OSC, false, "52;%c;", selection_chars[idx]);

    state->tmp.selection.sendpartial = 0;
  }

  if(frag.len) {
    size_t bufcur = 0;
    char *buffer = state->selection.buffer;

    uint32_t x = 0;
    int n = 0;

    if(state->tmp.selection.sendpartial) {
      n = state->tmp.selection.sendpartial >> 24;
      x = state->tmp.selection.sendpartial & 0xFFFFFF;

      state->tmp.selection.sendpartial = 0;
    }

    while((state->selection.buflen - bufcur) >= 4 && frag.len) {
      x = (x << 8) | frag.str[0];
      n++;
      frag.str++, frag.len--;

      if(n == 3) {
        buffer[0] = base64_one((x >> 18) & 0x3F);
        buffer[1] = base64_one((x >> 12) & 0x3F);
        buffer[2] = base64_one((x >>  6) & 0x3F);
        buffer[3] = base64_one((x >>  0) & 0x3F);

        buffer += 4, bufcur += 4;
        x = 0;
        n = 0;
      }

      if(!frag.len || (state->selection.buflen - bufcur) < 4) {
        if(bufcur)
          vterm_push_output_bytes(vt, state->selection.buffer, bufcur);

        buffer = state->selection.buffer;
        bufcur = 0;
      }
    }

    if(n)
      state->tmp.selection.sendpartial = (n << 24) | x;
  }

  if(frag.final) {
    if(state->tmp.selection.sendpartial) {
      int n      = state->tmp.selection.sendpartial >> 24;
      uint32_t x = state->tmp.selection.sendpartial & 0xFFFFFF;
      char *buffer = state->selection.buffer;

      /* n is either 1 or 2 now */
      x <<= (n == 1) ? 16 : 8;

      buffer[0] = base64_one((x >> 18) & 0x3F);
      buffer[1] = base64_one((x >> 12) & 0x3F);
      buffer[2] = (n == 1) ? '=' : base64_one((x >>  6) & 0x3F);
      buffer[3] = '=';

      vterm_push_output_sprintf_str(vt, 0, true, "%.*s", 4, buffer);
    }
    else
      vterm_push_output_sprintf_str(vt, 0, true, "");
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdx, -0x10(%rbp)
movq %rcx, -0x8(%rbp)
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x8(%rbp), %eax
shrl $0x1e, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0xab7b
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jge 0xab44
movl -0x1c(%rbp), %eax
movl -0x2c(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xab37
jmp 0xab44
jmp 0xab39
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xab19
movq -0x28(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq 0x8d5d(%rip), %rax      # 0x138b0
movsbl (%rax,%rcx), %r8d
movl $0x9d, %esi
xorl %edx, %edx
leaq 0x8d53(%rip), %rcx      # 0x138b9
movb $0x0, %al
callq 0x11f90
movq -0x18(%rbp), %rax
movl $0x0, 0x1b0(%rax)
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpq $0x0, %rax
je 0xad88
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x1c8(%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1b0(%rax)
je 0xabf1
movq -0x18(%rbp), %rax
movl 0x1b0(%rax), %eax
shrl $0x18, %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x1b0(%rax), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x1b0(%rax)
jmp 0xabf3
movq -0x18(%rbp), %rax
movq 0x1d0(%rax), %rcx
subq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq $0x4, %rcx
movb %al, -0x59(%rbp)
jb 0xac20
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0xac2c
jmp 0xad6d
movl -0x44(%rbp), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movsbl (%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
addq $-0x1, %rax
movl %eax, %ecx
movl -0x8(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0x8(%rbp)
cmpl $0x3, -0x48(%rbp)
jne 0xad0d
movl -0x44(%rbp), %eax
shrl $0x12, %eax
andl $0x3f, %eax
movzbl %al, %edi
callq 0xaeb0
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movl -0x44(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
movzbl %al, %edi
callq 0xaeb0
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x44(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
movzbl %al, %edi
callq 0xaeb0
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x44(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
movzbl %al, %edi
callq 0xaeb0
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpq $0x0, %rax
je 0xad32
movq -0x18(%rbp), %rax
movq 0x1d0(%rax), %rax
subq -0x38(%rbp), %rax
cmpq $0x4, %rax
jae 0xad68
cmpq $0x0, -0x38(%rbp)
je 0xad51
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x1c8(%rax), %rsi
movq -0x38(%rbp), %rdx
callq 0x11c50
movq -0x18(%rbp), %rax
movq 0x1c8(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0xabf3
cmpl $0x0, -0x48(%rbp)
je 0xad86
movl -0x48(%rbp), %ecx
shll $0x18, %ecx
orl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1b0(%rax)
jmp 0xad88
movl -0x8(%rbp), %eax
shrl $0x1f, %eax
testl $0x1, %eax
je 0xaea4
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1b0(%rax)
je 0xae89
movq -0x18(%rbp), %rax
movl 0x1b0(%rax), %eax
shrl $0x18, %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movl 0x1b0(%rax), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x1c8(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x4c(%rbp), %edx
movl $0x8, %ecx
movl $0x10, %eax
cmpl $0x1, %edx
cmovel %eax, %ecx
movl -0x50(%rbp), %eax
shll %cl, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
shrl $0x12, %eax
andl $0x3f, %eax
movzbl %al, %edi
callq 0xaeb0
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, (%rax)
movl -0x50(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
movzbl %al, %edi
callq 0xaeb0
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, 0x1(%rax)
cmpl $0x1, -0x4c(%rbp)
jne 0xae39
movl $0x3d, %eax
movl %eax, -0x60(%rbp)
jmp 0xae50
movl -0x50(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
movzbl %al, %edi
callq 0xaeb0
movsbl %al, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x58(%rbp), %rax
movb $0x3d, 0x3(%rax)
movq -0x28(%rbp), %rdi
movq -0x58(%rbp), %r9
xorl %esi, %esi
movl $0x1, %edx
leaq 0x8a46(%rip), %rcx      # 0x138c0
movl $0x4, %r8d
movb $0x0, %al
callq 0x11f90
jmp 0xaea2
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
leaq 0x8303(%rip), %rcx      # 0x1319e
movb $0x0, %al
callq 0x11f90
jmp 0xaea4
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)