// File: /workspace/github_c_makefile_star2_O1/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
movl $0x0, 0x10(%rdx)
testb $0x2, %cl
je 0x491d
cmpb $0x5e, (%r15)
jne 0x491d
cmpb $0x0, 0x1(%r15)
je 0x491d
incq %r15
andl $-0x3, %ecx
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3160
testq %rax, %rax
je 0x4b2f
cmpl $0x0, (%rbx)
jne 0x4b2f
movq %rax, %r15
movq 0x8(%rbx), %rax
leaq -0x60(%rax), %rcx
cmpq $-0x20, %rcx
jb 0x4b2f
cmpl $0x0, 0x10(%rbx)
jne 0x4b2f
cmpq $0x40, %rax
sete %cl
cmpq $0x5b, %rax
setge %dl
orb %cl, %dl
jne 0x4909
orq $0x20, %rax
movq %rax, 0x8(%rbx)
movl $0x4, 0x10(%rbx)
movq %rbx, %rdi
callq 0x3b1e
jmp 0x4bc1
movq %rdi, 0x28(%rsp)
movq %rbx, 0x18(%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
leaq (%rax,%rax,2), %rax
leaq 0x4bd6(%rip), %rdx      # 0x9520
leaq (%rdx,%rax,8), %r14
movl %ecx, 0x8(%rsp)
testb $0x10, %cl
movl $0x2d, %eax
movl $0x20, %r12d
cmovel %eax, %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x3100
testq %rax, %rax
je 0x4a18
movq %rax, %rbx
movq %rax, %r13
subq %r15, %r13
movq 0x8(%r14), %rbp
movq %rbp, %rdi
callq 0x30f0
cmpq %rax, %r13
jne 0x49a4
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30c0
testl %eax, %eax
je 0x49ed
movq 0x10(%r14), %rbp
movq %rbp, %rdi
callq 0x30f0
cmpq %rax, %r13
jne 0x49c7
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30c0
testl %eax, %eax
je 0x49f4
movq (%r14), %rbp
movq %rbp, %rdi
callq 0x30f0
cmpq %rax, %r13
jne 0x49e9
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30c0
testl %eax, %eax
je 0x49fb
xorl %eax, %eax
jmp 0x4a10
movl $0x2, %eax
jmp 0x4a00
movl $0x4, %eax
jmp 0x4a00
movl $0x1, %eax
movq 0x18(%rsp), %rcx
orl %eax, 0x10(%rcx)
incq %rbx
movb $0x1, %al
movq %rbx, %r15
testb %al, %al
jne 0x4964
movq 0x18(%rsp), %rbx
leaq 0x8(%rbx), %r12
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl 0x8(%rsp), %ecx
callq 0x408a
testq %rax, %rax
je 0x4a4b
movl $0x2, (%rbx)
movq %rax, %r15
jmp 0x4bb6
leaq 0x273e(%rip), %rsi      # 0x7190
movq %rsp, %rcx
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x31d0
cmpl $0x1, %eax
jne 0x4a76
movl $0x1, (%rbx)
addq (%rsp), %r15
jmp 0x4bb6
leaq 0x271a(%rip), %rsi      # 0x7197
leaq 0x30(%rsp), %rdx
leaq 0x24(%rsp), %rcx
movq %rsp, %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x31d0
cmpl $0x2, %eax
jne 0x4af7
addq (%rsp), %r15
movl $0x3, (%rbx)
leaq 0x4b36(%rip), %r13      # 0x95e0
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbx
movq (%r13), %rdi
movq %rbx, %rsi
callq 0x3170
testl %eax, %eax
je 0x4ad2
incq %r14
addq $0x8, %r13
cmpq $0x4, %r14
jne 0x4ab2
xorl %r14d, %r14d
leal -0x1(%r14), %eax
cmpl $0x2, %eax
movq 0x18(%rsp), %rbx
jae 0x4b37
movb 0x24(%rsp), %al
decb %al
movzbl %al, %ecx
orb $0x20, %al
cmpl $0x2, %r14d
movzbl %al, %eax
cmovnel %ecx, %eax
jmp 0x4b41
movq %r15, %rdi
callq 0x30f0
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x4bd3
cmpl $0x1, %eax
jne 0x4b2f
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x3b1e
addq 0x10(%rsp), %r15
jmp 0x4bb6
xorl %r15d, %r15d
jmp 0x4bc1
movb $0x3, %al
cmpl $0x3, %r14d
je 0x4b41
movb $-0x80, %al
movb %al, (%r12)
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movl %eax, 0xc(%rsp)
btl $0x8, 0x8(%rsp)
movq 0x28(%rsp), %r14
jae 0x4b83
leaq 0x2648(%rip), %rsi      # 0x71ab
leaq 0xc(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rsp, %r8
movq %r15, %rdi
xorl %eax, %eax
callq 0x31d0
cmpl $0x2, %eax
jne 0x4b83
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(%rbx)
movb %al, 0xa(%rbx)
shrl $0x8, %edx
andl $0xf, %edx
shrl $0x4, %eax
andl $0x30, %eax
orl %edx, %eax
movb %al, 0xb(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3270
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq