user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<cfg_ack_check>:
  endbr64
  push   %r15
  mov    $0x1,%r15d
  push   %r14
  lea    D45(%rip),%r14
  push   %r13
  lea    0x1(%rdi),%r13d
  push   %r12
  push   %rbp
  mov    %edi,%ebp
  push   %rbx
  sub    $0xfe8,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0xfd8(%rsp)
  xor    %eax,%eax
  movl   $0x3,0x20(%rsp)
  lea    0x1c(%rsp),%rbx
  lea    0x20(%rsp),%r12
  movq   $0x0,0x28(%rsp)
  cs nopw 0x0(%rax,%rax,1)
L83:
  mov    %rbx,%rdi
  call   <FD_ZERO@plt>
  mov    %rbx,%rsi
  mov    %ebp,%edi
  call   <FD_SET@plt>
  xor    %ecx,%ecx
  xor    %edx,%edx
  mov    %r12,%r8
  mov    %rbx,%rsi
  mov    %r13d,%edi
  call   <select@plt>
  cmp    $0xffffffff,%eax
  je     L70
  test   %eax,%eax
  je     L41
  lea    0x30(%rsp),%r15
  mov    $0xfa0,%edx
  mov    %ebp,%edi
  mov    %r15,%rsi
  call   <read@plt>
  mov    %rax,%rcx
  xor    %eax,%eax
  test   %rcx,%rcx
  jne    L145
  jmp    L139
  nopl   0x0(%rax)
L118:
  cmp    %rax,%rcx
  je     L139
L145:
  mov    (%r15,%rax,4),%edx
  mov    %rax,%rsi
  add    $0x1,%rax
  cmp    $0xb5,%edx
  jne    L118
  cmpl   $0x62,(%r15,%rax,4)
  jne    L118
  mov    %r14,%rdi
  mov    %rcx,0x8(%rsp)
  mov    %rsi,(%rsp)
  call   <printf@plt>
  mov    (%rsp),%rsi
  mov    0x8(%rsp),%rcx
  cmp    %rcx,%rsi
  jne    L51
L139:
  mov    $0x3,%r15d
  jmp    L83
L70:
  lea    D39(%rip),%rdi
  call   <perror@plt>
L21:
  mov    0xfd8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L25
  add    $0xfe8,%rsp
  mov    %r15d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L41:
  lea    D3(%rip),%rdi
  mov    $0x3,%r15d
  call   <printf@plt>
  jmp    L21
L51:
  cmpl   $0x5,0x38(%rsp,%rsi,4)
  jne    L54
  mov    0x3c(%rsp,%rsi,4),%eax
  test   %eax,%eax
  je     L116
L54:
  lea    D19(%rip),%rdi
  mov    $0x1,%r15d
  call   <printf@plt>
  jmp    L21
L116:
  lea    D21(%rip),%rdi
  mov    $0x2,%r15d
  call   <printf@plt>
  jmp    L21
L25:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D45
datatype: string
name: unpack_data
arguments: label: D39
datatype: string
name: unpack_data
arguments: label: D3
datatype: string
name: unpack_data
arguments: label: D19
datatype: string
name: unpack_data
arguments: label: D21
datatype: string

tool: D45: Found header B5 62


tool: D39: select

tool: D3: No ACK/NAK received.


tool: D19: Received ACK, succeeded.


tool: D21: Received NAK, failed.


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