user: Converte this assembly snippet into its equivalent C code:

```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    L89
  test   %rsi,%rsi
  jne    L75
L89:
  test   %edx,%edx
  jne    L230
  movl   $0x0,0x20(%rsp)
  movl   $0x0,0x24(%rsp)
  lea    0x20(%rsp),%rax
  mov    %rax,0x8(%rsp)
L36:
  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     L32
  mov    (%rsp),%rbx
  mov    $0x0,%r12d
  mov    $0xffffffff,%r14d
  lea    0x1c(%rsp),%r15
  jmp    L307
L75:
  mov    D137(%rip),%rax
  mov    (%rax),%edx
  mov    D136(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r12d
  jmp    L107
L230:
  jle    L265
  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    L36
L265:
  cmp    $0xffffffff,%edx
  jne    L161
  movq   $0x0,0x8(%rsp)
  jmp    L36
L161:
  mov    D9(%rip),%rax
  mov    (%rax),%edx
  mov    D136(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r12d
  jmp    L107
L29:
  lea    0x14(%rsp),%rsi
  call   <FD_SET@plt>
  jmp    L175
L246:
  lea    0x18(%rsp),%rsi
  mov    0x0(%rbp),%edi
  call   <FD_SET@plt>
  jmp    L244
L252:
  mov    %r15,%rsi
  mov    0x0(%rbp),%edi
  call   <FD_SET@plt>
  jmp    L136
L285:
  mov    D31(%rip),%rax
  mov    (%rax),%edx
  mov    D136(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r12d
L107:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L30
  mov    %r12d,%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L40:
  add    $0x1,%r12
  add    $0xc,%rbx
  cmp    %r12,%r13
  je     L74
L307:
  mov    %rbx,%rbp
  mov    (%rbx),%edi
  test   %edi,%edi
  js     L40
  mov    D143(%rip),%rax
  mov    (%rax),%eax
  mov    D139(%rip),%rdx
  or     (%rdx),%eax
  and    0x4(%rbx),%eax
  jne    L29
L175:
  mov    D156(%rip),%rax
  mov    (%rax),%eax
  mov    D49(%rip),%rdx
  or     (%rdx),%eax
  mov    D85(%rip),%rdx
  or     (%rdx),%eax
  and    0x4(%rbp),%eax
  jne    L246
L244:
  mov    D102(%rip),%rax
  mov    (%rax),%eax
  mov    D164(%rip),%rdx
  or     (%rdx),%eax
  and    0x4(%rbp),%eax
  jne    L252
L136:
  mov    0x0(%rbp),%edx
  cmp    %r14d,%edx
  jl     L40
  mov    D143(%rip),%rax
  mov    (%rax),%eax
  mov    D156(%rip),%rcx
  or     (%rcx),%eax
  mov    D102(%rip),%rcx
  or     (%rcx),%eax
  mov    D139(%rip),%rcx
  or     (%rcx),%eax
  mov    D164(%rip),%rcx
  or     (%rcx),%eax
  mov    D49(%rip),%rcx
  or     (%rcx),%eax
  mov    D85(%rip),%rcx
  or     (%rcx),%eax
  and    0x4(%rbp),%eax
  je     L40
  mov    D160(%rip),%rax
  cmp    (%rax),%edx
  jg     L285
  mov    %edx,%r14d
  jmp    L40
L32:
  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    L107
L256:
  lea    0x18(%rsp),%rcx
  lea    0x14(%rsp),%rdx
  mov    0x4(%rbx),%esi
  mov    %r15,%r8
  call   <compute_revents@plt>
  test   %eax,%eax
  je     L306
  mov    %eax,0x8(%rbx)
  add    $0x1,%r12d
L306:
  add    $0x1,%rbp
  add    $0xc,%rbx
  cmp    %rbp,%r13
  jbe    L107
L96:
  mov    (%rbx),%edi
  test   %edi,%edi
  jns    L256
  movl   $0x0,0x8(%rbx)
  jmp    L306
L74:
  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     L107
  mov    (%rsp),%rbx
  mov    $0x0,%ebp
  mov    $0x0,%r12d
  lea    0x1c(%rsp),%r15
  jmp    L96
L30:
  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;
}
```