user: Please show me the C implementation that matches the assembly code listed below:

```asm
<poll>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %edx,-0x54(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  cmpq   $0x0,-0x48(%rbp)
  jne    L61
  cmpq   $0x0,-0x50(%rbp)
  je     L61
  mov    D114(%rip),%rax
  mov    (%rax),%edx
  mov    D85(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L242
L61:
  cmpl   $0x0,-0x54(%rbp)
  jne    L75
  lea    -0x10(%rbp),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x20(%rbp),%rax
  movl   $0x0,(%rax)
  mov    -0x20(%rbp),%rax
  movl   $0x0,0x4(%rax)
  jmp    L2
L75:
  cmpl   $0x0,-0x54(%rbp)
  jle    L116
  lea    -0x10(%rbp),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x54(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x10624dd3,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x6,%edx
  sar    $0x1f,%eax
  sub    %eax,%edx
  mov    -0x20(%rbp),%rax
  mov    %edx,(%rax)
  mov    -0x54(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x10624dd3,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x6,%edx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  imul   $0x3e8,%edx,%ecx
  sub    %ecx,%eax
  mov    %eax,%edx
  imul   $0x3e8,%edx,%edx
  mov    -0x20(%rbp),%rax
  mov    %edx,0x4(%rax)
  jmp    L2
L116:
  cmpl   $0xffffffff,-0x54(%rbp)
  jne    L158
  movq   $0x0,-0x20(%rbp)
  jmp    L2
L158:
  mov    D139(%rip),%rax
  mov    (%rax),%edx
  mov    D85(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L242
L2:
  movl   $0xffffffff,-0x2c(%rbp)
  lea    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <FD_ZERO@plt>
  lea    -0x34(%rbp),%rax
  mov    %rax,%rdi
  call   <FD_ZERO@plt>
  lea    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <FD_ZERO@plt>
  movq   $0x0,-0x18(%rbp)
  jmp    L160
L189:
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  js     L167
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    0x4(%rax),%edx
  mov    D117(%rip),%rax
  mov    (%rax),%ecx
  mov    D159(%rip),%rax
  mov    (%rax),%eax
  or     %ecx,%eax
  and    %edx,%eax
  test   %eax,%eax
  je     L194
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  lea    -0x38(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_SET@plt>
L194:
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    0x4(%rax),%edx
  mov    D44(%rip),%rax
  mov    (%rax),%ecx
  mov    D118(%rip),%rax
  mov    (%rax),%eax
  or     %eax,%ecx
  mov    D30(%rip),%rax
  mov    (%rax),%eax
  or     %ecx,%eax
  and    %edx,%eax
  test   %eax,%eax
  je     L236
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  lea    -0x34(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_SET@plt>
L236:
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    0x4(%rax),%edx
  mov    D73(%rip),%rax
  mov    (%rax),%ecx
  mov    D142(%rip),%rax
  mov    (%rax),%eax
  or     %ecx,%eax
  and    %edx,%eax
  test   %eax,%eax
  je     L151
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  lea    -0x30(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_SET@plt>
L151:
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cmp    %eax,-0x2c(%rbp)
  jg     L262
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    0x4(%rax),%edx
  mov    D117(%rip),%rax
  mov    (%rax),%ecx
  mov    D44(%rip),%rax
  mov    (%rax),%eax
  or     %eax,%ecx
  mov    D73(%rip),%rax
  mov    (%rax),%eax
  or     %eax,%ecx
  mov    D159(%rip),%rax
  mov    (%rax),%eax
  or     %eax,%ecx
  mov    D142(%rip),%rax
  mov    (%rax),%eax
  or     %eax,%ecx
  mov    D118(%rip),%rax
  mov    (%rax),%eax
  or     %eax,%ecx
  mov    D30(%rip),%rax
  mov    (%rax),%eax
  or     %ecx,%eax
  and    %edx,%eax
  test   %eax,%eax
  je     L262
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0x2c(%rbp)
  mov    D104(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,-0x2c(%rbp)
  jle    L262
  mov    D102(%rip),%rax
  mov    (%rax),%edx
  mov    D85(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L242
L167:
  nop
L262:
  addq   $0x1,-0x18(%rbp)
L160:
  mov    -0x18(%rbp),%rax
  cmp    -0x50(%rbp),%rax
  jb     L189
  mov    -0x2c(%rbp),%eax
  lea    0x1(%rax),%edi
  mov    -0x20(%rbp),%rsi
  lea    -0x30(%rbp),%rcx
  lea    -0x34(%rbp),%rdx
  lea    -0x38(%rbp),%rax
  mov    %rsi,%r8
  mov    %rax,%rsi
  call   <select@plt>
  mov    %eax,-0x28(%rbp)
  cmpl   $0x0,-0x28(%rbp)
  jns    L112
  mov    -0x28(%rbp),%eax
  jmp    L242
L112:
  movl   $0x0,-0x28(%rbp)
  movq   $0x0,-0x18(%rbp)
  jmp    L57
L266:
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jns    L208
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  movl   $0x0,0x8(%rax)
  jmp    L127
L208:
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    0x4(%rax),%esi
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  lea    -0x30(%rbp),%rdi
  lea    -0x34(%rbp),%rcx
  lea    -0x38(%rbp),%rdx
  mov    %rdi,%r8
  mov    %eax,%edi
  call   <compute_revents@plt>
  mov    %eax,-0x24(%rbp)
  cmpl   $0x0,-0x24(%rbp)
  je     L127
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x2,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rax,%rdx
  mov    -0x24(%rbp),%eax
  mov    %eax,0x8(%rdx)
  addl   $0x1,-0x28(%rbp)
L127:
  addq   $0x1,-0x18(%rbp)
L57:
  mov    -0x18(%rbp),%rax
  cmp    -0x50(%rbp),%rax
  jb     L266
  mov    -0x28(%rbp),%eax
L242:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L197
  call   <__stack_chk_fail@plt>
L197:
  leave
  ret
```

