// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rdx, (%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
testb $0x8, %bpl
jne 0x4278
xorl %r14d, %r14d
jmp 0x428a
movb $0x1, %r14b
cmpl $0x0, (%r15)
jne 0x428a
cmpl $0x0, 0x10(%r15)
setne %r14b
testb $0x10, %bpl
movl $0x2d, %eax
movl $0x20, %ebx
cmovel %eax, %ebx
testb $0x2, %bpl
je 0x42ec
cmpl $0x0, (%r15)
jne 0x42ec
cmpl $0x4, 0x10(%r15)
jne 0x42ec
movq 0x8(%r15), %rcx
leaq -0x61(%rcx), %rax
cmpq $0x19, %rax
ja 0x4461
leaq 0x2e6a(%rip), %rax      # 0x7131
leaq 0x2e69(%rip), %rdx      # 0x7137
movl %r14d, %r12d
testb %r14b, %r14b
cmovneq %rax, %rdx
addl $-0x20, %ecx
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
jmp 0x4496
xorl %r13d, %r13d
movq %rax, 0x20(%rsp)
testb %r14b, %r14b
je 0x432f
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %rdi
movq (%rsp), %rsi
subq %r13, %rsi
leaq 0x2e2b(%rip), %rdx      # 0x713b
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x4459
movl %r14d, 0x1c(%rsp)
movq %r13, %r12
movslq %eax, %r13
addq %r13, %r12
jmp 0x4337
movl %r14d, 0x1c(%rsp)
movq %r13, %r12
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 0x51c6(%rip), %rcx      # 0x9520
leaq (%rcx,%rax,8), %r14
testb $0x2, 0x10(%r15)
je 0x4399
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
movq 0x8(%r14), %rcx
movzbl %bl, %r8d
leaq 0x2db9(%rip), %rdx      # 0x713d
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x47e2
movslq %eax, %r13
addq %r13, %r12
testb $0x4, 0x10(%r15)
je 0x43d4
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
movq 0x10(%r14), %rcx
movzbl %bl, %r8d
leaq 0x2d7e(%rip), %rdx      # 0x713d
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x47e2
movslq %eax, %r13
addq %r13, %r12
testb $0x1, 0x10(%r15)
je 0x440e
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
movq (%r14), %rcx
movzbl %bl, %r8d
leaq 0x2d44(%rip), %rdx      # 0x713d
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x47e2
movslq %eax, %r13
addq %r13, %r12
movl (%r15), %eax
incl %eax
cmpl $0x8, %eax
movl 0x1c(%rsp), %r14d
ja 0x47af
leaq 0x2c14(%rip), %rcx      # 0x703c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
movzbl 0x8(%r15), %ecx
leaq 0x2d3c(%rip), %rdx      # 0x7189
xorl %eax, %eax
callq 0x3110
jmp 0x47ac
movq %r13, %rax
jmp 0x47e5
leaq -0x5b(%rcx), %rax
cmpq $0x5, %rax
jae 0x47f4
leaq 0x2cbb(%rip), %rax      # 0x7131
leaq 0x2cba(%rip), %rdx      # 0x7137
movl %r14d, %r12d
testb %r14b, %r14b
cmovneq %rax, %rdx
movsbl %cl, %ecx
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x3110
movslq %eax, %r13
movq %r13, %rax
testb %r14b, %r14b
movl %r12d, %r14d
jne 0x42ef
jmp 0x47e5
leaq 0x34(%rsp), %r13
leaq 0x30(%rsp), %rbx
leaq 0x28(%rsp), %r8
leaq 0x2c(%rsp), %r9
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x30d0
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
movl (%r13), %eax
leaq 0x50ea(%rip), %rcx      # 0x95e0
movq (%rcx,%rax,8), %rcx
movl (%rbx), %r8d
leaq 0x2c43(%rip), %rdx      # 0x7147
xorl %eax, %eax
callq 0x3110
movslq %eax, %r13
movb $0x1, %bl
btl $0x8, %ebp
jae 0x454b
testl %eax, %eax
je 0x4811
addq %r13, %r12
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
movl 0x2c(%rsp), %ecx
movl 0x28(%rsp), %r8d
leaq 0x2c12(%rip), %rdx      # 0x7153
xorl %eax, %eax
callq 0x3110
movslq %eax, %r13
movq 0x20(%rsp), %rax
testb %bl, %bl
jne 0x47af
jmp 0x47e5
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
andl $0x40, %ebp
shrl %ebp
orl $0x46, %ebp
movl 0x8(%r15), %r8d
leaq 0x2bc2(%rip), %rdx      # 0x7142
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3110
jmp 0x47ac
movslq 0x8(%r15), %rax
leaq 0x2b90(%rip), %rbx      # 0x7129
cmpq $-0x1, %rax
je 0x45b7
movq 0x10(%rsp), %rcx
cmpl %eax, 0x90(%rcx)
jle 0x45b7
movq 0x98(%rcx), %rcx
movq (%rcx,%rax,8), %rbx
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
testb $0x40, %bpl
jne 0x46b5
movq (%rsp), %rsi
subq %r12, %rsi
leaq 0x2df5(%rip), %rdx      # 0x73cd
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3110
movl %eax, %r15d
jmp 0x4878
leaq 0x34(%rsp), %rbx
leaq 0x30(%rsp), %rbp
leaq 0x28(%rsp), %r13
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
movq %r13, %r8
callq 0x30a0
movl (%rbx), %ecx
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
movl (%rbp), %r8d
movl (%r13), %r9d
testl %ecx, %ecx
je 0x477a
leaq 0x2b2f(%rip), %rdx      # 0x7167
xorl %eax, %eax
callq 0x3110
jmp 0x478e
leaq 0x14(%r15), %rbx
cmpb $0x0, 0x14(%r15)
jne 0x4657
movq %r15, %rdi
callq 0x3b1e
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
leaq 0x2d5f(%rip), %rdx      # 0x73cd
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3110
jmp 0x47ac
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
leaq 0x2aca(%rip), %rdx      # 0x715e
jmp 0x47a5
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
leaq 0x2ad5(%rip), %rdx      # 0x7185
jmp 0x47a5
movq %r12, %rax
notq %rax
xorl %r14d, %r14d
addq (%rsp), %rax
je 0x480c
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x480c
xorl %r14d, %r14d
movq %rdi, 0x10(%rsp)
movq %rax, 0x20(%rsp)
callq 0x32f0
movq %rbx, %r8
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rdi
xorl %r15d, %r15d
movq (%rax), %rsi
movsbq %bpl, %rcx
testb $0x1, 0x1(%rsi,%rcx,2)
je 0x4722
testl %r14d, %r14d
je 0x4722
cmpq $0x0, 0x8(%rsp)
je 0x4719
movb $0x20, (%rdi,%r15)
incq %r15
cmpq %rdx, %r15
jae 0x481e
movq %rax, %r13
movq (%rax), %rax
movsbq (%r8), %rbp
movzwl (%rax,%rbp,2), %r14d
andl $0x200, %r14d           # imm = 0x200
movq %r8, %rbx
callq 0x32e0
movq %rbx, %rcx
movq 0x20(%rsp), %rdx
movq (%rax), %rax
incq %rbx
movb (%rax,%rbp,4), %al
movq 0x10(%rsp), %rdi
movb %al, (%rdi,%r15)
incq %r15
cmpq %rdx, %r15
jae 0x4826
movb 0x1(%rcx), %bpl
movq %rbx, %r8
testb %bpl, %bpl
movq %r13, %rax
jne 0x46f6
jmp 0x4826
leaq 0x29f4(%rip), %rdx      # 0x7175
movl %r8d, %ecx
movl %r9d, %r8d
xorl %eax, %eax
callq 0x3110
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
movq (%rsp), %rsi
subq %r12, %rsi
leaq 0x29dc(%rip), %rdx      # 0x7181
xorl %eax, %eax
callq 0x3110
movslq %eax, %r13
testq %r13, %r13
je 0x47e2
addq %r13, %r12
testb %r14b, %r14b
je 0x47e2
movq 0x8(%rsp), %rdi
addq %r12, %rdi
movq (%rsp), %rsi
subq %r12, %rsi
leaq 0x2963(%rip), %rdx      # 0x7135
xorl %eax, %eax
callq 0x3110
testl %eax, %eax
je 0x47e2
cltq
addq %rax, %r12
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x40, %rcx
je 0x446f
movl %r14d, %r12d
movb $0x1, %r14b
xorl %r13d, %r13d
jmp 0x44a3
xorl %r15d, %r15d
jmp 0x4826
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %r12, %rax
jmp 0x4550
movq %r8, %rbx
movq 0x10(%rsp), %rdi
movb $0x0, (%rdi,%r15)
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x4873
callq 0x32f0
movq (%rax), %rax
incq %rbx
movsbq %bpl, %rcx
movzwl (%rax,%rcx,2), %ecx
movl %ecx, %edx
shrl $0x8, %edx
testl %r14d, %r14d
setne %sil
andb %dl, %sil
movzbl %sil, %edx
andl $0x200, %ecx            # imm = 0x200
addq %rdx, %r15
incq %r15
movb (%rbx), %bpl
incq %rbx
movl %ecx, %r14d
testb %bpl, %bpl
jne 0x483e
movl 0x1c(%rsp), %r14d
movslq %r15d, %r13
jmp 0x47af