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

```asm
<connect_nonb>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x30,%rsp
  mov    %edi,%ebx
  mov    %rsi,%r12
  mov    %edx,%r14d
  mov    %ecx,%r13d
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  mov    $0x0,%edx
  mov    D31(%rip),%rax
  mov    (%rax),%esi
  call   <fcntl@plt>
  mov    %eax,%ebp
  mov    D59(%rip),%rax
  mov    %ebp,%edx
  or     (%rax),%edx
  mov    D7(%rip),%rax
  mov    (%rax),%esi
  mov    %ebx,%edi
  call   <fcntl@plt>
  movl   $0x0,(%rsp)
  mov    %r14d,%edx
  mov    %r12,%rsi
  mov    %ebx,%edi
  call   <connect@plt>
  test   %eax,%eax
  js     L43
  jne    L71
L91:
  mov    %ebp,%edx
  mov    D7(%rip),%rax
  mov    (%rax),%esi
  mov    %ebx,%edi
  call   <fcntl@plt>
  mov    (%rsp),%eax
  test   %eax,%eax
  jne    L100
L7:
  mov    0x28(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L92
  add    $0x30,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L43:
  mov    D22(%rip),%rdx
  mov    D74(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,(%rdx)
  jne    L4
L71:
  lea    0x8(%rsp),%r12
  mov    %r12,%rdi
  call   <FD_ZERO@plt>
  mov    %r12,%rsi
  mov    %ebx,%edi
  call   <FD_SET@plt>
  mov    0x8(%rsp),%eax
  mov    %eax,0xc(%rsp)
  mov    %r13d,0x10(%rsp)
  movq   $0x0,0x18(%rsp)
  lea    0x10(%rsp),%r8
  test   %r13d,%r13d
  mov    $0x0,%eax
  cmove  %rax,%r8
  lea    0xc(%rsp),%rdx
  mov    %r12,%rsi
  lea    0x1(%rbx),%edi
  mov    $0x0,%ecx
  call   <select@plt>
  test   %eax,%eax
  je     L133
  lea    0x8(%rsp),%rsi
  mov    %ebx,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  jne    L132
  lea    0xc(%rsp),%rsi
  mov    %ebx,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  je     L52
L132:
  movl   $0x4,0x4(%rsp)
  mov    %rsp,%rcx
  lea    0x4(%rsp),%r8
  mov    D75(%rip),%rax
  mov    (%rax),%edx
  mov    D39(%rip),%rax
  mov    (%rax),%esi
  mov    %ebx,%edi
  call   <getsockopt@plt>
  test   %rax,%rax
  jns    L91
  mov    $0xffffffff,%eax
  jmp    L7
L133:
  mov    %ebx,%edi
  call   <close@plt>
  mov    D21(%rip),%rax
  mov    (%rax),%edx
  mov    D22(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L7
L52:
  mov    $0x0,%edi
  call   <assert@plt>
  jmp    L91
L100:
  mov    %ebx,%edi
  call   <close@plt>
  mov    D22(%rip),%rax
  mov    (%rsp),%edx
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L7
L4:
  mov    $0xffffffff,%eax
  jmp    L7
L92:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, int nsec) {
  int flags, n, error;
  socklen_t len;
  fd_set rset, wset;
  struct timeval tval;
  flags = fcntl(sockfd, F_GETFL, 0);
  fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
  error = 0;
  if ((n = connect(sockfd, saptr, salen)) < 0)
    if (errno != EINPROGRESS)
      return (-1);
  if (n == 0)
    goto done;
  FD_ZERO(&rset);
  FD_SET(sockfd, &rset);
  wset = rset;
  tval.tv_sec = nsec;
  tval.tv_usec = 0;
  if ((n = select(sockfd + 1, &rset, &wset, NULL, nsec ? &tval : NULL)) == 0) {
    close(sockfd);
    errno = ETIMEDOUT;
    return (-1);
  }
  if (FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset)) {
    len = sizeof(error);
    if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
      return (-1);
  } else
    assert(0 && "select error: sockfd not set");
done:
  fcntl(sockfd, F_SETFL, flags);
  if (error) {
    close(sockfd);
    errno = error;
    return (-1);
  }
  return (0);
}
```