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

```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    L250
  test   %rsi,%rsi
  jne    L217
L250:
  test   %edx,%edx
  je     L173
  jle    L151
  movslq %edx,%rax
  mov    %edx,%ecx
  imul   $0x10624dd3,%rax,%rax
  sar    $0x1f,%ecx
  sar    $0x26,%rax
  sub    %ecx,%eax
  mov    %eax,0x30(%rsp)
  imul   $0x3e8,%eax,%eax
  sub    %eax,%edx
  lea    0x30(%rsp),%rax
  imul   $0x3e8,%edx,%edx
  mov    %rax,0x18(%rsp)
  mov    %edx,0x34(%rsp)
L42:
  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     L84
  movl   $0xffffffff,0x8(%rsp)
  mov    0x10(%rsp),%r12
  xor    %ebx,%ebx
  jmp    L28
  nopl   0x0(%rax)
L77:
  test   $0x304,%eax
  jne    L89
L157:
  test   $0x82,%al
  jne    L255
L187:
  cmp    %edi,0x8(%rsp)
  jg     L11
  testl  $0x3c7,0x4(%r12)
  je     L11
  mov    D38(%rip),%rax
  cmp    %edi,(%rax)
  jl     L245
  mov    %edi,0x8(%rsp)
  nop
L11:
  add    $0x1,%rbx
  add    $0xc,%r12
  cmp    %rbx,%rbp
  je     L248
L28:
  mov    (%r12),%edi
  test   %edi,%edi
  js     L11
  mov    0x4(%r12),%eax
  test   $0x41,%al
  je     L77
  mov    %r13,%rsi
  call   <FD_SET@plt>
  mov    0x4(%r12),%eax
  mov    (%r12),%edi
  test   $0x304,%eax
  je     L157
L89:
  mov    %r14,%rsi
  call   <FD_SET@plt>
  mov    0x4(%r12),%eax
  mov    (%r12),%edi
  test   $0x82,%al
  je     L187
L255:
  mov    %r15,%rsi
  call   <FD_SET@plt>
  mov    (%r12),%edi
  jmp    L187
  nopl   0x0(%rax)
L173:
  movq   $0x0,0x30(%rsp)
  lea    0x30(%rsp),%rax
  mov    %rax,0x18(%rsp)
  jmp    L42
  nopl   0x0(%rax,%rax,1)
L248:
  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     L251
  mov    0x10(%rsp),%rbx
  xor    %r9d,%r9d
  xor    %r12d,%r12d
  nopl   0x0(%rax)
L207:
  mov    (%rbx),%edi
  xor    %eax,%eax
  test   %edi,%edi
  js     L170
  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
L170:
  add    $0x1,%r9
  mov    %eax,0x8(%rbx)
  add    $0xc,%rbx
  cmp    %r9,%rbp
  ja     L207
L251:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L229
  add    $0x48,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L151:
  cmp    $0xffffffff,%edx
  jne    L41
  movq   $0x0,0x18(%rsp)
  jmp    L42
L245:
  mov    D55(%rip),%rax
  mov    $0xffffffff,%r12d
  mov    (%rax),%edx
  mov    D2(%rip),%rax
  mov    %edx,(%rax)
  jmp    L251
L84:
  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    L251
L217:
  mov    D52(%rip),%rax
  mov    $0xffffffff,%r12d
  mov    (%rax),%edx
  mov    D2(%rip),%rax
  mov    %edx,(%rax)
  jmp    L251
L41:
  mov    D8(%rip),%rax
  mov    $0xffffffff,%r12d
  mov    (%rax),%edx
  mov    D2(%rip),%rax
  mov    %edx,(%rax)
  jmp    L251
L229:
  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;
}
```