// File: /workspace/github_c_makefile_star2_O3/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 0x7758
xorl %eax, %eax
btl %eax, %esi
jb 0x7726
incl %eax
cmpl $0x4, %eax
jne 0x7715
movl $0x4, %eax
movl %eax, %eax
leaq 0x52c1(%rip), %rcx      # 0xc9f0
movsbl (%rax,%rcx), %r8d
leaq 0x52ba(%rip), %rcx      # 0xc9f5
movq (%rsp), %rdi
movl $0x9d, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xb06f
movl $0x0, 0x1b0(%r14)
movq %r15, %rax
shlq $0x22, %rax
je 0x791d
movl 0x1b0(%r14), %ebp
testl %ebp, %ebp
je 0x778a
movl %ebp, %r13d
shrl $0x18, %r13d
andl $0xffffff, %ebp         # imm = 0xFFFFFF
movl $0x0, 0x1b0(%r14)
jmp 0x778f
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq $0x4, 0x1d0(%r14)
setb %al
testl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
sete %cl
orb %al, %cl
jne 0x790a
movq 0x1c8(%r14), %rsi
xorl %edx, %edx
shll $0x8, %ebp
movsbl (%r12), %eax
orl %eax, %ebp
incl %r13d
cmpl $0x3, %r13d
jne 0x78a8
movl %ebp, %ecx
shrl $0x12, %ecx
andb $0x3f, %cl
cmpb $0x19, %cl
ja 0x77de
addb $0x41, %cl
jmp 0x77fe
cmpb $0x33, %cl
ja 0x77e8
addb $0x47, %cl
jmp 0x77fe
cmpb $0x3d, %cl
ja 0x77f2
addb $-0x4, %cl
jmp 0x77fe
cmpb $0x3e, %cl
setne %cl
shlb $0x2, %cl
orb $0x2b, %cl
movb %cl, (%rsi)
movl %ebp, %ecx
shrl $0xc, %ecx
andb $0x3f, %cl
cmpb $0x19, %cl
ja 0x7812
addb $0x41, %cl
jmp 0x7832
cmpb $0x33, %cl
ja 0x781c
addb $0x47, %cl
jmp 0x7832
cmpb $0x3d, %cl
ja 0x7826
addb $-0x4, %cl
jmp 0x7832
cmpb $0x3e, %cl
setne %cl
shlb $0x2, %cl
orb $0x2b, %cl
movb %cl, 0x1(%rsi)
shrl $0x6, %ebp
andb $0x3f, %bpl
cmpb $0x19, %bpl
ja 0x7848
addb $0x41, %bpl
jmp 0x7870
cmpb $0x33, %bpl
ja 0x7854
addb $0x47, %bpl
jmp 0x7870
cmpb $0x3d, %bpl
ja 0x7860
addb $-0x4, %bpl
jmp 0x7870
cmpb $0x3e, %bpl
setne %bpl
shlb $0x2, %bpl
orb $0x2b, %bpl
movb %bpl, 0x2(%rsi)
andb $0x3f, %al
cmpb $0x19, %al
ja 0x787e
addb $0x41, %al
jmp 0x7898
cmpb $0x33, %al
ja 0x7886
addb $0x47, %al
jmp 0x7898
cmpb $0x3d, %al
ja 0x788e
addb $-0x4, %al
jmp 0x7898
cmpb $0x3e, %al
setne %al
shlb $0x2, %al
orb $0x2b, %al
movb %al, 0x3(%rsi)
addq $0x4, %rsi
addq $0x4, %rdx
xorl %ebp, %ebp
xorl %r13d, %r13d
leal -0x1(%r15), %ebx
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
je 0x78c7
movq 0x1d0(%r14), %rax
movq %rax, %rcx
subq %rdx, %rcx
cmpq $0x3, %rcx
ja 0x78ec
movq 0x1c8(%r14), %rsi
testq %rdx, %rdx
je 0x78e3
movq (%rsp), %rdi
callq 0xadad
movq 0x1c8(%r14), %rsi
movq 0x1d0(%r14), %rax
xorl %edx, %edx
andl $0xc0000000, %r15d      # imm = 0xC0000000
orl %ebx, %r15d
subq %rdx, %rax
cmpq $0x4, %rax
jb 0x790a
incq %r12
testl %ebx, %ebx
jne 0x77b5
testl %r13d, %r13d
je 0x791d
shll $0x18, %r13d
orl %ebp, %r13d
movl %r13d, 0x1b0(%r14)
testl %r15d, %r15d
js 0x7931
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x1b0(%r14), %edx
testl %edx, %edx
je 0x7973
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 0x799a
addb $0x41, %cl
jmp 0x79ba
leaq 0x4934(%rip), %rcx      # 0xc2ae
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 0xb06f
cmpb $0x33, %cl
ja 0x79a4
addb $0x47, %cl
jmp 0x79ba
cmpb $0x3d, %cl
ja 0x79ae
addb $-0x4, %cl
jmp 0x79ba
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 0x79cf
addb $0x41, %cl
jmp 0x79ef
cmpb $0x33, %cl
ja 0x79d9
addb $0x47, %cl
jmp 0x79ef
cmpb $0x3d, %cl
ja 0x79e3
addb $-0x4, %cl
jmp 0x79ef
cmpb $0x3e, %cl
setne %cl
shlb $0x2, %cl
orb $0x2b, %cl
movb %cl, 0x1(%r9)
movb $0x3d, %cl
cmpl $0x1000000, %edx        # imm = 0x1000000
je 0x7a16
shrl $0x6, %eax
andb $0x3c, %al
cmpb $0x19, %al
ja 0x7a0a
orb $0x41, %al
jmp 0x7a14
cmpb $0x33, %al
ja 0x7a12
addb $0x47, %al
jmp 0x7a14
addb $-0x4, %al
movl %eax, %ecx
movb %cl, 0x2(%r9)
movb $0x3d, 0x3(%r9)
leaq 0x4fd6(%rip), %rcx      # 0xc9fc
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 0xb06f