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

```asm
<timed_write>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %rdx,-0x58(%rbp)
  mov    %ecx,-0x48(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x44(%rbp),%eax
  mov    %eax,%edi
  call   <fd_get_flags@plt>
  mov    %eax,-0x34(%rbp)
  cmpl   $0xffffffff,-0x34(%rbp)
  jne    L114
  mov    $0xffffffff,%eax
  jmp    L147
L114:
  mov    -0x34(%rbp),%edx
  mov    -0x44(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <fd_set_nonblocking@plt>
  test   %rax,%rax
  je     L4
  mov    $0xffffffff,%eax
  jmp    L147
L4:
  cmpl   $0x0,-0x48(%rbp)
  jne    L82
  movl   $0xffffffff,-0x48(%rbp)
L82:
  movq   $0x0,-0x28(%rbp)
L74:
  lea    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <FD_ZERO@plt>
  lea    -0x38(%rbp),%rdx
  mov    -0x44(%rbp),%eax
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_SET@plt>
  mov    -0x48(%rbp),%eax
  mov    %eax,-0x20(%rbp)
  movq   $0x0,-0x18(%rbp)
  mov    -0x44(%rbp),%eax
  lea    0x1(%rax),%edi
  lea    -0x20(%rbp),%rdx
  lea    -0x38(%rbp),%rax
  mov    %rdx,%r8
  mov    $0x0,%ecx
  mov    %rax,%rdx
  mov    $0x0,%esi
  call   <select@plt>
  mov    %eax,-0x30(%rbp)
  cmpl   $0x0,-0x30(%rbp)
  jne    L128
  cmpq   $0x0,-0x28(%rbp)
  jne    L113
  mov    D37(%rip),%rax
  mov    (%rax),%rdx
  mov    D31(%rip),%rax
  mov    %rdx,(%rax)
  movq   $0xffffffffffffffff,-0x28(%rbp)
  jmp    L113
L128:
  cmpl   $0xffffffff,-0x30(%rbp)
  jne    L208
  mov    D31(%rip),%rax
  mov    (%rax),%rdx
  mov    D60(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L158
  movq   $0xffffffffffffffff,-0x28(%rbp)
  jmp    L170
L208:
  mov    -0x58(%rbp),%rax
  sub    -0x28(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x50(%rbp),%rcx
  mov    -0x28(%rbp),%rax
  add    %rax,%rcx
  mov    -0x44(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <write@plt>
  mov    %eax,-0x2c(%rbp)
  cmpl   $0xffffffff,-0x2c(%rbp)
  jne    L34
  mov    D31(%rip),%rax
  mov    (%rax),%rdx
  mov    D60(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L5
  mov    D31(%rip),%rax
  mov    (%rax),%rdx
  mov    D10(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L5
  movq   $0xffffffffffffffff,-0x28(%rbp)
  jmp    L170
L34:
  cmpl   $0x0,-0x2c(%rbp)
  je     L10
  mov    -0x2c(%rbp),%eax
  cltq
  add    %rax,-0x28(%rbp)
  jmp    L74
L158:
  nop
  jmp    L74
L5:
  nop
  jmp    L74
L113:
  nop
  jmp    L170
L10:
  nop
L170:
  mov    -0x34(%rbp),%edx
  mov    -0x44(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <fd_clear_nonblocking@plt>
  mov    -0x28(%rbp),%rax
L147:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L26
  call   <__stack_chk_fail@plt>
L26:
  leave
  ret
```

assistant: ```c
ssize_t timed_write(int fd, const void *buf, size_t size, unsigned int timeout) {
  int ret;
  int flags;
  fd_set set;
  size_t have;
  ssize_t count;
  struct timeval wait_time;
  flags = fd_get_flags(fd);
  if (flags == -1)
    return -1;
  if (fd_set_nonblocking(fd, flags))
    return -1;
  if (!timeout)
    timeout = (unsigned int)-1;
  have = 0;
  for (;;) {
    FD_ZERO(&set);
    FD_SET(fd, &set);
    wait_time.tv_sec = timeout;
    wait_time.tv_usec = 0;
    ret = select(fd + 1, NULL, &set, NULL, &wait_time);
    if (ret == 0) {
      if (!have) {
        errno = ETIMEDOUT;
        have = -1;
      }
      break;
    } else if (ret == -1) {
      if (errno == EINTR) {
        continue;
      } else {
        have = -1;
        break;
      }
    } else {
      count = write(fd, buf + have, size - have);
      if (count == -1) {
        if (errno == EINTR || errno == EAGAIN) {
          continue;
        } else {
          have = -1;
          break;
        }
      } else if (count == 0) {
        break;
      } else {
        have += (size_t)count;
      }
    }
  }
  (void)fd_clear_nonblocking(fd, flags);
  return have;
}
```