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

```asm
<connect_nonb>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %edx,-0x48(%rbp)
  mov    %ecx,-0x54(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    D106(%rip),%rax
  mov    (%rax),%ecx
  mov    -0x44(%rbp),%eax
  mov    $0x0,%edx
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <fcntl@plt>
  mov    %eax,-0x28(%rbp)
  mov    D86(%rip),%rax
  mov    (%rax),%eax
  or     -0x28(%rbp),%eax
  mov    %eax,%edx
  mov    D15(%rip),%rax
  mov    (%rax),%ecx
  mov    -0x44(%rbp),%eax
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <fcntl@plt>
  movl   $0x0,-0x38(%rbp)
  mov    -0x48(%rbp),%edx
  mov    -0x50(%rbp),%rcx
  mov    -0x44(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <connect@plt>
  mov    %eax,-0x24(%rbp)
  cmpl   $0x0,-0x24(%rbp)
  jns    L153
  mov    D75(%rip),%rax
  mov    (%rax),%edx
  mov    D89(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,%edx
  je     L153
  mov    $0xffffffff,%eax
  jmp    L58
L153:
  cmpl   $0x0,-0x24(%rbp)
  je     L14
  lea    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <FD_ZERO@plt>
  lea    -0x30(%rbp),%rdx
  mov    -0x44(%rbp),%eax
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_SET@plt>
  mov    -0x30(%rbp),%eax
  mov    %eax,-0x2c(%rbp)
  mov    -0x54(%rbp),%eax
  mov    %eax,-0x20(%rbp)
  movq   $0x0,-0x18(%rbp)
  cmpl   $0x0,-0x54(%rbp)
  je     L102
  lea    -0x20(%rbp),%rcx
  jmp    L131
L102:
  mov    $0x0,%ecx
L131:
  mov    -0x44(%rbp),%eax
  lea    0x1(%rax),%edi
  lea    -0x2c(%rbp),%rdx
  lea    -0x30(%rbp),%rax
  mov    %rcx,%r8
  mov    $0x0,%ecx
  mov    %rax,%rsi
  call   <select@plt>
  mov    %eax,-0x24(%rbp)
  cmpl   $0x0,-0x24(%rbp)
  jne    L51
  mov    -0x44(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  mov    D32(%rip),%rax
  mov    (%rax),%edx
  mov    D75(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L58
L51:
  lea    -0x30(%rbp),%rdx
  mov    -0x44(%rbp),%eax
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  jne    L147
  lea    -0x2c(%rbp),%rdx
  mov    -0x44(%rbp),%eax
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  je     L73
L147:
  movl   $0x4,-0x34(%rbp)
  mov    D63(%rip),%rax
  mov    (%rax),%edx
  mov    D94(%rip),%rax
  mov    (%rax),%esi
  lea    -0x34(%rbp),%rdi
  lea    -0x38(%rbp),%rcx
  mov    -0x44(%rbp),%eax
  mov    %rdi,%r8
  mov    %eax,%edi
  call   <getsockopt@plt>
  test   %rax,%rax
  jns    L27
  mov    $0xffffffff,%eax
  jmp    L58
L73:
  mov    $0x0,%edi
  call   <assert@plt>
  jmp    L27
L14:
  nop
L27:
  mov    D15(%rip),%rax
  mov    (%rax),%ecx
  mov    -0x28(%rbp),%edx
  mov    -0x44(%rbp),%eax
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <fcntl@plt>
  mov    -0x38(%rbp),%eax
  test   %eax,%eax
  je     L13
  mov    -0x44(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  mov    -0x38(%rbp),%edx
  mov    D75(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L58
L13:
  mov    $0x0,%eax
L58:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L0
  call   <__stack_chk_fail@plt>
L0:
  leave
  ret
```

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