// File: /workspace/github_c_makefile_star2_O0/neovim[P]libtermkey/termkey.c
// Function: termkey_waitkey
TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key)
{
  if(tk->fd == -1) {
    errno = EBADF;
    return TERMKEY_RES_ERROR;
  }

  while(1) {
    TermKeyResult ret = termkey_getkey(tk, key);

    switch(ret) {
      case TERMKEY_RES_KEY:
      case TERMKEY_RES_EOF:
      case TERMKEY_RES_ERROR:
        return ret;

      case TERMKEY_RES_NONE:
        ret = termkey_advisereadable(tk);
        if(ret == TERMKEY_RES_ERROR)
          return ret;
        break;

      case TERMKEY_RES_AGAIN:
        {
          if(tk->is_closed)
            // We're closed now. Never going to get more bytes so just go with
            // what we have
            return termkey_getkey_force(tk, key);

          struct pollfd fd;

retry:
          fd.fd = tk->fd;
          fd.events = POLLIN;

          int pollret = poll(&fd, 1, tk->waittime);
          if(pollret == -1) {
            if(errno == EINTR && !(tk->flags & TERMKEY_FLAG_EINTR))
              goto retry;

            return TERMKEY_RES_ERROR;
          }

          if(fd.revents & (POLLIN|POLLHUP|POLLERR))
            ret = termkey_advisereadable(tk);
          else
            ret = TERMKEY_RES_NONE;

          if(ret == TERMKEY_RES_ERROR)
            return ret;
          if(ret == TERMKEY_RES_NONE)
            return termkey_getkey_force(tk, key);
        }
        break;
    }
  }

  /* UNREACHABLE */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x44b0
callq 0x30a0
movl $0x9, (%rax)
movl $0x4, -0x4(%rbp)
jmp 0x45dc
jmp 0x44b2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3140
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq %rax, -0x30(%rbp)
subq $0x4, %rax
ja 0x45d7
movq -0x30(%rbp), %rax
leaq 0x5b4e(%rip), %rcx      # 0xa02c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x45dc
movq -0x10(%rbp), %rdi
callq 0x32e0
movl %eax, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jne 0x450f
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x45dc
jmp 0x45d7
movq -0x10(%rbp), %rax
cmpb $0x0, 0x8c(%rax)
je 0x4536
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3070
movl %eax, -0x4(%rbp)
jmp 0x45dc
jmp 0x4538
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movw $0x1, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x88(%rax), %edx
leaq -0x24(%rbp), %rdi
movl $0x1, %esi
callq 0x3250
movl %eax, -0x28(%rbp)
cmpl $-0x1, -0x28(%rbp)
jne 0x458e
callq 0x30a0
cmpl $0x4, (%rax)
jne 0x4585
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x4585
jmp 0x4538
movl $0x4, -0x4(%rbp)
jmp 0x45dc
movswl -0x1e(%rbp), %eax
andl $0x19, %eax
cmpl $0x0, %eax
je 0x45a8
movq -0x10(%rbp), %rdi
callq 0x32e0
movl %eax, -0x1c(%rbp)
jmp 0x45af
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jne 0x45bd
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x45dc
cmpl $0x0, -0x1c(%rbp)
jne 0x45d5
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3070
movl %eax, -0x4(%rbp)
jmp 0x45dc
jmp 0x45d7
jmp 0x44b2
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)