// File: /workspace/github_c_makefile_star2_O3/neovim[P]libtermkey/termkey.c
// Function: termkey_init
static int termkey_init(TermKey *tk, const char *term)
{
  tk->buffer = malloc(tk->buffsize);
  if(!tk->buffer)
    return 0;

  tk->keynames = malloc(sizeof(tk->keynames[0]) * tk->nkeynames);
  if(!tk->keynames)
    goto abort_free_buffer;

  int i;
  for(i = 0; i < tk->nkeynames; i++)
    tk->keynames[i] = NULL;

  for(i = 0; keynames[i].name; i++)
    if(termkey_register_keyname(tk, keynames[i].sym, keynames[i].name) == -1)
      goto abort_free_keynames;

  register_c0(tk, TERMKEY_SYM_TAB,    0x09, NULL);
  register_c0(tk, TERMKEY_SYM_ENTER,  0x0d, NULL);
  register_c0(tk, TERMKEY_SYM_ESCAPE, 0x1b, NULL);

  struct TermKeyDriverNode *tail = NULL;

  for(i = 0; drivers[i]; i++) {
    void *info = (*drivers[i]->new_driver)(tk, term);
    if(!info)
      continue;

#ifdef DEBUG
    fprintf(stderr, "Loading the %s driver...\n", drivers[i]->name);
#endif

    struct TermKeyDriverNode *thisdrv = malloc(sizeof(*thisdrv));
    if(!thisdrv)
      goto abort_free_drivers;

    thisdrv->driver = drivers[i];
    thisdrv->info = info;
    thisdrv->next = NULL;

    if(!tail)
      tk->drivers = thisdrv;
    else
      tail->next = thisdrv;

    tail = thisdrv;

#ifdef DEBUG
    fprintf(stderr, "Loaded %s driver\n", drivers[i]->name);
#endif
  }

  if(!tk->drivers) {
    errno = ENOENT;
    goto abort_free_keynames;
  }

  return 1;

abort_free_drivers:
  for(struct TermKeyDriverNode *p = tk->drivers; p; ) {
    (*p->driver->free_driver)(p->info);
    struct TermKeyDriverNode *next = p->next;
    free(p);
    p = next;
  }

abort_free_keynames:
  free(tk->keynames);

abort_free_buffer:
  free(tk->buffer);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, (%rsp)
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
callq 0x31c0
movq %rax, %r15
movq %rax, 0x10(%rbx)
xorl %eax, %eax
testq %r15, %r15
je 0x37cb
movslq 0x90(%rbx), %r12
leaq (,%r12,8), %rdi
callq 0x31c0
movq %rax, 0x98(%rbx)
testq %rax, %rax
je 0x37c1
testl %r12d, %r12d
jle 0x36a0
xorl %eax, %eax
movq 0x98(%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
incq %rax
cmpq %rax, %r12
jne 0x3689
leaq 0x3b2e(%rip), %rdx      # 0x71d5
xorl %r15d, %r15d
leaq 0x6f4f(%rip), %r12      # 0xa600
movl (%r15,%r12), %esi
movq %rbx, %rdi
callq 0x3210
cmpl $-0x1, %eax
je 0x37b1
movq 0x18(%r15,%r12), %rdx
addq $0x10, %r15
cmpq $0x3c0, %r15            # imm = 0x3C0
jne 0x36b1
movq $0x2, 0x134(%rbx)
xorl %r12d, %r12d
movl %r12d, 0x13c(%rbx)
movq $0x3, 0x174(%rbx)
movl %r12d, 0x17c(%rbx)
movq $0x4, 0x254(%rbx)
movl %r12d, 0x25c(%rbx)
leaq 0x2a0(%rbx), %r13
xorl %ebp, %ebp
leaq 0x72af(%rip), %rax      # 0xa9d0
movq (%r12,%rax), %r14
movq %rbx, %rdi
movq (%rsp), %rsi
callq *0x8(%r14)
testq %rax, %rax
je 0x3767
movq %rax, %r15
movl $0x18, %edi
callq 0x31c0
testq %rax, %rax
je 0x378a
movq %r14, (%rax)
movq %r15, 0x8(%rax)
movq $0x0, 0x10(%rax)
leaq 0x10(%rbp), %rcx
testq %rbp, %rbp
cmoveq %r13, %rcx
movq %rax, (%rcx)
movq %rax, %rbp
addq $0x8, %r12
cmpq $0x10, %r12
jne 0x371a
movl $0x1, %eax
cmpq $0x0, (%r13)
jne 0x37cb
callq 0x3090
movl $0x2, (%rax)
jmp 0x37b1
movq (%r13), %r14
testq %r14, %r14
je 0x37b1
movq (%r14), %rax
movq 0x8(%r14), %rdi
callq *0x10(%rax)
movq 0x10(%r14), %r15
movq %r14, %rdi
callq 0x3050
movq %r15, %r14
testq %r15, %r15
jne 0x3793
movq 0x98(%rbx), %rdi
callq 0x3050
movq 0x10(%rbx), %r15
movq %r15, %rdi
callq 0x3050
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq