// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %r8d, %ebp
movq %rcx, %r12
movq %rdx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
testb $0x8, %bpl
jne 0x4220
xorl %r14d, %r14d
jmp 0x4234
movb $0x1, %r14b
cmpl $0x0, (%r12)
jne 0x4234
cmpl $0x0, 0x10(%r12)
setne %r14b
testb $0x10, %bpl
movl $0x2d, %eax
movl $0x20, %r13d
cmovel %eax, %r13d
testb $0x2, %bpl
je 0x42c3
cmpl $0x0, (%r12)
jne 0x42c3
cmpl $0x4, 0x10(%r12)
jne 0x42c3
movq 0x8(%r12), %rcx
leaq -0x61(%rcx), %rax
cmpq $0x19, %rax
ja 0x4285
leaq 0x2edb(%rip), %rax      # 0x714d
leaq 0x2eda(%rip), %rdx      # 0x7153
testb %r14b, %r14b
cmovneq %rax, %rdx
addl $-0x20, %ecx
jmp 0x42a4
leaq -0x5b(%rcx), %rax
cmpq $0x5, %rax
jae 0x42bd
leaq 0x2eb7(%rip), %rax      # 0x714d
leaq 0x2eb6(%rip), %rdx      # 0x7153
testb %r14b, %r14b
cmovneq %rax, %rdx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3110
movslq %eax, %rbx
jmp 0x4765
cmpq $0x40, %rcx
je 0x428f
testb %r14b, %r14b
je 0x42f9
leaq 0x2e88(%rip), %rdx      # 0x7157
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x4765
movq %r15, 0x18(%rsp)
movl %r14d, 0x24(%rsp)
movslq %eax, %r15
jmp 0x4306
movq %r15, 0x18(%rsp)
movl %r14d, 0x24(%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
leaq (%rcx,%rcx,2), %rax
leaq 0x61f7(%rip), %rcx      # 0xa520
leaq (%rcx,%rax,8), %r14
movl 0x10(%r12), %eax
testb $0x2, %al
jne 0x433b
movq %r15, %rbx
jmp 0x4378
movq 0x10(%rsp), %rax
leaq (%rax,%r15), %rdi
movq 0x8(%rsp), %rsi
subq %r15, %rsi
movq 0x8(%r14), %rcx
movzbl %r13b, %r8d
leaq 0x2dfe(%rip), %rdx      # 0x7159
xorl %eax, %eax
callq 0x3110
movq %r15, %rbx
testl %eax, %eax
je 0x4765
movslq %eax, %r15
addq %r15, %rbx
movl 0x10(%r12), %eax
testb $0x4, %al
je 0x43b6
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movq 0x10(%r14), %rcx
movzbl %r13b, %r8d
leaq 0x2dbd(%rip), %rdx      # 0x7159
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x4765
movslq %eax, %r15
addq %r15, %rbx
movl 0x10(%r12), %eax
testb $0x1, %al
je 0x43ee
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movq (%r14), %rcx
movzbl %r13b, %r8d
leaq 0x2d80(%rip), %rdx      # 0x7159
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x4765
movslq %eax, %r15
addq %r15, %rbx
movl (%r12), %eax
incl %eax
cmpl $0x8, %eax
ja 0x472f
leaq 0x2c38(%rip), %rcx      # 0x703c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movzbl 0x8(%r12), %ecx
leaq 0x2d7a(%rip), %rdx      # 0x71a5
xorl %eax, %eax
callq 0x3110
jmp 0x472c
leaq 0x34(%rsp), %r13
leaq 0x30(%rsp), %r14
leaq 0x28(%rsp), %r8
leaq 0x2c(%rsp), %r9
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x30d0
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movl (%r13), %eax
leaq 0x6166(%rip), %rcx      # 0xa5e0
movq (%rcx,%rax,8), %rcx
movl (%r14), %r8d
leaq 0x2cdb(%rip), %rdx      # 0x7163
xorl %eax, %eax
callq 0x3110
movslq %eax, %r15
btl $0x8, %ebp
jae 0x472f
testl %eax, %eax
je 0x4765
addq %r15, %rbx
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movl 0x2c(%rsp), %ecx
movl 0x28(%rsp), %r8d
leaq 0x2ca7(%rip), %rdx      # 0x716f
jmp 0x44f1
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
andl $0x40, %ebp
shrl %ebp
orl $0x46, %ebp
movl 0x8(%r12), %r8d
leaq 0x2c6f(%rip), %rdx      # 0x715e
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3110
jmp 0x472c
movslq 0x8(%r12), %rax
leaq 0x2c3c(%rip), %r13      # 0x7145
cmpq $-0x1, %rax
je 0x4527
movq 0x18(%rsp), %rcx
cmpl %eax, 0x90(%rcx)
jle 0x4527
movq 0x98(%rcx), %rcx
movq (%rcx,%rax,8), %r13
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
testb $0x40, %bpl
jne 0x462d
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
leaq 0x3204(%rip), %rdx      # 0x774d
movq %r13, %rcx
xorl %eax, %eax
callq 0x3110
movl %eax, %r12d
jmp 0x47cf
leaq 0x34(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0x28(%rsp), %r14
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %r14, %r8
callq 0x30a0
movl (%r13), %ecx
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movl (%rbp), %r8d
movl (%r14), %r9d
testl %ecx, %ecx
je 0x46f9
leaq 0x2bd8(%rip), %rdx      # 0x7183
xorl %eax, %eax
callq 0x3110
jmp 0x470d
leaq 0x14(%r12), %r13
cmpb $0x0, 0x14(%r12)
jne 0x45cc
movq %r12, %rdi
callq 0x3b05
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
leaq 0x3169(%rip), %rdx      # 0x774d
movq %r13, %rcx
xorl %eax, %eax
callq 0x3110
jmp 0x472c
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
leaq 0x2b6f(%rip), %rdx      # 0x717a
jmp 0x4725
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
leaq 0x2b79(%rip), %rdx      # 0x71a1
jmp 0x4725
movq %rbx, %rax
notq %rax
xorl %r15d, %r15d
addq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
je 0x4777
movb (%r13), %bpl
testb %bpl, %bpl
je 0x4777
xorl %r15d, %r15d
movq %rdi, 0x38(%rsp)
callq 0x32f0
movq 0x38(%rsp), %rdi
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
movq 0x40(%rsp), %rax
movq (%rax), %rax
movsbq %bpl, %rbp
movzwl (%rax,%rbp,2), %eax
btl $0x8, %eax
jae 0x46b4
testl %r15d, %r15d
je 0x46b4
cmpq $0x0, 0x10(%rsp)
je 0x4698
movb $0x20, (%rdi,%r12)
incq %r12
cmpq 0x18(%rsp), %r12
jae 0x477f
movq 0x40(%rsp), %rax
movq (%rax), %rax
movsbq (%r13), %rbp
movzwl (%rax,%rbp,2), %eax
movl %eax, %r15d
andl $0x200, %r15d           # imm = 0x200
callq 0x32e0
movq (%rax), %rax
leaq 0x1(%r13), %r14
movb (%rax,%rbp,4), %al
movq 0x38(%rsp), %rdi
movb %al, (%rdi,%r12)
incq %r12
cmpq 0x18(%rsp), %r12
jae 0x4782
movb 0x1(%r13), %bpl
movq %r14, %r13
testb %bpl, %bpl
jne 0x466d
jmp 0x4782
leaq 0x2a91(%rip), %rdx      # 0x7191
movl %r8d, %ecx
movl %r9d, %r8d
xorl %eax, %eax
callq 0x3110
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
leaq 0x2a78(%rip), %rdx      # 0x719d
xorl %eax, %eax
callq 0x3110
movslq %eax, %r15
testq %r15, %r15
je 0x4765
addq %r15, %rbx
cmpb $0x0, 0x24(%rsp)
je 0x4765
movq 0x10(%rsp), %rdi
addq %rbx, %rdi
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
leaq 0x29fc(%rip), %rdx      # 0x7151
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x4765
cltq
addq %rax, %rbx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %r14
xorl %r12d, %r12d
jmp 0x4782
movq %r13, %r14
movb $0x0, (%rdi,%r12)
movb (%r14), %bpl
testb %bpl, %bpl
je 0x47cf
callq 0x32f0
movq (%rax), %rax
incq %r14
movsbq %bpl, %rcx
movzwl (%rax,%rcx,2), %ecx
movl %ecx, %edx
shrl $0x8, %edx
testl %r15d, %r15d
setne %sil
andb %dl, %sil
movzbl %sil, %edx
andl $0x200, %ecx            # imm = 0x200
addq %rdx, %r12
incq %r12
movb (%r14), %bpl
incq %r14
movl %ecx, %r15d
testb %bpl, %bpl
jne 0x479a
movslq %r12d, %r15
jmp 0x472f