// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq %rdx, %rbx
movq %rsi, %r15
andl $0x0, 0x10(%rdx)
testb $0x2, %cl
je 0x4720
cmpb $0x5e, (%r15)
jne 0x4720
cmpb $0x0, 0x1(%r15)
je 0x4720
incq %r15
andl $-0x3, %ecx
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3160
testq %rax, %rax
je 0x48ff
cmpl $0x0, (%rbx)
jne 0x48ff
movq %rax, %r15
movq 0x8(%rbx), %rax
leaq -0x60(%rax), %rcx
cmpq $-0x20, %rcx
jb 0x48ff
cmpl $0x0, 0x10(%rbx)
jne 0x48ff
cmpq $0x40, %rax
sete %cl
cmpq $0x5b, %rax
setae %dl
orb %cl, %dl
jne 0x470c
orq $0x20, %rax
movq %rax, 0x8(%rbx)
movl $0x4, 0x10(%rbx)
movq %rbx, %rdi
callq 0x3a94
jmp 0x49b8
movq %rdi, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
movl %ecx, %eax
andl $0x1, %eax
movl %ecx, %edx
shrl %edx
andl $0x2, %edx
orl %eax, %edx
movl %ecx, %eax
shrl $0x3, %eax
andl $0x4, %eax
orl %edx, %eax
imulq $0x18, %rax, %rax
leaq 0x5dd3(%rip), %r14      # 0xa520
addq %rax, %r14
movl %ecx, 0x8(%rsp)
testb $0x10, %cl
pushq $0x2d
popq %rax
pushq $0x20
popq %rcx
cmovel %eax, %ecx
movl %ecx, 0x20(%rsp)
xorl %r12d, %r12d
movq %r15, %rdi
movl 0x20(%rsp), %esi
callq 0x3110
testq %rax, %rax
je 0x480d
movq %rax, %rbx
movq %rax, %r13
subq %r15, %r13
movq 0x8(%r14), %rbp
movq %rbp, %rdi
callq 0x3100
cmpq %rax, %r13
jne 0x47ab
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30d0
pushq $0x2
popq %rcx
testl %eax, %eax
je 0x47f6
movq 0x10(%r14), %rbp
movq %rbp, %rdi
callq 0x3100
cmpq %rax, %r13
jne 0x47d1
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30d0
pushq $0x4
popq %rcx
testl %eax, %eax
je 0x47f6
movq (%r14), %rbp
movq %rbp, %rdi
callq 0x3100
cmpq %rax, %r13
jne 0x480d
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30d0
pushq $0x1
popq %rcx
testl %eax, %eax
jne 0x480d
orl %ecx, %r12d
movq 0x28(%rsp), %rax
movl %r12d, 0x10(%rax)
incq %rbx
movq %rbx, %r15
jmp 0x4767
movq 0x28(%rsp), %rbp
leaq 0x8(%rbp), %r12
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl 0x8(%rsp), %ecx
callq 0x3f67
testq %rax, %rax
je 0x4841
movl $0x2, (%rbp)
movq %rax, %r15
jmp 0x49ad
leaq 0x2964(%rip), %rsi      # 0x71ac
movq %rsp, %rcx
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x31d0
cmpl $0x1, %eax
jne 0x486d
movl $0x1, (%rbp)
addq (%rsp), %r15
jmp 0x49ad
leaq 0x293f(%rip), %rsi      # 0x71b3
leaq 0x30(%rsp), %rdx
leaq 0x24(%rsp), %rcx
movq %rsp, %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x31d0
cmpl $0x2, %eax
jne 0x48c9
addq (%rsp), %r15
movl $0x3, (%rbp)
leaq 0x5d3e(%rip), %r13      # 0xa5e0
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbx
cmpq $0x4, %r14
je 0x492f
movq (%r13), %rdi
movq %rbx, %rsi
callq 0x3170
testl %eax, %eax
je 0x4907
incq %r14
addq $0x8, %r13
jmp 0x48aa
movq %r15, %rdi
callq 0x3100
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x49ca
cmpl $0x1, %eax
jne 0x48ff
andl $0x0, (%rbp)
movq %rbp, %rdi
callq 0x3a94
addq 0x10(%rsp), %r15
jmp 0x49ad
xorl %r15d, %r15d
jmp 0x49b8
leal -0x1(%r14), %eax
cmpl $0x2, %eax
jae 0x4927
movb 0x24(%rsp), %al
decb %al
movzbl %al, %ecx
orb $0x20, %al
cmpq $0x2, %r14
movzbl %al, %eax
cmovnel %ecx, %eax
jmp 0x4931
movb $0x3, %al
cmpl $0x3, %r14d
je 0x4931
movb $-0x80, %al
movb %al, (%r12)
andl $0x0, 0x10(%rsp)
andl $0x0, 0xc(%rsp)
btl $0x8, 0x8(%rsp)
jb 0x494e
movq 0x18(%rsp), %rbx
jmp 0x497a
leaq 0x2872(%rip), %rsi      # 0x71c7
leaq 0xc(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rsp, %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x31d0
cmpl $0x2, %eax
movq 0x18(%rsp), %rbx
jne 0x497a
addq (%rsp), %r15
movl 0xc(%rsp), %eax
movl 0x10(%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(%rbp)
movb %al, 0xa(%rbp)
shrl $0x8, %edx
andl $0xf, %edx
shrl $0x4, %eax
andl $0x30, %eax
orl %edx, %eax
movb %al, 0xb(%rbp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3270
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq