// File: /workspace/github_c_makefile_star2_O2/neovim[P]libtermkey/termkey.c
// Function: termkey_strfkey
size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format)
{
  size_t pos = 0;
  size_t l = 0;

  struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) +
                                    !!(format & TERMKEY_FORMAT_ALTISMETA) * 2 +
                                    !!(format & TERMKEY_FORMAT_LOWERMOD) * 4];

  int wrapbracket = (format & TERMKEY_FORMAT_WRAPBRACKET) &&
                    (key->type != TERMKEY_TYPE_UNICODE || key->modifiers != 0);

  char sep = (format & TERMKEY_FORMAT_SPACEMOD) ? ' ' : '-';

  if(format & TERMKEY_FORMAT_CARETCTRL &&
     key->type == TERMKEY_TYPE_UNICODE &&
     key->modifiers == TERMKEY_KEYMOD_CTRL) {
    long codepoint = key->code.codepoint;

    // Handle some of the special cases first
    if(codepoint >= 'a' && codepoint <= 'z') {
      l = snprintf(buffer + pos, len - pos, wrapbracket ? "<^%c>" : "^%c", (char)codepoint - 0x20);
      if(l <= 0) return pos;
      pos += l;
      return pos;
    }
    else if((codepoint >= '@' && codepoint < 'A') ||
            (codepoint > 'Z' && codepoint <= '_')) {
      l = snprintf(buffer + pos, len - pos, wrapbracket ? "<^%c>" : "^%c", (char)codepoint);
      if(l <= 0) return pos;
      pos += l;
      return pos;
    }
  }

  if(wrapbracket) {
    l = snprintf(buffer + pos, len - pos, "<");
    if(l <= 0) return pos;
    pos += l;
  }

  if(key->modifiers & TERMKEY_KEYMOD_ALT) {
    l = snprintf(buffer + pos, len - pos, "%s%c", mods->alt, sep);
    if(l <= 0) return pos;
    pos += l;
  }

  if(key->modifiers & TERMKEY_KEYMOD_CTRL) {
    l = snprintf(buffer + pos, len - pos, "%s%c", mods->ctrl, sep);
    if(l <= 0) return pos;
    pos += l;
  }

  if(key->modifiers & TERMKEY_KEYMOD_SHIFT) {
    l = snprintf(buffer + pos, len - pos, "%s%c", mods->shift, sep);
    if(l <= 0) return pos;
    pos += l;
  }

  switch(key->type) {
  case TERMKEY_TYPE_UNICODE:
    if(!key->utf8[0]) // In case of user-supplied key structures
      fill_utf8(key);
    l = snprintf(buffer + pos, len - pos, "%s", key->utf8);
    break;
  case TERMKEY_TYPE_KEYSYM:
    {
      const char *name = termkey_get_keyname(tk, key->code.sym);
      if(format & TERMKEY_FORMAT_LOWERSPACE)
        l = snprint_cameltospaces(buffer + pos, len - pos, name);
      else
        l = snprintf(buffer + pos, len - pos, "%s", name);
    }
    break;
  case TERMKEY_TYPE_FUNCTION:
    l = snprintf(buffer + pos, len - pos, "%c%d",
        (format & TERMKEY_FORMAT_LOWERSPACE ? 'f' : 'F'), key->code.number);
    break;
  case TERMKEY_TYPE_MOUSE:
    {
      TermKeyMouseEvent ev;
      int button;
      int line, col;
      termkey_interpret_mouse(tk, key, &ev, &button, &line, &col);

      l = snprintf(buffer + pos, len - pos, "Mouse%s(%d)",
          evnames[ev], button);

      if(format & TERMKEY_FORMAT_MOUSE_POS) {
        if(l <= 0) return pos;
        pos += l;

        l = snprintf(buffer + pos, len - pos, " @ (%u,%u)", col, line);
      }
    }
    break;
  case TERMKEY_TYPE_POSITION:
    l = snprintf(buffer + pos, len - pos, "Position");
    break;
  case TERMKEY_TYPE_MODEREPORT:
    {
      int initial, mode, value;
      termkey_interpret_modereport(tk, key, &initial, &mode, &value);
      if(initial)
        l = snprintf(buffer + pos, len - pos, "Mode(%c%d=%d)", initial, mode, value);
      else
        l = snprintf(buffer + pos, len - pos, "Mode(%d=%d)", mode, value);
    }
  case TERMKEY_TYPE_DCS:
    l = snprintf(buffer + pos, len - pos, "DCS");
    break;
  case TERMKEY_TYPE_OSC:
    l = snprintf(buffer + pos, len - pos, "OSC");
    break;
  case TERMKEY_TYPE_UNKNOWN_CSI:
    l = snprintf(buffer + pos, len - pos, "CSI %c", key->code.number & 0xff);
    break;
  }

  if(l <= 0) return pos;
  pos += l;

  if(wrapbracket) {
    l = snprintf(buffer + pos, len - pos, ">");
    if(l <= 0) return pos;
    pos += l;
  }

  return pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebp
