// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq 0x28(%rdi), %rdi
callq 0x31c0
movq %rax, 0x10(%r14)
xorl %ebp, %ebp
testq %rax, %rax
je 0x367d
movq %rax, %r12
movslq 0x90(%r14), %rbx
leaq (,%rbx,8), %rdi
callq 0x31c0
movq %rax, 0x98(%r14)
testq %rax, %rax
je 0x3675
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
cmpq %rax, %rbx
je 0x3636
movq 0x98(%r14), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x3620
pushq $0x8
popq %rcx
leaq 0x6fc0(%rip), %rbx      # 0xa600
leaq 0x10(%rcx), %r15
cmpq $0x3d8, %r15            # imm = 0x3D8
je 0x368e
movq (%rcx,%rbx), %rdx
movl -0x8(%rcx,%rbx), %esi
movq %r14, %rdi
callq 0x3210
movq %r15, %rcx
cmpl $-0x1, %eax
jne 0x3640
movq 0x98(%r14), %rdi
callq 0x3050
movq 0x10(%r14), %r12
movq %r12, %rdi
callq 0x3050
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x2, 0x134(%r14)
andl $0x0, 0x13c(%r14)
movq $0x3, 0x174(%r14)
andl $0x0, 0x17c(%r14)
movq $0x4, 0x254(%r14)
andl $0x0, 0x25c(%r14)
leaq 0x2a0(%r14), %rbp
xorl %ebx, %ebx
xorl %r12d, %r12d
cmpq $0x10, %rbx
je 0x3728
leaq 0x72f0(%rip), %rax      # 0xa9d0
movq (%rbx,%rax), %r15
movq %r14, %rdi
movq (%rsp), %rsi
callq *0x8(%r15)
testq %rax, %rax
je 0x3722
movq %rax, %r13
pushq $0x18
popq %rdi
callq 0x31c0
testq %rax, %rax
je 0x3737
movq %r15, (%rax)
movq %r13, 0x8(%rax)
andq $0x0, 0x10(%rax)
leaq 0x10(%r12), %rcx
testq %r12, %r12
cmoveq %rbp, %rcx
movq %rax, (%rcx)
movq %rax, %r12
addq $0x8, %rbx
jmp 0x36d3
cmpq $0x0, (%rbp)
je 0x3761
pushq $0x1
popq %rbp
jmp 0x367d
movq (%rbp), %r15
xorl %ebp, %ebp
testq %r15, %r15
je 0x3665
movq (%r15), %rax
movq 0x8(%r15), %rdi
callq *0x10(%rax)
movq 0x10(%r15), %rbx
movq %r15, %rdi
callq 0x3050
movq %rbx, %r15
jmp 0x373d
callq 0x30a0
movl $0x2, (%rax)
xorl %ebp, %ebp
jmp 0x3665