// File: /workspace/github_c_makefile_star2_O1/neovim[P]libvterm/src/state.c
// Function: on_control
static int on_control(unsigned char control, void *user)
{
  VTermState *state = user;

  VTermPos oldpos = state->pos;

  switch(control) {
  case 0x07: // BEL - ECMA-48 8.3.3
    if(state->callbacks && state->callbacks->bell)
      (*state->callbacks->bell)(state->cbdata);
    break;

  case 0x08: // BS - ECMA-48 8.3.5
    if(state->pos.col > 0)
      state->pos.col--;
    break;

  case 0x09: // HT - ECMA-48 8.3.60
    tab(state, 1, +1);
    break;

  case 0x0a: // LF - ECMA-48 8.3.74
  case 0x0b: // VT
  case 0x0c: // FF
    linefeed(state);
    if(state->mode.newline)
      state->pos.col = 0;
    break;

  case 0x0d: // CR - ECMA-48 8.3.15
    state->pos.col = 0;
    break;

  case 0x0e: // LS1 - ECMA-48 8.3.76
    state->gl_set = 1;
    break;

  case 0x0f: // LS0 - ECMA-48 8.3.75
    state->gl_set = 0;
    break;

  case 0x84: // IND - DEPRECATED but implemented for completeness
    linefeed(state);
    break;

  case 0x85: // NEL - ECMA-48 8.3.86
    linefeed(state);
    state->pos.col = 0;
    break;

  case 0x88: // HTS - ECMA-48 8.3.62
    set_col_tabstop(state, state->pos.col);
    break;

  case 0x8d: // RI - ECMA-48 8.3.104
    if(state->pos.row == state->scrollregion_top) {
      VTermRect rect = {
        .start_row = state->scrollregion_top,
        .end_row   = SCROLLREGION_BOTTOM(state),
        .start_col = SCROLLREGION_LEFT(state),
        .end_col   = SCROLLREGION_RIGHT(state),
      };

      scroll(state, rect, -1, 0);
    }
    else if(state->pos.row > 0)
        state->pos.row--;
    break;

  case 0x8e: // SS2 - ECMA-48 8.3.141
    state->gsingle_set = 2;
    break;

  case 0x8f: // SS3 - ECMA-48 8.3.142
    state->gsingle_set = 3;
    break;

  default:
    if(state->fallbacks && state->fallbacks->control)
      if((*state->fallbacks->control)(control, state->fbdata))
        return 1;

    return 0;
  }

  updatecursor(state, &oldpos, 1);

#ifdef DEBUG
  if(state->pos.row < 0 || state->pos.row >= state->rows ||
     state->pos.col < 0 || state->pos.col >= state->cols) {
    fprintf(stderr, "Position out of bounds after Ctrl %02x: (%d,%d)\n",
        control, state->pos.row, state->pos.col);
    abort();
  }
#endif

  return 1;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq 0x38(%rsi), %rax
movq %rax, (%rsp)
leal -0x7(%rdi), %eax
cmpl $0x8, %eax
ja 0x75a8
leaq 0x4153(%rip), %rcx      # 0xb6d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x9822
testb $0x10, 0xac(%rbx)
jne 0x764d
jmp 0x771a
leal -0x84(%rdi), %eax
cmpl $0xb, %eax
ja 0x76ba
leaq 0x413e(%rip), %rcx      # 0xb6fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x9822
jmp 0x771a
movl $0x3, 0x130(%rbx)
jmp 0x771a
movl $0x2, 0x130(%rbx)
jmp 0x771a
movl 0x3c(%rbx), %eax
movl %eax, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
movq 0x58(%rbx), %rcx
sarl $0x3, %eax
cltq
orb %dl, (%rcx,%rax)
jmp 0x771a
movl 0x38(%rbx), %ecx
movl 0x44(%rbx), %eax
cmpl %eax, %ecx
jne 0x76e2
movl 0x48(%rbx), %esi
testl %esi, %esi
jns 0x762a
movl 0x30(%rbx), %esi
shlq $0x20, %rsi
movl 0xac(%rbx), %edx
btl $0xc, %edx
jb 0x76ed
xorl %ecx, %ecx
jmp 0x76f0
movq %rbx, %rdi
callq 0x9822
movl $0x0, 0x3c(%rbx)
jmp 0x771a
movl $0x1, 0x128(%rbx)
jmp 0x771a
movl 0x3c(%rbx), %eax
testl %eax, %eax
jle 0x771a
decl %eax
movl %eax, 0x3c(%rbx)
jmp 0x771a
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x9b3b
jmp 0x771a
movl $0x0, 0x128(%rbx)
jmp 0x771a
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x771a
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x771a
movq 0x10(%rbx), %rdi
callq *%rax
jmp 0x771a
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x76de
movq (%rax), %rax
testq %rax, %rax
je 0x76de
movq 0x28(%rbx), %rsi
movzbl %dil, %edi
callq *%rax
movl $0x1, %ebp
testl %eax, %eax
jne 0x772f
xorl %ebp, %ebp
jmp 0x772f
testl %ecx, %ecx
jle 0x771a
decl %ecx
movl %ecx, 0x38(%rbx)
jmp 0x771a
movl 0x4c(%rbx), %ecx
orq %rax, %rsi
btl $0xc, %edx
jae 0x7700
movl 0x50(%rbx), %edx
testl %edx, %edx
jns 0x7703
movl 0x34(%rbx), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movq %rbx, %rdi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x988b
movq %rsp, %rsi
movl $0x1, %ebp
movq %rbx, %rdi
movl $0x1, %edx
callq 0x9af5
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq