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

```asm
<poll>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,(%rsp)
  mov    %rsi,%r13
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  jne    L7
  test   %rsi,%rsi
  jne    L298
L7:
  test   %edx,%edx
  jne    L206
  movl   $0x0,0x20(%rsp)
  movl   $0x0,0x24(%rsp)
  lea    0x20(%rsp),%rax
  mov    %rax,0x8(%rsp)
L218:
  lea    0x14(%rsp),%rdi
  call   <FD_ZERO@plt>
  lea    0x18(%rsp),%rdi
  call   <FD_ZERO@plt>
  lea    0x1c(%rsp),%rdi
  call   <FD_ZERO@plt>
  test   %r13,%r13
  je     L305
  mov    (%rsp),%rbx
  mov    $0x0,%r12d
  mov    $0xffffffff,%r14d
  lea    0x1c(%rsp),%r15
  jmp    L297
L298:
  mov    D43(%rip),%rax
  mov    (%rax),%edx
  mov    D6(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r12d
  jmp    L125
L206:
  jle    L119
  movslq %edx,%rax
  imul   $0x10624dd3,%rax,%rax
  sar    $0x26,%rax
  mov    %edx,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%eax
  mov    %eax,0x20(%rsp)
  imul   $0x3e8,%eax,%eax
  sub    %eax,%edx
  imul   $0x3e8,%edx,%edx
  mov    %edx,0x24(%rsp)
  lea    0x20(%rsp),%rax
  mov    %rax,0x8(%rsp)
  jmp    L218
L119:
  cmp    $0xffffffff,%edx
  jne    L148
  movq   $0x0,0x8(%rsp)
  jmp    L218
L148:
  mov    D200(%rip),%rax
  mov    (%rax),%edx
  mov    D6(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r12d
  jmp    L125
L224:
  lea    0x14(%rsp),%rsi
  call   <FD_SET@plt>
  jmp    L269
L1:
  lea    0x18(%rsp),%rsi
  mov    0x0(%rbp),%edi
  call   <FD_SET@plt>
  jmp    L92
L302:
  mov    %r15,%rsi
  mov    0x0(%rbp),%edi
  call   <FD_SET@plt>
  jmp    L19
L258:
  mov    D30(%rip),%rax
  mov    (%rax),%edx
  mov    D6(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r12d
L125:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L29
  mov    %r12d,%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L144:
  add    $0x1,%r12
  add    $0xc,%rbx
  cmp    %r12,%r13
  je     L291
L297:
  mov    %rbx,%rbp
  mov    (%rbx),%edi
  test   %edi,%edi
  js     L144
  mov    D202(%rip),%rax
  mov    (%rax),%eax
  mov    D112(%rip),%rdx
  or     (%rdx),%eax
  and    0x4(%rbx),%eax
  jne    L224
L269:
  mov    D29(%rip),%rax
  mov    (%rax),%eax
  mov    D172(%rip),%rdx
  or     (%rdx),%eax
  mov    D89(%rip),%rdx
  or     (%rdx),%eax
  and    0x4(%rbp),%eax
  jne    L1
L92:
  mov    D121(%rip),%rax
  mov    (%rax),%eax
  mov    D31(%rip),%rdx
  or     (%rdx),%eax
  and    0x4(%rbp),%eax
  jne    L302
L19:
  mov    0x0(%rbp),%edx
  cmp    %r14d,%edx
  jl     L144
  mov    D202(%rip),%rax
  mov    (%rax),%eax
  mov    D29(%rip),%rcx
  or     (%rcx),%eax
  mov    D121(%rip),%rcx
  or     (%rcx),%eax
  mov    D112(%rip),%rcx
  or     (%rcx),%eax
  mov    D31(%rip),%rcx
  or     (%rcx),%eax
  mov    D172(%rip),%rcx
  or     (%rcx),%eax
  mov    D89(%rip),%rcx
  or     (%rcx),%eax
  and    0x4(%rbp),%eax
  je     L144
  mov    D186(%rip),%rax
  cmp    (%rax),%edx
  jg     L258
  mov    %edx,%r14d
  jmp    L144
L305:
  lea    0x1c(%rsp),%rcx
  lea    0x18(%rsp),%rdx
  lea    0x14(%rsp),%rsi
  mov    0x8(%rsp),%r8
  mov    $0x0,%edi
  call   <select@plt>
  test   %eax,%eax
  mov    $0x0,%edx
  cmovle %eax,%edx
  mov    %edx,%r12d
  jmp    L125
L140:
  lea    0x18(%rsp),%rcx
  lea    0x14(%rsp),%rdx
  mov    0x4(%rbx),%esi
  mov    %r15,%r8
  call   <compute_revents@plt>
  test   %eax,%eax
  je     L83
  mov    %eax,0x8(%rbx)
  add    $0x1,%r12d
L83:
  add    $0x1,%rbp
  add    $0xc,%rbx
  cmp    %rbp,%r13
  jbe    L125
L100:
  mov    (%rbx),%edi
  test   %edi,%edi
  jns    L140
  movl   $0x0,0x8(%rbx)
  jmp    L83
L291:
  lea    0x1c(%rsp),%rcx
  lea    0x18(%rsp),%rdx
  lea    0x14(%rsp),%rsi
  lea    0x1(%r14),%edi
  mov    0x8(%rsp),%r8
  call   <select@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  js     L125
  mov    (%rsp),%rbx
  mov    $0x0,%ebp
  mov    $0x0,%r12d
  lea    0x1c(%rsp),%r15
  jmp    L100
L29:
  call   <__stack_chk_fail@plt>
```

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;
}
```