// File: /workspace/github_c_makefile_star2_O3/neovim[P]libvterm/src/state.c
// Function: on_escape
static int on_escape(const char *bytes, size_t len, void *user)
{
  VTermState *state = user;

  /* Easier to decode this from the first byte, even though the final
   * byte terminates it
   */
  switch(bytes[0]) {
  case ' ':
    if(len != 2)
      return 0;

    switch(bytes[1]) {
      case 'F': // S7C1T
        state->vt->mode.ctrl8bit = 0;
        break;

      case 'G': // S8C1T
        state->vt->mode.ctrl8bit = 1;
        break;

      default:
        return 0;
    }
    return 2;

  case '#':
    if(len != 2)
      return 0;

    switch(bytes[1]) {
      case '3': // DECDHL top
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_TOP);
        break;

      case '4': // DECDHL bottom
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_BOTTOM);
        break;

      case '5': // DECSWL
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_OFF, DHL_OFF);
        break;

      case '6': // DECDWL
        if(state->mode.leftrightmargin)
          break;
        set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_OFF);
        break;

      case '8': // DECALN
      {
        VTermPos pos;
        uint32_t E[] = { 'E', 0 };
        for(pos.row = 0; pos.row < state->rows; pos.row++)
          for(pos.col = 0; pos.col < ROWWIDTH(state, pos.row); pos.col++)
            putglyph(state, E, 1, pos);
        break;
      }

      default:
        return 0;
    }
    return 2;

  case '(': case ')': case '*': case '+': // SCS
    if(len != 2)
      return 0;

    {
      int setnum = bytes[0] - 0x28;
      VTermEncoding *newenc = vterm_lookup_encoding(ENC_SINGLE_94, bytes[1]);

      if(newenc) {
        state->encoding[setnum].enc = newenc;

        if(newenc->init)
          (*newenc->init)(newenc, state->encoding[setnum].data);
      }
    }

    return 2;

  case '7': // DECSC
    savecursor(state, 1);
    return 1;

  case '8': // DECRC
    savecursor(state, 0);
    return 1;

  case '<': // Ignored by VT100. Used in VT52 mode to switch up to VT100
    return 1;

  case '=': // DECKPAM
    state->mode.keypad = 1;
    return 1;

  case '>': // DECKPNM
    state->mode.keypad = 0;
    return 1;

  case 'c': // RIS - ECMA-48 8.3.105
  {
    VTermPos oldpos = state->pos;
    vterm_state_reset(state, 1);
    if(state->callbacks && state->callbacks->movecursor)
      (*state->callbacks->movecursor)(state->pos, oldpos, state->mode.cursor_visible, state->cbdata);
    return 1;
  }

  case 'n': // LS2 - ECMA-48 8.3.78
    state->gl_set = 2;
    return 1;

  case 'o': // LS3 - ECMA-48 8.3.80
    state->gl_set = 3;
    return 1;

  case '~': // LS1R - ECMA-48 8.3.77
    state->gr_set = 1;
    return 1;

  case '}': // LS2R - ECMA-48 8.3.79
    state->gr_set = 2;
    return 1;

  case '|': // LS3R - ECMA-48 8.3.81
    state->gr_set = 3;
    return 1;

  default:
    return 0;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movzbl (%rdi), %r15d
