// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
callq 0x31c0
movq %rax, %rcx
movq %rax, 0x10(%rbx)
xorl %eax, %eax
testq %rcx, %rcx
je 0x37e4
movslq 0x90(%rbx), %r15
leaq (,%r15,8), %rdi
callq 0x31c0
movq %rax, 0x98(%rbx)
testq %rax, %rax
je 0x37d9
testl %r15d, %r15d
jle 0x36a4
xorl %eax, %eax
movq 0x98(%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0x368d
leaq 0x3b0e(%rip), %rdx      # 0x71b9
xorl %r15d, %r15d
leaq 0x5f4b(%rip), %r12      # 0x9600
movl (%r15,%r12), %esi
movq %rbx, %rdi
callq 0x3210
cmpl $-0x1, %eax
je 0x37cd
movq 0x18(%r15,%r12), %rdx
addq $0x10, %r15
cmpq $0x3c0, %r15            # imm = 0x3C0
jne 0x36b5
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), %rax
movq %rax, (%rsp)
xorl %r13d, %r13d
leaq 0x62a6(%rip), %rax      # 0x99d0
movq (%r12,%rax), %rbp
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rbp)
testq %rax, %rax
je 0x3773
movq %rax, %r15
movl $0x18, %edi
callq 0x31c0
testq %rax, %rax
je 0x3777
movq %rbp, (%rax)
movq %r15, 0x8(%rax)
leaq 0x10(%r13), %rcx
testq %r13, %r13
cmoveq (%rsp), %rcx
movq $0x0, 0x10(%rax)
movq %rax, (%rcx)
xorl %ecx, %ecx
movq %rax, %r13
jmp 0x3779
xorl %ecx, %ecx
jmp 0x3779
movb $0x1, %cl
testb %cl, %cl
jne 0x37a3
addq $0x8, %r12
cmpq $0x10, %r12
jne 0x3723
movl $0x1, %eax
cmpq $0x0, 0x2a0(%rbx)
jne 0x37e4
callq 0x3090
movl $0x2, (%rax)
jmp 0x37cd
movq 0x2a0(%rbx), %r14
testq %r14, %r14
je 0x37cd
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 0x37af
movq 0x98(%rbx), %rdi
callq 0x3050
movq 0x10(%rbx), %rdi
callq 0x3050
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq