// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/keyboard.c
// Function: vterm_keyboard_key
void vterm_keyboard_key(VTerm *vt, VTermKey key, VTermModifier mod)
{
  if(key == VTERM_KEY_NONE)
    return;

  keycodes_s k;
  if(key < VTERM_KEY_FUNCTION_0) {
    if(key >= sizeof(keycodes)/sizeof(keycodes[0]))
      return;
    k = keycodes[key];
  }
  else if(key >= VTERM_KEY_FUNCTION_0 && key <= VTERM_KEY_FUNCTION_MAX) {
    if((key - VTERM_KEY_FUNCTION_0) >= sizeof(keycodes_fn)/sizeof(keycodes_fn[0]))
      return;
    k = keycodes_fn[key - VTERM_KEY_FUNCTION_0];
  }
  else if(key >= VTERM_KEY_KP_0) {
    if((key - VTERM_KEY_KP_0) >= sizeof(keycodes_kp)/sizeof(keycodes_kp[0]))
      return;
    k = keycodes_kp[key - VTERM_KEY_KP_0];
  }

  switch(k.type) {
  case KEYCODE_NONE:
    break;

  case KEYCODE_TAB:
    /* Shift-Tab is CSI Z but plain Tab is 0x09 */
    if(mod == VTERM_MOD_SHIFT)
      vterm_push_output_sprintf_ctrl(vt, C1_CSI, "Z");
    else if(mod & VTERM_MOD_SHIFT)
      vterm_push_output_sprintf_ctrl(vt, C1_CSI, "1;%dZ", mod+1);
    else
      goto case_LITERAL;
    break;

  case KEYCODE_ENTER:
    /* Enter is CRLF in newline mode, but just LF in linefeed */
    if(vt->state->mode.newline)
      vterm_push_output_sprintf(vt, "\r\n");
    else
      goto case_LITERAL;
    break;

  case KEYCODE_LITERAL: case_LITERAL:
    if(mod & (VTERM_MOD_SHIFT|VTERM_MOD_CTRL))
      vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%du", k.literal, mod+1);
    else
      vterm_push_output_sprintf(vt, mod & VTERM_MOD_ALT ? ESC_S "%c" : "%c", k.literal);
    break;

  case KEYCODE_SS3: case_SS3:
    if(mod == 0)
      vterm_push_output_sprintf_ctrl(vt, C1_SS3, "%c", k.literal);
    else
      goto case_CSI;
    break;

  case KEYCODE_CSI: case_CSI:
    if(mod == 0)
      vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%c", k.literal);
    else
      vterm_push_output_sprintf_ctrl(vt, C1_CSI, "1;%d%c", mod + 1, k.literal);
    break;

  case KEYCODE_CSINUM:
    if(mod == 0)
      vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d%c", k.csinum, k.literal);
    else
      vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%d%c", k.csinum, mod + 1, k.literal);
    break;

  case KEYCODE_CSI_CURSOR:
    if(vt->state->mode.cursor)
      goto case_SS3;
    else
      goto case_CSI;

  case KEYCODE_KEYPAD:
    if(vt->state->mode.keypad) {
      k.literal = k.csinum;
      goto case_SS3;
    }
    else
      goto case_LITERAL;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x2cbd
jmp 0x2fcd
cmpl $0x100, -0xc(%rbp)      # imm = 0x100
jae 0x2cf9
movl -0xc(%rbp), %eax
cmpq $0xf, %rax
jb 0x2cd4
jmp 0x2fcd
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x154b0(%rip), %rax     # 0x18190
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x1c(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x2d92
cmpl $0x100, -0xc(%rbp)      # imm = 0x100
jb 0x2d49
cmpl $0x1ff, -0xc(%rbp)      # imm = 0x1FF
ja 0x2d49
movl -0xc(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
movl %eax, %eax
cmpq $0xd, %rax
jb 0x2d20
jmp 0x2fcd
movl -0xc(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
movl %eax, %eax
movl %eax, %ecx
leaq 0x1551d(%rip), %rax     # 0x18250
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x1c(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x2d90
cmpl $0x200, -0xc(%rbp)      # imm = 0x200
jb 0x2d8e
movl -0xc(%rbp), %eax
subl $0x200, %eax            # imm = 0x200
movl %eax, %eax
cmpq $0x12, %rax
jb 0x2d67
jmp 0x2fcd
movl -0xc(%rbp), %eax
subl $0x200, %eax            # imm = 0x200
movl %eax, %eax
movl %eax, %ecx
leaq 0x15576(%rip), %rax     # 0x182f0
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x1c(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x2d90
jmp 0x2d92
movl -0x1c(%rbp), %eax
movq %rax, -0x28(%rbp)
subq $0x8, %rax
ja 0x2fcd
movq -0x28(%rbp), %rax
leaq 0x103b6(%rip), %rcx     # 0x13164
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x2fcd
cmpl $0x1, -0x10(%rbp)
jne 0x2ddb
movq -0x8(%rbp), %rdi
movl $0x9b, %esi
leaq 0x103c8(%rip), %rdx     # 0x1319a
movb $0x0, %al
callq 0x11e00
jmp 0x2e09
movl -0x10(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2e05
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movl $0x9b, %esi
leaq 0x1039a(%rip), %rdx     # 0x13196
movb $0x0, %al
callq 0x11e00
jmp 0x2e07
jmp 0x2e4d
jmp 0x2e09
jmp 0x2fcd
movq -0x8(%rbp), %rax
movq 0x128(%rax), %rax
movw 0xac(%rax), %ax
shrw $0x4, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2e44
movq -0x8(%rbp), %rdi
leaq 0x10361(%rip), %rsi     # 0x1319c
movb $0x0, %al
callq 0x11d60
jmp 0x2e46
jmp 0x2e4d
jmp 0x2fcd
jmp 0x2e4d
movl -0x10(%rbp), %eax
andl $0x5, %eax
cmpl $0x0, %eax
je 0x2e7d
movq -0x8(%rbp), %rdi
movsbl -0x18(%rbp), %ecx
movl -0x10(%rbp), %r8d
addl $0x1, %r8d
movl $0x9b, %esi
leaq 0x10314(%rip), %rdx     # 0x13188
movb $0x0, %al
callq 0x11e00
jmp 0x2ea7
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %ecx
andl $0x2, %ecx
leaq 0x10312(%rip), %rsi     # 0x131a0
leaq 0x1030a(%rip), %rax     # 0x1319f
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movsbl -0x18(%rbp), %edx
movb $0x0, %al
callq 0x11d60
jmp 0x2fcd
jmp 0x2eae
cmpl $0x0, -0x10(%rbp)
jne 0x2ed1
movq -0x8(%rbp), %rdi
movsbl -0x18(%rbp), %ecx
movl $0x8f, %esi
leaq 0x102d8(%rip), %rdx     # 0x131a0
movb $0x0, %al
callq 0x11e00
jmp 0x2ed3
jmp 0x2eda
jmp 0x2fcd
jmp 0x2eda
cmpl $0x0, -0x10(%rbp)
jne 0x2efd
movq -0x8(%rbp), %rdi
movsbl -0x18(%rbp), %ecx
movl $0x9b, %esi
leaq 0x102ac(%rip), %rdx     # 0x131a0
movb $0x0, %al
callq 0x11e00
jmp 0x2f1f
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movsbl -0x18(%rbp), %r8d
movl $0x9b, %esi
leaq 0x1028b(%rip), %rdx     # 0x131a3
movb $0x0, %al
callq 0x11e00
jmp 0x2fcd
cmpl $0x0, -0x10(%rbp)
jne 0x2f4b
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %ecx
movsbl -0x18(%rbp), %r8d
movl $0x9b, %esi
leaq 0x10263(%rip), %rdx     # 0x131a5
movb $0x0, %al
callq 0x11e00
jmp 0x2f72
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %ecx
movl -0x10(%rbp), %r8d
addl $0x1, %r8d
movsbl -0x18(%rbp), %r9d
movl $0x9b, %esi
leaq 0x10281(%rip), %rdx     # 0x131ec
movb $0x0, %al
callq 0x11e00
jmp 0x2fcd
movq -0x8(%rbp), %rax
movq 0x128(%rax), %rax
movw 0xac(%rax), %ax
shrw %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2f9a
jmp 0x2eae
jmp 0x2eda
movq -0x8(%rbp), %rax
movq 0x128(%rax), %rax
movw 0xac(%rax), %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x2fc8
movl -0x14(%rbp), %eax
movb %al, -0x18(%rbp)
jmp 0x2eae
jmp 0x2e4d
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)