assistant: ```c
int poll(struct pollfd *pfd, nfds_t nfd, int timeout) {
  fd_set rfds, wfds, efds;
  struct timeval tv;
  struct timeval *ptv;
  int maxfd, rc;
  nfds_t i;
  if (!pfd && nfd) {
    errno = EFAULT;
    return -1;
  }
  if (timeout == 0) {
    ptv = &tv;
    ptv->tv_sec = 0;
    ptv->tv_usec = 0;
  } else if (timeout > 0) {
    ptv = &tv;
    ptv->tv_sec = timeout / 1000;
    ptv->tv_usec = (timeout % 1000) * 1000;
  } else if (timeout == (-1))
    ptv = NULL;
  else {
    errno = EINVAL;
    return -1;
  }
  maxfd = -1;
  FD_ZERO(&rfds);
  FD_ZERO(&wfds);
  FD_ZERO(&efds);
  for (i = 0; i < nfd; i++) {
    if (pfd[i].fd < 0)
      continue;
    if (pfd[i].events & (POLLIN | POLLRDNORM))
      FD_SET(pfd[i].fd, &rfds);
    if (pfd[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND))
      FD_SET(pfd[i].fd, &wfds);
    if (pfd[i].events & (POLLPRI | POLLRDBAND))
      FD_SET(pfd[i].fd, &efds);
    if (pfd[i].fd >= maxfd && (pfd[i].events & (POLLIN | POLLOUT | POLLPRI | POLLRDNORM | POLLRDBAND | POLLWRNORM | POLLWRBAND))) {
      maxfd = pfd[i].fd;
      if (maxfd > FD_SETSIZE) {
        errno = EOVERFLOW;
        return -1;
      }
    }
  }
  rc = select(maxfd + 1, &rfds, &wfds, &efds, ptv);
  if (rc < 0)
    return rc;
  rc = 0;
  for (i = 0; i < nfd; i++)
    if (pfd[i].fd < 0)
      pfd[i].revents = 0;
    else {
      int happened = compute_revents(pfd[i].fd, pfd[i].events, &rfds, &wfds, &efds);
      if (happened) {
        pfd[i].revents = happened;
        rc++;
      }
    }
  return rc;
}
```