// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x31f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x37df
movl $0x0, -0x4(%rbp)
jmp 0x3a60
movq -0x10(%rbp), %rax
movslq 0x90(%rax), %rdi
shlq $0x3, %rdi
callq 0x31f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x98(%rax)
jne 0x3814
jmp 0x3a4c
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x90(%rcx), %eax
jge 0x384c
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x381b
movl $0x0, -0x1c(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x9a22(%rip), %rax      # 0xd280
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x38b6
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x9a05(%rip), %rax      # 0xd280
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %esi
movslq -0x1c(%rbp), %rcx
leaq 0x99f1(%rip), %rax      # 0xd280
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
callq 0x3240
cmpl $-0x1, %eax
jne 0x38a9
jmp 0x3a3c
jmp 0x38ab
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3853
movq -0x10(%rbp), %rdi
movl $0x2, %esi
movl $0x9, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x63e0
movq -0x10(%rbp), %rdi
movl $0x3, %esi
movl $0xd, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x63e0
movq -0x10(%rbp), %rdi
movl $0x4, %esi
movl $0x1b, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x63e0
movq $0x0, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x9d3b(%rip), %rax      # 0xd650
cmpq $0x0, (%rax,%rcx,8)
je 0x39cc
movslq -0x1c(%rbp), %rcx
leaq 0x9d25(%rip), %rax      # 0xd650
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq *%rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x394a
jmp 0x39be
movl $0x18, %edi
callq 0x31f0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x3964
jmp 0x39f0
movslq -0x1c(%rbp), %rcx
leaq 0x9ce1(%rip), %rax      # 0xd650
movq (%rax,%rcx,8), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x10(%rax)
cmpq $0x0, -0x28(%rbp)
jne 0x39aa
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x2a0(%rax)
jmp 0x39b6
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x390a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x2a0(%rax)
jne 0x39e7
callq 0x30a0
movl $0x2, (%rax)
jmp 0x3a3c
movl $0x1, -0x4(%rbp)
jmp 0x3a60
movq -0x10(%rbp), %rax
movq 0x2a0(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x3a3a
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rdi
callq *%rax
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x3050
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x39ff
jmp 0x3a3c
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0x3050
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3050
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)