// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl -0x24(%rbp), %ecx
andl $0x4, %ecx
cmpl $0x0, %ecx
setne %cl
xorb $-0x1, %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shll %ecx
addl %ecx, %eax
movl -0x24(%rbp), %ecx
andl $0x20, %ecx
cmpl $0x0, %ecx
setne %cl
xorb $-0x1, %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
shll $0x2, %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x7d6e(%rip), %rax      # 0xd1a0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, 0x10(%rax)
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x551b
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5e, %eax
jne 0x551b
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x551b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
andl $-0x3, %ecx
callq 0x3160
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x54c7
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x54c7
movq -0x20(%rbp), %rax
cmpq $0x40, 0x8(%rax)
jl 0x54c7
movq -0x20(%rbp), %rax
cmpq $0x5f, 0x8(%rax)
jg 0x54c7
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x54d4
movq $0x0, -0x8(%rbp)
jmp 0x58d1
movq -0x20(%rbp), %rax
cmpq $0x41, 0x8(%rax)
jl 0x54fa
movq -0x20(%rbp), %rax
cmpq $0x5a, 0x8(%rax)
jg 0x54fa
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl $0x4, 0x10(%rax)
movq -0x20(%rbp), %rdi
callq 0x4090
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x58d1
jmp 0x551d
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %ecx
andl $0x10, %ecx
movl $0x2d, %esi
movl $0x20, %eax
cmpl $0x0, %ecx
cmovnel %eax, %esi
callq 0x3110
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x5661
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3100
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jne 0x55ac
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x30d0
cmpl $0x0, %eax
jne 0x55ac
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x10(%rax)
jmp 0x5650
movq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3100
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jne 0x55fc
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x30d0
cmpl $0x0, %eax
jne 0x55fc
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x10(%rax)
jmp 0x564e
movq -0x40(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x3100
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jne 0x564a
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x30d0
cmpl $0x0, %eax
jne 0x564a
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x564c
jmp 0x5661
jmp 0x564e
jmp 0x5650
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x551d
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x8, %rdx
movl -0x24(%rbp), %ecx
callq 0x49a0
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x569a
movq -0x20(%rbp), %rax
movl $0x2, (%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x58bc
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
addq $0x8, %rdx
leaq 0x4ae7(%rip), %rsi      # 0xa194
leaq -0x50(%rbp), %rcx
movb $0x0, %al
callq 0x3200
cmpl $0x1, %eax
jne 0x56d8
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x50(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x58ba
movq -0x18(%rbp), %rdi
leaq -0x80(%rbp), %rdx
leaq 0x4ab4(%rip), %rsi      # 0xa19b
leaq -0x5c(%rbp), %rcx
leaq -0x50(%rbp), %r8
movb $0x0, %al
callq 0x3200
cmpl $0x2, %eax
jne 0x5857
movq -0x50(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl $0x3, (%rax)
movl $0x0, -0x84(%rbp)
movq $0x0, -0x90(%rbp)
cmpq $0x4, -0x90(%rbp)
jae 0x577d
movq -0x90(%rbp), %rcx
leaq 0x7b1e(%rip), %rax      # 0xd260
movq (%rax,%rcx,8), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3170
cmpl $0x0, %eax
jne 0x5767
movq -0x90(%rbp), %rax
addq $0x0, %rax
movl %eax, -0x84(%rbp)
jmp 0x577d
jmp 0x5769
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x572a
movl -0x84(%rbp), %eax
movl %eax, -0xbc(%rbp)
decl %eax
subl $0x2, %eax
jb 0x579f
jmp 0x5792
movl -0xbc(%rbp), %eax
subl $0x3, %eax
je 0x57c5
jmp 0x57d1
movl -0x5c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x94(%rbp)
cmpl $0x2, -0x84(%rbp)
jne 0x57c3
movl -0x94(%rbp), %eax
orl $0x20, %eax
movl %eax, -0x94(%rbp)
jmp 0x57db
movl $0x3, -0x94(%rbp)
jmp 0x57db
movl $0x80, -0x94(%rbp)
movl -0x94(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x8(%rax)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x24(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x5840
movq -0x18(%rbp), %rdi
leaq 0x4999(%rip), %rsi      # 0xa1af
leaq -0x9c(%rbp), %rdx
leaq -0x98(%rbp), %rcx
leaq -0x50(%rbp), %r8
movb $0x0, %al
callq 0x3200
cmpl $0x2, %eax
jne 0x5840
movq -0x50(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rdi
movl -0x9c(%rbp), %esi
movl -0x98(%rbp), %edx
callq 0x58e0
jmp 0x58b8
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3100
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rdx
addq $0x8, %rdx
leaq -0x48(%rbp), %rcx
callq 0x5960
cmpl $0x1, %eax
jne 0x58ac
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x4090
movq -0x48(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x58b6
movq $0x0, -0x8(%rbp)
jmp 0x58d1
jmp 0x58b8
jmp 0x58ba
jmp 0x58bc
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x32a0
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nop