// File: /workspace/github_c_makefile_star2_O3/neovim[P]libtermkey/termkey.c
// Function: termkey_strpkey
const char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyFormat format)
{
  struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) +
                                    !!(format & TERMKEY_FORMAT_ALTISMETA) * 2 +
                                    !!(format & TERMKEY_FORMAT_LOWERMOD) * 4];

  key->modifiers = 0;

  if((format & TERMKEY_FORMAT_CARETCTRL) && str[0] == '^' && str[1]) {
    str = termkey_strpkey(tk, str+1, key, format & ~TERMKEY_FORMAT_CARETCTRL);

    if(!str ||
       key->type != TERMKEY_TYPE_UNICODE ||
       key->code.codepoint < '@' || key->code.codepoint > '_' ||
       key->modifiers != 0)
      return NULL;

    if(key->code.codepoint >= 'A' && key->code.codepoint <= 'Z')
      key->code.codepoint += 0x20;
    key->modifiers = TERMKEY_KEYMOD_CTRL;
    fill_utf8(key);
    return (char *)str;
  }

  const char *sep_at;

  while((sep_at = strchr(str, (format & TERMKEY_FORMAT_SPACEMOD) ? ' ' : '-'))) {
    size_t n = sep_at - str;

    if(n == strlen(mods->alt) && strncmp(mods->alt, str, n) == 0)
      key->modifiers |= TERMKEY_KEYMOD_ALT;
    else if(n == strlen(mods->ctrl) && strncmp(mods->ctrl, str, n) == 0)
      key->modifiers |= TERMKEY_KEYMOD_CTRL;
    else if(n == strlen(mods->shift) && strncmp(mods->shift, str, n) == 0)
      key->modifiers |= TERMKEY_KEYMOD_SHIFT;

    else
      break;

    str = sep_at + 1;
  }

  size_t nbytes;
  ssize_t snbytes;
  const char *endstr;
  int button;
  char event_name[32];

  if((endstr = termkey_lookup_keyname_format(tk, str, &key->code.sym, format))) {
    key->type = TERMKEY_TYPE_KEYSYM;
    str = endstr;
  }
  else if(sscanf(str, "F%d%zn", &key->code.number, &snbytes) == 1) {
    key->type = TERMKEY_TYPE_FUNCTION;
    str += snbytes;
  }
  else if(sscanf(str, "Mouse%31[^(](%d)%zn", event_name, &button, &snbytes) == 2) {
    str += snbytes;
    key->type = TERMKEY_TYPE_MOUSE;

    TermKeyMouseEvent ev = TERMKEY_MOUSE_UNKNOWN;
    for(size_t i = 0; i < sizeof(evnames)/sizeof(evnames[0]); i++) {
      if(strcmp(evnames[i], event_name) == 0) {
        ev = TERMKEY_MOUSE_UNKNOWN + i;
        break;
      }
    }

    int code;
    switch(ev) {
    case TERMKEY_MOUSE_PRESS:
    case TERMKEY_MOUSE_DRAG:
      code = button - 1;
      if(ev == TERMKEY_MOUSE_DRAG) {
        code |= 0x20;
      }
      break;
    case TERMKEY_MOUSE_RELEASE:
      code = 3;
      break;
    default:
      code = 128;
      break;
    }
    key->code.mouse[0] = code;

    unsigned int line = 0, col = 0;
    if((format & TERMKEY_FORMAT_MOUSE_POS) && sscanf(str, " @ (%u,%u)%zn", &col, &line, &snbytes) == 2) {
      str += snbytes;
    }
    termkey_key_set_linecol(key, col, line);
  }
  // Unicode must be last
  else if(parse_utf8((unsigned const char *)str, strlen(str), &key->code.codepoint, &nbytes) == TERMKEY_RES_KEY) {
    key->type = TERMKEY_TYPE_UNICODE;
    fill_utf8(key);
    str += nbytes;
  }
  else
    return NULL;

  termkey_canonicalise(tk, key);

  return (char *)str;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %r15d
movq %rdx, %r14
movq %rsi, %rbp
movl $0x0, 0x10(%rdx)
testb $0x2, %r15b
je 0x4882
cmpb $0x5e, (%rbp)
jne 0x4882
cmpb $0x0, 0x1(%rbp)
je 0x4882
incq %rbp
andl $-0x3, %r15d
movq %rbp, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x3160
testq %rax, %rax
je 0x4a9f
cmpl $0x0, (%r14)
jne 0x4a9f
movq %rax, %rbp
movq 0x8(%r14), %rax
leaq -0x60(%rax), %rcx
cmpq $-0x20, %rcx
jb 0x4a9f
cmpl $0x0, 0x10(%r14)
jne 0x4a9f
cmpq $0x40, %rax
sete %cl
cmpq $0x5b, %rax
setae %dl
orb %cl, %dl
jne 0x486d
orq $0x20, %rax
movq %rax, 0x8(%r14)
movl $0x4, 0x10(%r14)
movq %r14, %rdi
callq 0x3b05
jmp 0x4b5d
movq %rdi, 0x38(%rsp)
testb $0x10, %r15b
movl $0x2d, %eax
movl $0x20, %esi
cmovel %eax, %esi
movq %rbp, %rdi
movl %esi, 0x28(%rsp)
callq 0x3100
testq %rax, %rax
movq %r14, 0x8(%rsp)
movl %r15d, 0x18(%rsp)
je 0x49aa
movq %rax, %rbx
movl %r15d, %eax
andl $0x1, %eax
movl %r15d, %ecx
shrl %ecx
andl $0x2, %ecx
orl %eax, %ecx
movl %r15d, %eax
shrl $0x3, %eax
andl $0x4, %eax
orl %ecx, %eax
leaq (%rax,%rax,2), %rax
leaq 0x5c40(%rip), %rcx      # 0xa520
leaq (%rcx,%rax,8), %r12
movq 0x8(%r12), %rax
movq %rax, 0x30(%rsp)
xorl %r15d, %r15d
movq %rbx, %r13
subq %rbp, %r13
movq 0x30(%rsp), %rdi
callq 0x30f0
cmpq %rax, %r13
jne 0x491a
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x30c0
testl %eax, %eax
je 0x496d
movq 0x10(%r12), %r14
movq %r14, %rdi
callq 0x30f0
cmpq %rax, %r13
jne 0x493e
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x30c0
testl %eax, %eax
je 0x4974
movq (%r12), %r14
movq %r14, %rdi
callq 0x30f0
cmpq %rax, %r13
jne 0x49a5
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x30c0
movl $0x1, %ecx
testl %eax, %eax
movq 0x8(%rsp), %r14
je 0x497e
jmp 0x49aa
movl $0x2, %ecx
jmp 0x497e
movl $0x4, %ecx
movq 0x8(%rsp), %r14
orl %ecx, %r15d
movl %r15d, 0x10(%r14)
movq %rbx, %rbp
incq %rbp
movq %rbp, %rdi
movl 0x28(%rsp), %esi
callq 0x3100
movq %rax, %rbx
testq %rax, %rax
jne 0x48f1
jmp 0x49aa
movq 0x8(%rsp), %r14
leaq 0x8(%r14), %r12
movq 0x38(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movl 0x18(%rsp), %ecx
callq 0x4039
testq %rax, %rax
je 0x49d9
movl $0x2, (%r14)
movq %rax, %rbp
jmp 0x4b52
leaq 0x27cc(%rip), %rsi      # 0x71ac
leaq 0x10(%rsp), %rcx
movq %rbp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x31d0
cmpl $0x1, %eax
jne 0x4a08
movl $0x1, (%r14)
addq 0x10(%rsp), %rbp
jmp 0x4b52
leaq 0x27a4(%rip), %rsi      # 0x71b3
leaq 0x40(%rsp), %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %rbp, %rdi
xorl %eax, %eax
callq 0x31d0
cmpl $0x2, %eax
jne 0x4a66
addq 0x10(%rsp), %rbp
movl $0x3, (%r14)
leaq 0x5ba0(%rip), %r15      # 0xa5e0
xorl %r14d, %r14d
leaq 0x40(%rsp), %rbx
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x3170
testl %eax, %eax
je 0x4aa6
incq %r14
addq $0x8, %r15
cmpq $0x4, %r14
jne 0x4a48
jmp 0x4ace
movq %rbp, %rdi
callq 0x30f0
leaq 0x20(%rsp), %rcx
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x4b6f
cmpl $0x1, %eax
jne 0x4a9f
movl $0x0, (%r14)
movq %r14, %rdi
callq 0x3b05
addq 0x20(%rsp), %rbp
jmp 0x4b52
xorl %ebp, %ebp
jmp 0x4b5d
leal -0x1(%r14), %eax
cmpl $0x2, %eax
jae 0x4ac6
movb 0x2c(%rsp), %al
decb %al
movzbl %al, %ecx
orb $0x20, %al
cmpq $0x2, %r14
movzbl %al, %eax
cmovnel %ecx, %eax
jmp 0x4ad0
movb $0x3, %al
cmpl $0x3, %r14d
je 0x4ad0
movb $-0x80, %al
movb %al, (%r12)
xorl %eax, %eax
movl %eax, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
btl $0x8, 0x18(%rsp)
jb 0x4aed
movq 0x8(%rsp), %r14
jmp 0x4b1c
leaq 0x26d3(%rip), %rsi      # 0x71c7
leaq 0x1c(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %rbp, %rdi
xorl %eax, %eax
callq 0x31d0
cmpl $0x2, %eax
movq 0x8(%rsp), %r14
jne 0x4b1c
addq 0x10(%rsp), %rbp
movl 0x1c(%rsp), %eax
movl 0x20(%rsp), %ecx
movl $0xfff, %edx            # imm = 0xFFF
cmpl %edx, %eax
cmovll %eax, %edx
movl $0x7ff, %eax            # imm = 0x7FF
cmpl %eax, %ecx
cmovll %ecx, %eax
movb %dl, 0x9(%r14)
movb %al, 0xa(%r14)
shrl $0x8, %edx
andl $0xf, %edx
shrl $0x4, %eax
andl $0x30, %eax
orl %edx, %eax
movb %al, 0xb(%r14)
movq %r13, %rdi
movq %r14, %rsi
callq 0x3270
movq %rbp, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq