// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/state.c
// Function: osc_selection
static void osc_selection(VTermState *state, VTermStringFragment frag)
{
  if(frag.initial) {
    state->tmp.selection.mask = 0;
    state->tmp.selection.state = SELECTION_INITIAL;
  }

  while(!state->tmp.selection.state && frag.len) {
    /* Parse selection parameter */
    switch(frag.str[0]) {
      case 'c':
        state->tmp.selection.mask |= VTERM_SELECTION_CLIPBOARD;
        break;
      case 'p':
        state->tmp.selection.mask |= VTERM_SELECTION_PRIMARY;
        break;
      case 'q':
        state->tmp.selection.mask |= VTERM_SELECTION_SECONDARY;
        break;
      case 's':
        state->tmp.selection.mask |= VTERM_SELECTION_SELECT;
        break;
      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
        state->tmp.selection.mask |= (VTERM_SELECTION_CUT0 << (frag.str[0] - '0'));
        break;

      case ';':
        state->tmp.selection.state = SELECTION_SELECTED;
        if(!state->tmp.selection.mask)
          state->tmp.selection.mask = VTERM_SELECTION_SELECT|VTERM_SELECTION_CUT0;
        break;
    }

    frag.str++;
    frag.len--;
  }

  if(!frag.len) {
    /* Clear selection if we're already finished but didn't do anything */
    if(frag.final && state->selection.callbacks->set) {
      (*state->selection.callbacks->set)(state->tmp.selection.mask, (VTermStringFragment){
              .str     = NULL,
              .len     = 0,
              .initial = state->tmp.selection.state != SELECTION_SET,
              .final   = true,
            }, state->selection.user);
    }
    return;
  }

  if(state->tmp.selection.state == SELECTION_SELECTED) {
    if(frag.str[0] == '?') {
      state->tmp.selection.state = SELECTION_QUERY;
    }
    else {
      state->tmp.selection.state = SELECTION_SET_INITIAL;
      state->tmp.selection.recvpartial = 0;
    }
  }

  if(state->tmp.selection.state == SELECTION_QUERY) {
    if(state->selection.callbacks->query)
      (*state->selection.callbacks->query)(state->tmp.selection.mask, state->selection.user);
    return;
  }

  if(state->tmp.selection.state == SELECTION_INVALID)
    return;

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

    uint32_t x = 0; /* Current decoding value */
    int n = 0;      /* Number of sextets consumed */

    if(state->tmp.selection.recvpartial) {
      n = state->tmp.selection.recvpartial >> 24;
      x = state->tmp.selection.recvpartial & 0x03FFFF; /* could be up to 18 bits of state in here */

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

    while((state->selection.buflen - bufcur) >= 3 && frag.len) {
      if(frag.str[0] == '=') {
        if(n == 2) {
          buffer[0] = (x >> 4) & 0xFF;
          buffer += 1, bufcur += 1;
        }
        if(n == 3) {
          buffer[0] = (x >> 10) & 0xFF;
          buffer[1] = (x >>  2) & 0xFF;
          buffer += 2, bufcur += 2;
        }

        while(frag.len && frag.str[0] == '=')
          frag.str++, frag.len--;

        n = 0;
      }
      else {
        uint8_t b = unbase64one(frag.str[0]);
        if(b == 0xFF) {
          DEBUG_LOG("base64decode bad input %02X\n", (uint8_t)frag.str[0]);

          state->tmp.selection.state = SELECTION_INVALID;
          if(state->selection.callbacks->set) {
            (*state->selection.callbacks->set)(state->tmp.selection.mask, (VTermStringFragment){
                .str     = NULL,
                .len     = 0,
                .initial = true,
                .final   = true,
                }, state->selection.user);
          }
          break;
        }

        x = (x << 6) | b;
        n++;
        frag.str++, frag.len--;

        if(n == 4) {
          buffer[0] = (x >> 16) & 0xFF;
          buffer[1] = (x >>  8) & 0xFF;
          buffer[2] = (x >>  0) & 0xFF;

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

      if(!frag.len || (state->selection.buflen - bufcur) < 3) {
        if(bufcur) {
          (*state->selection.callbacks->set)(state->tmp.selection.mask, (VTermStringFragment){
              .str     = state->selection.buffer,
              .len     = bufcur,
              .initial = state->tmp.selection.state == SELECTION_SET_INITIAL,
              .final   = frag.final && !frag.len,
            }, state->selection.user);
          state->tmp.selection.state = SELECTION_SET;
        }

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rsi, -0x10(%rbp)
movq %rdx, -0x8(%rbp)
movq %rdi, -0x18(%rbp)
movl -0x8(%rbp), %eax
shrl $0x1e, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x106ef
movq -0x18(%rbp), %rax
movw $0x0, 0x1a8(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x1aa(%rax)
jmp 0x106f1
movq -0x18(%rbp), %rax
movzbl 0x1aa(%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x69(%rbp)
jne 0x10719
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x10725
jmp 0x10834
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
addl $-0x30, %eax
movl %eax, %ecx
movq %rcx, -0x78(%rbp)
subl $0x43, %eax
ja 0x10800
movq -0x78(%rbp), %rax
leaq 0x3057(%rip), %rcx      # 0x137a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movzwl 0x1a8(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0x1a8(%rax)
jmp 0x10800
movq -0x18(%rbp), %rax
movzwl 0x1a8(%rax), %ecx
orl $0x2, %ecx
movw %cx, 0x1a8(%rax)
jmp 0x10800
movq -0x18(%rbp), %rax
movzwl 0x1a8(%rax), %ecx
orl $0x4, %ecx
movw %cx, 0x1a8(%rax)
jmp 0x10800
movq -0x18(%rbp), %rax
movzwl 0x1a8(%rax), %ecx
orl $0x8, %ecx
movw %cx, 0x1a8(%rax)
jmp 0x10800
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
subl $0x30, %ecx
movl $0x10, %edx
shll %cl, %edx
movq -0x18(%rbp), %rax
movzwl 0x1a8(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1a8(%rax)
jmp 0x10800
movq -0x18(%rbp), %rax
movb $0x1, 0x1aa(%rax)
movq -0x18(%rbp), %rax
cmpw $0x0, 0x1a8(%rax)
jne 0x107fe
movq -0x18(%rbp), %rax
movw $0x18, 0x1a8(%rax)
jmp 0x10800
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)
jmp 0x106f1
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpq $0x0, %rax
jne 0x108ee
movl -0x8(%rbp), %eax
shrl $0x1f, %eax
testl $0x1, %eax
je 0x108e9
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
cmpq $0x0, (%rax)
je 0x108e9
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movzwl 0x1a8(%rcx), %edi
movq $0x0, -0x28(%rbp)
movl -0x20(%rbp), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x0, %ecx
movl %ecx, -0x20(%rbp)
movq -0x18(%rbp), %rcx
movzbl 0x1aa(%rcx), %ecx
cmpl $0x4, %ecx
setne %cl
andb $0x1, %cl
movzbl %cl, %edx
movl -0x20(%rbp), %ecx
shll $0x1e, %edx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl %edx, %ecx
movl %ecx, -0x20(%rbp)
movl -0x20(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, -0x20(%rbp)
movq -0x18(%rbp), %rcx
movq 0x1c0(%rcx), %rcx
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq *%rax
jmp 0x10df6
movq -0x18(%rbp), %rax
movzbl 0x1aa(%rax), %eax
cmpl $0x1, %eax
jne 0x10932
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3f, %eax
jne 0x10917
movq -0x18(%rbp), %rax
movb $0x2, 0x1aa(%rax)
jmp 0x10930
movq -0x18(%rbp), %rax
movb $0x3, 0x1aa(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x1ac(%rax)
jmp 0x10932
movq -0x18(%rbp), %rax
movzbl 0x1aa(%rax), %eax
cmpl $0x2, %eax
jne 0x10980
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x1097b
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movzwl 0x1a8(%rcx), %edi
movq -0x18(%rbp), %rcx
movq 0x1c0(%rcx), %rsi
callq *%rax
jmp 0x10df6
movq -0x18(%rbp), %rax
movzbl 0x1aa(%rax), %eax
cmpl $0x5, %eax
jne 0x10995
jmp 0x10df6
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
cmpq $0x0, (%rax)
je 0x10df6
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x1c8(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1ac(%rax)
je 0x10a0c
movq -0x18(%rbp), %rax
movl 0x1ac(%rax), %eax
shrl $0x18, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x1ac(%rax), %eax
andl $0x3ffff, %eax          # imm = 0x3FFFF
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x1ac(%rax)
jmp 0x10a0e
movq -0x18(%rbp), %rax
movq 0x1d0(%rax), %rcx
subq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq $0x3, %rcx
movb %al, -0x79(%rbp)
jb 0x10a3b
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x10a47
jmp 0x10ddb
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x10b3b
cmpl $0x2, -0x40(%rbp)
jne 0x10a88
movl -0x3c(%rbp), %eax
shrl $0x4, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, (%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
cmpl $0x3, -0x40(%rbp)
jne 0x10acd
movl -0x3c(%rbp), %eax
shrl $0xa, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
shrl $0x2, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
jmp 0x10acf
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x7a(%rbp)
je 0x10af5
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
sete %al
movb %al, -0x7a(%rbp)
movb -0x7a(%rbp), %al
testb $0x1, %al
jne 0x10afe
jmp 0x10b2f
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)
jmp 0x10acf
movl $0x0, -0x40(%rbp)
jmp 0x10c93
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x10e00
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0xff, %eax
jne 0x10be3
movq -0x18(%rbp), %rax
movb $0x5, 0x1aa(%rax)
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
cmpq $0x0, (%rax)
je 0x10bde
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movzwl 0x1a8(%rcx), %edi
movq $0x0, -0x58(%rbp)
movl -0x50(%rbp), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x0, %ecx
movl %ecx, -0x50(%rbp)
movl -0x50(%rbp), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, -0x50(%rbp)
movl -0x50(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, -0x50(%rbp)
movq -0x18(%rbp), %rcx
movq 0x1c0(%rcx), %rcx
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq *%rax
jmp 0x10ddb
movl -0x3c(%rbp), %eax
shll $0x6, %eax
movzbl -0x41(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%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 $0x4, -0x40(%rbp)
jne 0x10c91
movl -0x3c(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x3c(%rbp), %eax
shrl $0x0, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x38(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x10c93
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpq $0x0, %rax
je 0x10cbc
movq -0x18(%rbp), %rax
movq 0x1d0(%rax), %rax
subq -0x30(%rbp), %rax
cmpq $0x3, %rax
jae 0x10dd6
cmpq $0x0, -0x30(%rbp)
je 0x10dbf
movq -0x18(%rbp), %rax
movq 0x1b8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x1a8(%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x18(%rbp), %rax
movq 0x1c8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movl %eax, %ecx
movl -0x60(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x1aa(%rax), %eax
cmpl $0x3, %eax
sete %al
andb $0x1, %al
movzbl %al, %ecx
movl -0x60(%rbp), %eax
shll $0x1e, %ecx
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl %ecx, %eax
movl %eax, -0x60(%rbp)
leaq -0x68(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x88(%rbp)
movl -0x8(%rbp), %ecx
shrl $0x1f, %ecx
xorl %eax, %eax
testl $0x1, %ecx
movb %al, -0x7b(%rbp)
je 0x10d73
movl -0x8(%rbp), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
movb %al, -0x7b(%rbp)
movq -0x98(%rbp), %rax
movl -0x8c(%rbp), %edi
movq -0x88(%rbp), %rcx
movb -0x7b(%rbp), %dl
andb $0x1, %dl
movzbl %dl, %esi
movl (%rcx), %edx
shll $0x1f, %esi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl %esi, %edx
movl %edx, (%rcx)
movq -0x18(%rbp), %rcx
movq 0x1c0(%rcx), %rcx
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq *%rax
movq -0x18(%rbp), %rax
movb $0x4, 0x1aa(%rax)
movq -0x18(%rbp), %rax
movq 0x1c8(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
jmp 0x10a0e
cmpl $0x0, -0x40(%rbp)
je 0x10df4
movl -0x40(%rbp), %ecx
shll $0x18, %ecx
orl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1ac(%rax)
jmp 0x10df6
addq $0xa0, %rsp
popq %rbp
retq
nop