// File: /workspace/github_c_makefile_star2_O0/neovim[P]libtermkey/driver-ti.c
// Function: load_terminfo
static int load_terminfo(TermKeyTI *ti)
{
  int i;

#ifdef HAVE_UNIBILIUM
  unibi_term *unibi = ti->unibi;
#else
  {
    int err;

    /* Have to cast away the const. But it's OK - we know terminfo won't really
    * modify term */
    if(setupterm((char*)ti->term, 1, &err) != OK)
      return 0;
  }
#endif

  ti->root = new_node_arr(0, 0xff);
  if(!ti->root)
    return 0;

  /* First the regular key strings
   */
  for(i = 0; funcs[i].funcname; i++) {
    char name[MAX_FUNCNAME + 5 + 1];

    sprintf(name, "key_%s", funcs[i].funcname);
    if(!try_load_terminfo_key(ti, name, &(struct keyinfo){
          .type = funcs[i].type,
          .sym  = funcs[i].sym,
          .modifier_mask = funcs[i].mods,
          .modifier_set  = funcs[i].mods,
      }))
      continue;

    /* Maybe it has a shifted version */
    sprintf(name, "key_s%s", funcs[i].funcname);
    try_load_terminfo_key(ti, name, &(struct keyinfo){
        .type = funcs[i].type,
        .sym  = funcs[i].sym,
        .modifier_mask = funcs[i].mods | TERMKEY_KEYMOD_SHIFT,
        .modifier_set  = funcs[i].mods | TERMKEY_KEYMOD_SHIFT,
    });
  }

  /* Now the F<digit> keys
   */
  for(i = 1; i < 255; i++) {
    char name[9];
    sprintf(name, "key_f%d", i);
    if(!try_load_terminfo_key(ti, name, &(struct keyinfo){
          .type = TERMKEY_TYPE_FUNCTION,
          .sym  = i,
          .modifier_mask = 0,
          .modifier_set  = 0,
      }))
      break;
  }

  /* Finally mouse mode */
  {
    const char *value = NULL;

#ifdef HAVE_UNIBILIUM
    if(ti->unibi)
      value = unibi_get_str_by_name(ti->unibi, "key_mouse");
#else
    if(ti->term)
      value = tigetstr("key_mouse");
#endif

    if(ti->tk->ti_getstr_hook)
      value = (ti->tk->ti_getstr_hook)("key_mouse", value, ti->tk->ti_getstr_hook_data);

    /* Some terminfos (e.g. xterm-1006) claim a different key_mouse that won't
     * give X10 encoding. We'll only accept this if it's exactly "\e[M"
     */
    if(value && streq(value, "\x1b[M")) {
      struct trie_node *node = new_node_key(TERMKEY_TYPE_MOUSE, 0, 0, 0);
      insert_seq(ti, value, node);
    }
  }

  /* Take copies of these terminfo strings, in case we build multiple termkey
   * instances for multiple different termtypes, and it's different by the
   * time we want to use it
   */
#ifdef HAVE_UNIBILIUM
  const char *keypad_xmit = unibi ?
    unibi_get_str(unibi, unibi_keypad_xmit) :
    NULL;
#endif

  if(keypad_xmit)
    ti->start_string = strdup(keypad_xmit);
  else
    ti->start_string = NULL;

#ifdef HAVE_UNIBILIUM
  const char *keypad_local = unibi ?
    unibi_get_str(unibi, unibi_keypad_local) :
    NULL;
#endif

  if(keypad_local)
    ti->stop_string = strdup(keypad_local);
  else
    ti->stop_string = NULL;

#ifdef HAVE_UNIBILIUM
  if(unibi)
    unibi_destroy(unibi);

  ti->unibi = NULL;
#else
  if(ti->term)
    free(ti->term);

  ti->term = NULL;
#endif

  ti->root = compress_trie(ti->root);

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
leaq -0x18(%rbp), %rdx
callq 0x3230
cmpl $0x0, %eax
je 0x8ac6
movl $0x0, -0x4(%rbp)
jmp 0x8e3d
xorl %edi, %edi
movl $0xff, %esi
callq 0x8e50
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x8af4
movl $0x0, -0x4(%rbp)
jmp 0x8e3d
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x4bca(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x8c64
leaq -0x27(%rbp), %rdi
movslq -0x14(%rbp), %rcx
leaq 0x4baa(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
leaq 0x1876(%rip), %rsi      # 0xa3ad
movb $0x0, %al
callq 0x32b0
movq -0x10(%rbp), %rdi
leaq -0x27(%rbp), %rsi
movslq -0x14(%rbp), %rcx
leaq 0x4b7f(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x4b67(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x34(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x4b4f(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x30(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x4b37(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x2c(%rbp)
leaq -0x38(%rbp), %rdx
callq 0x8f00
testb $0x1, %al
jne 0x8bb8
jmp 0x8c56
leaq -0x27(%rbp), %rdi
movslq -0x14(%rbp), %rcx
leaq 0x4b09(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
leaq 0x17dc(%rip), %rsi      # 0xa3b4
movb $0x0, %al
callq 0x32b0
movq -0x10(%rbp), %rdi
leaq -0x27(%rbp), %rsi
movslq -0x14(%rbp), %rcx
leaq 0x4ade(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x4ac6(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x4aae(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
orl $0x1, %eax
movl %eax, -0x40(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x4a93(%rip), %rax      # 0xd6d0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
orl $0x1, %eax
movl %eax, -0x3c(%rbp)
leaq -0x48(%rbp), %rdx
callq 0x8f00
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8afb
movl $0x1, -0x14(%rbp)
cmpl $0xff, -0x14(%rbp)
jge 0x8cc8
leaq -0x51(%rbp), %rdi
movl -0x14(%rbp), %edx
leaq 0x173a(%rip), %rsi      # 0xa3bc
movb $0x0, %al
callq 0x32b0
movq -0x10(%rbp), %rdi
leaq -0x51(%rbp), %rsi
movl $0x1, -0x64(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x58(%rbp)
leaq -0x64(%rbp), %rdx
callq 0x8f00
testb $0x1, %al
jne 0x8cbb
jmp 0x8cc8
jmp 0x8cbd
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8c6b
movq $0x0, -0x70(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x8ceb
leaq 0x16e2(%rip), %rdi      # 0xa3c4
callq 0x3290
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x78(%rax)
je 0x8d23
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x78(%rax), %rax
movq -0x70(%rbp), %rsi
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq 0x80(%rcx), %rdx
leaq 0x16a7(%rip), %rdi      # 0xa3c4
callq *%rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x8d64
movq -0x70(%rbp), %rdi
leaq 0x1699(%rip), %rsi      # 0xa3ce
callq 0x3170
cmpl $0x0, %eax
jne 0x8d64
movl $0x3, %edi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x8fd0
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x9050
movq 0x426d(%rip), %rax      # 0xcfd8
movq (%rax), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x2c8(%rax)
je 0x8da3
movq 0x4255(%rip), %rax      # 0xcfd8
movq (%rax), %rax
movq 0x20(%rax), %rax
movq 0x2c8(%rax), %rdi
callq 0x32d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x8daf
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq 0x4222(%rip), %rax      # 0xcfd8
movq (%rax), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x2c0(%rax)
je 0x8dee
movq 0x420a(%rip), %rax      # 0xcfd8
movq (%rax), %rax
movq 0x20(%rax), %rax
movq 0x2c0(%rax), %rdi
callq 0x32d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x8dfa
movq -0x10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x8e12
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3050
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x91f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)