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
  mov    %rsi,%rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,0x10(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  jne    L131
  test   %rsi,%rsi
  jne    L40
L131:
  test   %edx,%edx
  je     L137
  jle    L184
  movslq %edx,%rax
  mov    %edx,%ecx
  imul   $0x10624dd3,%rax,%rax
  sar    $0x1f,%ecx
  sar    $0x26,%rax
  sub    %ecx,%eax
  imul   $0x3e8,%eax,%ecx
  movd   %eax,%xmm0
  lea    0x30(%rsp),%rax
  mov    %rax,0x18(%rsp)
  sub    %ecx,%edx
  imul   $0x3e8,%edx,%edx
  movd   %edx,%xmm1
  punpckldq %xmm1,%xmm0
  movq   %xmm0,0x30(%rsp)
L141:
  lea    0x24(%rsp),%r13
  lea    0x28(%rsp),%r14
  mov    %r13,%rdi
  lea    0x2c(%rsp),%r15
  call   <FD_ZERO@plt>
  mov    %r14,%rdi
  call   <FD_ZERO@plt>
  mov    %r15,%rdi
  call   <FD_ZERO@plt>
  test   %rbp,%rbp
  je     L94
  movl   $0xffffffff,0x8(%rsp)
  mov    0x10(%rsp),%r12
  xor    %ebx,%ebx
  jmp    L18
  cs nopw 0x0(%rax,%rax,1)
L203:
  test   $0x304,%eax
  jne    L148
L10:
  test   $0x82,%al
  jne    L265
L244:
  cmp    %edi,0x8(%rsp)
  jg     L248
  testl  $0x3c7,0x4(%r12)
  je     L248
  mov    D7(%rip),%rax
  cmp    %edi,(%rax)
  jl     L205
  mov    %edi,0x8(%rsp)
  nop
L248:
  add    $0x1,%rbx
  add    $0xc,%r12
  cmp    %rbx,%rbp
  je     L1
L18:
  mov    (%r12),%edi
  test   %edi,%edi
  js     L248
  mov    0x4(%r12),%eax
  test   $0x41,%al
  je     L203
  mov    %r13,%rsi
  call   <FD_SET@plt>
  mov    0x4(%r12),%eax
  mov    (%r12),%edi
  test   $0x304,%eax
  je     L10
L148:
  mov    %r14,%rsi
  call   <FD_SET@plt>
  mov    0x4(%r12),%eax
  mov    (%r12),%edi
  test   $0x82,%al
  je     L244
L265:
  mov    %r15,%rsi
  call   <FD_SET@plt>
  mov    (%r12),%edi
  jmp    L244
  nopl   0x0(%rax)
L137:
  movq   $0x0,0x30(%rsp)
  lea    0x30(%rsp),%rax
  mov    %rax,0x18(%rsp)
  jmp    L141
  nopl   0x0(%rax,%rax,1)
L1:
  mov    0x8(%rsp),%edi
  mov    0x18(%rsp),%r8
  mov    %r15,%rcx
  mov    %r14,%rdx
  mov    %r13,%rsi
  add    $0x1,%edi
  call   <select@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  js     L204
  mov    0x10(%rsp),%rbx
  xor    %r9d,%r9d
  xor    %r12d,%r12d
  nopl   0x0(%rax)
L20:
  mov    (%rbx),%edi
  xor    %eax,%eax
  test   %edi,%edi
  js     L193
  mov    0x4(%rbx),%esi
  mov    %r15,%r8
  mov    %r14,%rcx
  mov    %r13,%rdx
  mov    %r9,0x8(%rsp)
  call   <compute_revents@plt>
  mov    0x8(%rsp),%r9
  cmp    $0x1,%eax
  sbb    $0xffffffff,%r12d
L193:
  add    $0x1,%r9
  mov    %eax,0x8(%rbx)
  add    $0xc,%rbx
  cmp    %r9,%rbp
  ja     L20
L204:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L215
  add    $0x48,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L184:
  cmp    $0xffffffff,%edx
  jne    L114
  movq   $0x0,0x18(%rsp)
  jmp    L141
L205:
  mov    D68(%rip),%rax
  mov    $0xffffffff,%r12d
  mov    (%rax),%edx
  mov    D45(%rip),%rax
  mov    %edx,(%rax)
  jmp    L204
L94:
  mov    0x18(%rsp),%r8
  mov    %r14,%rdx
  xor    %edi,%edi
  mov    %r15,%rcx
  mov    %r13,%rsi
  call   <select@plt>
  xor    %edx,%edx
  test   %eax,%eax
  cmovle %eax,%edx
  mov    %edx,%r12d
  jmp    L204
L40:
  mov    D54(%rip),%rax
  mov    $0xffffffff,%r12d
  mov    (%rax),%edx
  mov    D45(%rip),%rax
  mov    %edx,(%rax)
  jmp    L204
L114:
  mov    D18(%rip),%rax
  mov    $0xffffffff,%r12d
  mov    (%rax),%edx
  mov    D45(%rip),%rax
  mov    %edx,(%rax)
  jmp    L204
L215:
  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 & (0x0001 | 0x0040))
      FD_SET(pfd[i].fd, &rfds);
    if (pfd[i].events & (0x0004 | 0x0100 | 0x0200))
      FD_SET(pfd[i].fd, &wfds);
    if (pfd[i].events & (0x0002 | 0x0080))
      FD_SET(pfd[i].fd, &efds);
    if (pfd[i].fd >= maxfd && (pfd[i].events & (0x0001 | 0x0004 | 0x0002 | 0x0040 | 0x0080 | 0x0100 | 0x0200))) {
      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++;
      } else {
        pfd[i].revents = 0;
      }
    }
  return rc;
}
```