movq %rcx, %r12
movq %rdx, (%rsp)
movq %rsi, 0x8(%rsp)
testb $0x8, %bpl
movq %rdi, 0x10(%rsp)
jne 0x412b
xorl %r15d, %r15d
jmp 0x413f
movb $0x1, %r15b
cmpl $0x0, (%r12)
jne 0x413f
cmpl $0x0, 0x10(%r12)
setne %r15b
testb $0x10, %bpl
pushq $0x2d
popq %rax
pushq $0x20
popq %rbx
cmovel %eax, %ebx
testb $0x2, %bpl
je 0x41cc
cmpl $0x0, (%r12)
jne 0x41cc
cmpl $0x4, 0x10(%r12)
jne 0x41cc
movq 0x8(%r12), %rcx
leaq -0x61(%rcx), %rax
cmpq $0x19, %rax
ja 0x418a
leaq 0x2fd6(%rip), %rax      # 0x714d
leaq 0x2fd5(%rip), %rdx      # 0x7153
testb %r15b, %r15b
cmovneq %rax, %rdx
addl $-0x20, %ecx
jmp 0x41b4
leaq -0x40(%rcx), %rax
cmpq $0x1f, %rax
ja 0x41cc
movl $0xf8000001, %edx       # imm = 0xF8000001
btq %rax, %rdx
jae 0x41cc
leaq 0x2fa7(%rip), %rax      # 0x714d
leaq 0x2fa6(%rip), %rdx      # 0x7153
testb %r15b, %r15b
cmovneq %rax, %rdx
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x3120
movslq %eax, %r14
jmp 0x462a
testb %r15b, %r15b
je 0x41fd
leaq 0x2f7f(%rip), %rdx      # 0x7157
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x3120
testl %eax, %eax
je 0x462a
movl %r15d, 0x18(%rsp)
movslq %eax, %r15
jmp 0x4205
movl %r15d, 0x18(%rsp)
xorl %r15d, %r15d
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
andl $0x1, %ecx
andl $0x2, %eax
orl %ecx, %eax
movl %ebp, %ecx
shrl $0x3, %ecx
andl $0x4, %ecx
orl %eax, %ecx
imulq $0x18, %rcx, %rax
leaq 0x62f8(%rip), %r13      # 0xa520
addq %rax, %r13
movl 0x10(%r12), %eax
movzbl %bl, %ebx
testb $0x2, %al
jne 0x423c
movq %r15, %r14
jmp 0x4277
movq 0x8(%rsp), %rax
leaq (%rax,%r15), %rdi
movq (%rsp), %rsi
subq %r15, %rsi
movq 0x8(%r13), %rcx
leaq 0x2f02(%rip), %rdx      # 0x7159
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3120
movq %r15, %r14
testl %eax, %eax
je 0x462a
movslq %eax, %r15
addq %r15, %r14
movl 0x10(%r12), %eax
testb $0x4, %al
je 0x42b3
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
movq 0x10(%r13), %rcx
leaq 0x2ec3(%rip), %rdx      # 0x7159
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3120
testl %eax, %eax
je 0x462a
movslq %eax, %r15
addq %r15, %r14
movl 0x10(%r12), %eax
testb $0x1, %al
je 0x42ea
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
movq (%r13), %rcx
leaq 0x2e87(%rip), %rdx      # 0x7159
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3120
testl %eax, %eax
je 0x462a
movslq %eax, %r15
addq %r15, %r14
movl (%r12), %eax
incl %eax
cmpl $0x8, %eax
ja 0x45f5
leaq 0x2d3c(%rip), %rcx      # 0x703c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
movzbl 0x8(%r12), %ecx
leaq 0x2e7f(%rip), %rdx      # 0x71a5
xorl %eax, %eax
callq 0x3120
jmp 0x45f2
leaq 0x34(%rsp), %rbx
leaq 0x30(%rsp), %r15
leaq 0x1c(%rsp), %r8
leaq 0x2c(%rsp), %r9
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x30e0
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
movl (%rbx), %eax
leaq 0x626e(%rip), %rcx      # 0xa5e0
movq (%rcx,%rax,8), %rcx
movl (%r15), %r8d
leaq 0x2de3(%rip), %rdx      # 0x7163
xorl %eax, %eax
callq 0x3120
movslq %eax, %r15
btl $0x8, %ebp
jae 0x45f5
testl %eax, %eax
je 0x462a
addq %r15, %r14
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
movl 0x2c(%rsp), %ecx
movl 0x1c(%rsp), %r8d
leaq 0x2db0(%rip), %rdx      # 0x716f
jmp 0x43e7
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
andl $0x40, %ebp
shrl %ebp
orl $0x46, %ebp
movl 0x8(%r12), %r8d
leaq 0x2d79(%rip), %rdx      # 0x715e
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3120
jmp 0x45f2
movslq 0x8(%r12), %rax
leaq 0x2d46(%rip), %r12      # 0x7145
cmpq $-0x1, %rax
je 0x441d
movq 0x10(%rsp), %rcx
cmpl %eax, 0x90(%rcx)
jle 0x441d
movq 0x98(%rcx), %rcx
movq (%rcx,%rax,8), %r12
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
testb $0x40, %bpl
jne 0x451f
movq (%rsp), %rsi
subq %r14, %rsi
leaq 0x32a3(%rip), %rdx      # 0x76e1
movq %r12, %rcx
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
movslq %r13d, %r15
jmp 0x45f5
leaq 0x34(%rsp), %rbx
leaq 0x30(%rsp), %rbp
leaq 0x1c(%rsp), %r15
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x30b0
movl (%rbx), %ecx
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
movl (%rbp), %r8d
movl (%r15), %r9d
testl %ecx, %ecx
je 0x45c0
leaq 0x2ce3(%rip), %rdx      # 0x7183
xorl %eax, %eax
callq 0x3120
jmp 0x45d4
leaq 0x14(%r12), %rbx
cmpb $0x0, 0x14(%r12)
jne 0x44c1
movq %r12, %rdi
callq 0x3a94
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
leaq 0x3209(%rip), %rdx      # 0x76e1
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3120
jmp 0x45f2
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
leaq 0x2c7c(%rip), %rdx      # 0x717a
jmp 0x45eb
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
leaq 0x2c87(%rip), %rdx      # 0x71a1
jmp 0x45eb
movq %r14, %rax
notq %rax
addq (%rsp), %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r14, 0x20(%rsp)
cmpq 0x10(%rsp), %r13
jae 0x4644
movq %rdi, %r14
movb (%r12), %al
testb %al, %al
je 0x463c
movsbq %al, %rbx
callq 0x32f0
movq (%rax), %rcx
movzwl (%rcx,%rbx,2), %ebp
btl $0x8, %ebp
jae 0x4595
testl %r15d, %r15d
je 0x4595
cmpq $0x0, 0x8(%rsp)
je 0x457e
movb $0x20, (%r14,%r13)
incq %r13
cmpq 0x10(%rsp), %r13
jae 0x463c
movq (%rax), %rax
movsbq (%r12), %rbx
movzwl (%rax,%rbx,2), %ebp
andl $0x200, %ebp            # imm = 0x200
callq 0x32e0
movq (%rax), %rax
incq %r12
movb (%rax,%rbx,4), %al
movb %al, (%r14,%r13)
movq %r14, %rdi
incq %r13
movl %ebp, %r15d
movq 0x20(%rsp), %r14
jmp 0x4539
leaq 0x2bca(%rip), %rdx      # 0x7191
movl %r8d, %ecx
movl %r9d, %r8d
xorl %eax, %eax
callq 0x3120
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %rdi
movq (%rsp), %rsi
subq %r14, %rsi
leaq 0x2bb2(%rip), %rdx      # 0x719d
xorl %eax, %eax
callq 0x3120
movslq %eax, %r15
testq %r15, %r15
je 0x462a
addq %r15, %r14
cmpb $0x0, 0x18(%rsp)
je 0x462a
movq 0x8(%rsp), %rdi
addq %r14, %rdi
movq (%rsp), %rsi
subq %r14, %rsi
leaq 0x2b37(%rip), %rdx      # 0x7151
xorl %eax, %eax
callq 0x3120
testl %eax, %eax
je 0x462a
cltq
addq %rax, %r14
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq 0x20(%rsp), %r14
movb $0x0, (%rdi,%r13)
movsbq (%r12), %rbx
testq %rbx, %rbx
je 0x444b
callq 0x32f0
movq (%rax), %rax
movzwl (%rax,%rbx,2), %eax
movl %eax, %ecx
shrl $0x8, %ecx
testl %r15d, %r15d
setne %dl
andb %cl, %dl
movzbl %dl, %ecx
andl $0x200, %eax            # imm = 0x200
incq %r12
addq %rcx, %r13
incq %r13
movl %eax, %r15d
jmp 0x4649