movl $0x1, %ebx
cmpl $0x62, %r15d
jg 0x80d6
cmpl $0x36, %r15d
jg 0x810a
leal -0x28(%r15), %eax
cmpl $0x4, %eax
jae 0x8163
xorl %ebx, %ebx
cmpq $0x2, %rsi
jne 0x83b2
movsbl 0x1(%rdi), %esi
movl $0x1, %edi
callq 0x2130
movl $0x2, %ebx
testq %rax, %rax
je 0x83b2
leaq (%r15,%r15,2), %rdx
movq %rax, -0x310(%r14,%rdx,8)
movq (%rax), %rcx
testq %rcx, %rcx
je 0x83b2
leaq (%r14,%rdx,8), %rsi
addq $-0x310, %rsi           # imm = 0xFCF0
addq $0x8, %rsi
movq %rax, %rdi
callq *%rcx
jmp 0x83b2
cmpl $0x7b, %r15d
jg 0x8135
cmpl $0x63, %r15d
je 0x81f8
cmpl $0x6e, %r15d
je 0x8252
cmpl $0x6f, %r15d
jne 0x829c
movl $0x3, 0x128(%r14)
jmp 0x83b2
addl $-0x37, %r15d
cmpl $0x7, %r15d
ja 0x829c
leaq 0x469d(%rip), %rax      # 0xc7bc
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r14, %rdi
movl $0x1, %esi
jmp 0x81e1
cmpl $0x7c, %r15d
je 0x8242
cmpl $0x7d, %r15d
je 0x8262
cmpl $0x7e, %r15d
jne 0x829c
movl $0x1, 0x12c(%r14)
jmp 0x83b2
cmpl $0x20, %r15d
je 0x8272
cmpl $0x23, %r15d
jne 0x829c
xorl %ebx, %ebx
cmpq $0x2, %rsi
jne 0x83b2
movzbl 0x1(%rdi), %eax
addl $-0x33, %eax
cmpl $0x5, %eax
ja 0x83b2
leaq 0x4642(%rip), %rcx      # 0xc7dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x83b2
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x1, %r8d
jmp 0x831c
orb $0x1, 0xac(%r14)
jmp 0x83b2
movq %r14, %rdi
xorl %esi, %esi
callq 0xa4e3
jmp 0x83b2
andb $-0x2, 0xac(%r14)
jmp 0x83b2
movq 0x38(%r14), %r15
movq %r14, %rdi
movl $0x1, %esi
callq 0x2100
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x83b2
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x83b2
movl 0xac(%r14), %edx
shrl $0x5, %edx
andl $0x1, %edx
movq 0x10(%r14), %rcx
movq 0x38(%r14), %rdi
movq %r15, %rsi
callq *%rax
jmp 0x83b2
movl $0x3, 0x12c(%r14)
jmp 0x83b2
movl $0x2, 0x128(%r14)
jmp 0x83b2
movl $0x2, 0x12c(%r14)
jmp 0x83b2
xorl %ebx, %ebx
cmpq $0x2, %rsi
jne 0x83b2
movzbl 0x1(%rdi), %eax
cmpl $0x47, %eax
je 0x82a3
cmpl $0x46, %eax
jne 0x83b2
movq (%r14), %rax
andb $-0x3, 0x18(%rax)
jmp 0x83ad
xorl %ebx, %ebx
jmp 0x83b2
movq (%r14), %rax
orb $0x2, 0x18(%rax)
jmp 0x83ad
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x83b2
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
jmp 0x8319
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x83b2
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x2, %r8d
jmp 0x831c
movl $0x2, %ebx
testb $0x10, 0xad(%r14)
jne 0x83b2
movl 0x38(%r14), %esi
movq %r14, %rdi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x73b5
jmp 0x83b2
movq $0x45, (%rsp)
cmpl $0x0, 0x30(%r14)
jle 0x83ad
xorl %r12d, %r12d
movq %rsp, %rbx
movabsq $0x100000000, %r13      # imm = 0x100000000
movq 0x70(%r14), %rax
movl 0x34(%r14), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
testb $0x1, (%rax,%r12,4)
cmovel %ecx, %edx
testl %edx, %edx
jle 0x83a1
movq %r12, %r15
xorl %ebp, %ebp
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movq %r15, %rcx
callq 0xa111
incq %rbp
movq 0x70(%r14), %rax
movl 0x34(%r14), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
testb $0x1, (%rax,%r12,4)
cmovel %ecx, %edx
movslq %edx, %rax
addq %r13, %r15
cmpq %rax, %rbp
jl 0x8367
incq %r12
movslq 0x30(%r14), %rax
cmpq %rax, %r12
jl 0x8345
movl $0x2, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq