// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %r14
movq (%rdi), %rax
movq %rax, (%rsp)
btl $0x1e, %r15d
jae 0x6e0e
xorl %eax, %eax
btl %eax, %esi
jb 0x6ddc
incl %eax
cmpl $0x4, %eax
jne 0x6dcb
movl $0x4, %eax
movl %eax, %eax
leaq 0x4b7b(%rip), %rcx      # 0xb960
movsbl (%rax,%rcx), %r8d
leaq 0x4b74(%rip), %rcx      # 0xb965
movq (%rsp), %rdi
movl $0x9d, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xa755
movl $0x0, 0x1b0(%r14)
movq %r15, %rax
shlq $0x22, %rax
je 0x6ff1
movl 0x1b0(%r14), %ebp
testl %ebp, %ebp
je 0x6e40
movl %ebp, %r13d
shrl $0x18, %r13d
andl $0xffffff, %ebp         # imm = 0xFFFFFF
movl $0x0, 0x1b0(%r14)
jmp 0x6e45
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq $0x4, 0x1d0(%r14)
setb %al
testl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
sete %cl
orb %al, %cl
jne 0x6fde
movq 0x1c8(%r14), %rax
xorl %edx, %edx
shll $0x8, %ebp
movsbl (%r12), %ecx
orl %ecx, %ebp
incl %r13d
cmpl $0x3, %r13d
jne 0x6f7f
movl %ebp, %esi
shrl $0x12, %esi
andb $0x3f, %sil
cmpb $0x19, %sil
ja 0x6e97
addb $0x41, %sil
jmp 0x6ebf
cmpb $0x33, %sil
ja 0x6ea3
addb $0x47, %sil
jmp 0x6ebf
cmpb $0x3d, %sil
ja 0x6eaf
addb $-0x4, %sil
jmp 0x6ebf
cmpb $0x3e, %sil
setne %sil
shlb $0x2, %sil
orb $0x2b, %sil
movb %sil, (%rax)
movl %ebp, %esi
shrl $0xc, %esi
andb $0x3f, %sil
cmpb $0x19, %sil
ja 0x6ed7
addb $0x41, %sil
jmp 0x6eff
cmpb $0x33, %sil
ja 0x6ee3
addb $0x47, %sil
jmp 0x6eff
cmpb $0x3d, %sil
ja 0x6eef
addb $-0x4, %sil
jmp 0x6eff
cmpb $0x3e, %sil
setne %sil
shlb $0x2, %sil
orb $0x2b, %sil
movb %sil, 0x1(%rax)
shrl $0x6, %ebp
andb $0x3f, %bpl
cmpb $0x19, %bpl
ja 0x6f16
addb $0x41, %bpl
jmp 0x6f3e
cmpb $0x33, %bpl
ja 0x6f22
addb $0x47, %bpl
jmp 0x6f3e
cmpb $0x3d, %bpl
ja 0x6f2e
addb $-0x4, %bpl
jmp 0x6f3e
cmpb $0x3e, %bpl
setne %bpl
shlb $0x2, %bpl
orb $0x2b, %bpl
movb %bpl, 0x2(%rax)
andb $0x3f, %cl
cmpb $0x19, %cl
ja 0x6f4f
addb $0x41, %cl
jmp 0x6f6f
cmpb $0x33, %cl
ja 0x6f59
addb $0x47, %cl
jmp 0x6f6f
cmpb $0x3d, %cl
ja 0x6f63
addb $-0x4, %cl
jmp 0x6f6f
cmpb $0x3e, %cl
setne %cl
shlb $0x2, %cl
orb $0x2b, %cl
movb %cl, 0x3(%rax)
addq $0x4, %rax
addq $0x4, %rdx
xorl %ebp, %ebp
xorl %r13d, %r13d
leal -0x1(%r15), %ebx
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
je 0x6f9b
movq 0x1d0(%r14), %rcx
subq %rdx, %rcx
cmpq $0x3, %rcx
ja 0x6fb9
testq %rdx, %rdx
je 0x6fb0
movq 0x1c8(%r14), %rsi
movq (%rsp), %rdi
callq 0xa493
movq 0x1c8(%r14), %rax
xorl %edx, %edx
andl $0xc0000000, %r15d      # imm = 0xC0000000
orl %ebx, %r15d
movq 0x1d0(%r14), %rcx
subq %rdx, %rcx
cmpq $0x4, %rcx
jb 0x6fde
incq %r12
testl %ebx, %ebx
jne 0x6e6b
testl %r13d, %r13d
je 0x6ff1
shll $0x18, %r13d
orl %ebp, %r13d
movl %r13d, 0x1b0(%r14)
testl %r15d, %r15d
js 0x7005
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x1b0(%r14), %edx
testl %edx, %edx
je 0x7047
movl %edx, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movq 0x1c8(%r14), %r9
andl $0xff000000, %edx       # imm = 0xFF000000
cmpl $0x1000000, %edx        # imm = 0x1000000
sete %cl
shlb $0x3, %cl
addb $0x8, %cl
shll %cl, %eax
movl %eax, %ecx
shrl $0x12, %ecx
andb $0x3f, %cl
cmpb $0x19, %cl
ja 0x706e
addb $0x41, %cl
jmp 0x708e
leaq 0x4260(%rip), %rcx      # 0xb2ae
movq (%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa755
cmpb $0x33, %cl
ja 0x7078
addb $0x47, %cl
jmp 0x708e
cmpb $0x3d, %cl
ja 0x7082
addb $-0x4, %cl
jmp 0x708e
cmpb $0x3e, %cl
setne %cl
shlb $0x2, %cl
orb $0x2b, %cl
movb %cl, (%r9)
movl %eax, %ecx
shrl $0xc, %ecx
andb $0x3f, %cl
cmpb $0x19, %cl
ja 0x70a3
addb $0x41, %cl
jmp 0x70c3
cmpb $0x33, %cl
ja 0x70ad
addb $0x47, %cl
jmp 0x70c3
cmpb $0x3d, %cl
ja 0x70b7
addb $-0x4, %cl
jmp 0x70c3
cmpb $0x3e, %cl
setne %cl
shlb $0x2, %cl
orb $0x2b, %cl
movb %cl, 0x1(%r9)
movb $0x3d, %cl
cmpl $0x1000000, %edx        # imm = 0x1000000
je 0x70ea
shrl $0x6, %eax
andb $0x3c, %al
cmpb $0x19, %al
ja 0x70de
orb $0x41, %al
jmp 0x70e8
cmpb $0x33, %al
ja 0x70e6
addb $0x47, %al
jmp 0x70e8
addb $-0x4, %al
movl %eax, %ecx
movb %cl, 0x2(%r9)
movb $0x3d, 0x3(%r9)
leaq 0x4872(%rip), %rcx      # 0xb96c
movq (%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x4, %r8d
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa755