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

```asm
<cfg_ack_check>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0xff0,%rsp
  mov    %edi,-0xfe4(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x3,-0xfc0(%rbp)
  movq   $0x0,-0xfb8(%rbp)
  movq   $0x0,-0xfc8(%rbp)
  movl   $0x1,-0xfd8(%rbp)
L49:
  lea    -0xfdc(%rbp),%rax
  mov    %rax,%rdi
  call   <FD_ZERO@plt>
  lea    -0xfdc(%rbp),%rdx
  mov    -0xfe4(%rbp),%eax
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_SET@plt>
  mov    -0xfe4(%rbp),%eax
  lea    0x1(%rax),%edi
  lea    -0xfc0(%rbp),%rdx
  lea    -0xfdc(%rbp),%rax
  mov    %rdx,%r8
  mov    $0x0,%ecx
  mov    $0x0,%edx
  mov    %rax,%rsi
  call   <select@plt>
  mov    %eax,-0xfd4(%rbp)
  cmpl   $0xffffffff,-0xfd4(%rbp)
  jne    L25
  lea    D47(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  jmp    L116
L25:
  cmpl   $0x0,-0xfd4(%rbp)
  je     L39
  lea    -0xfb0(%rbp),%rcx
  mov    -0xfe4(%rbp),%eax
  mov    $0xfa0,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  mov    %rax,-0xfc8(%rbp)
  movq   $0x0,-0xfd0(%rbp)
  jmp    L103
L122:
  mov    -0xfd0(%rbp),%rax
  mov    -0xfb0(%rbp,%rax,4),%eax
  cmp    $0xb5,%eax
  jne    L19
  mov    -0xfd0(%rbp),%rax
  add    $0x1,%rax
  mov    -0xfb0(%rbp,%rax,4),%eax
  cmp    $0x62,%eax
  jne    L19
  lea    D39(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  jmp    L146
L19:
  addq   $0x1,-0xfd0(%rbp)
L103:
  mov    -0xfd0(%rbp),%rax
  cmp    -0xfc8(%rbp),%rax
  jb     L122
L146:
  mov    -0xfd0(%rbp),%rax
  cmp    -0xfc8(%rbp),%rax
  jne    L27
  movl   $0x3,-0xfd8(%rbp)
  jmp    L49
L27:
  mov    -0xfd0(%rbp),%rax
  add    $0x2,%rax
  mov    -0xfb0(%rbp,%rax,4),%eax
  cmp    $0x5,%eax
  jne    L16
  mov    -0xfd0(%rbp),%rax
  add    $0x3,%rax
  mov    -0xfb0(%rbp,%rax,4),%eax
  test   %eax,%eax
  jne    L16
  lea    D49(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  movl   $0x2,-0xfd8(%rbp)
  jmp    L116
L16:
  lea    D15(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  movl   $0x1,-0xfd8(%rbp)
  jmp    L116
L39:
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  movl   $0x3,-0xfd8(%rbp)
L116:
  mov    -0xfd8(%rbp),%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L60
  call   <__stack_chk_fail@plt>
L60:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D47
data_type: string
name: retrieve_data
arguments: data_label: D39
data_type: string
name: retrieve_data
arguments: data_label: D49
data_type: string
name: retrieve_data
arguments: data_label: D15
data_type: string
name: retrieve_data
arguments: data_label: D16
data_type: string

tool: D47: select

tool: D39: Found header B5 62


tool: D49: Received NAK, failed.


tool: D15: Received ACK, succeeded.


tool: D16: No ACK/NAK received.


assistant: ```c
u_int8_t cfg_ack_check(int fd) {
  int rev;
  fd_set rfds;
  struct timeval tv;
  tv.tv_sec = 3;
  tv.tv_usec = 0;
  u_int16_t len = 0, i;
  u_int8_t rval = 1, buf[1000];
  while (1) {
    FD_ZERO(&rfds);
    FD_SET(fd, &rfds);
    rev = select(fd + 1, &rfds, NULL, NULL, &tv);
    if (rev == -1) {
      perror("select");
      break;
    } else if (rev) {
      len = read(fd, buf, sizeof(buf));
      for (i = 0; i < len; i++) {
        if (buf[i] == 0xB5 && buf[i + 1] == 0x62) {
          printf("Found header B5 62\n");
          break;
        }
      }
      if (i == len) {
        rval = 3;
      } else {
        if (buf[i + 2] == 0x05 && buf[i + 3] == 0x00) {
          printf("Received NAK, failed.\n");
          rval = 2;
          break;
        } else {
          printf("Received ACK, succeeded.\n");
          rval = 1;
          break;
        }
      }
    } else {
      printf("No ACK/NAK received.\n");
      rval = 3;
      break;
    }
  }
  return rval;
}
```