user: Translate the below assembly code into C programming language:

```asm
<plat_wait_event>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %esi,-0x3c(%rbp)
  mov    %edx,-0x40(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x18(%rbp)
  movl   $0xffffffff,-0x1c(%rbp)
  cmpl   $0x0,-0x40(%rbp)
  js     L87
  mov    -0x40(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x10624dd3,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x6,%edx
  sar    $0x1f,%eax
  mov    %eax,%ecx
  mov    %edx,%eax
  sub    %ecx,%eax
  mov    %eax,-0x10(%rbp)
  mov    -0x40(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x10624dd3,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x6,%edx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  imul   $0x3e8,%edx,%ecx
  sub    %ecx,%eax
  mov    %eax,%edx
  imul   $0x3e8,%edx,%eax
  mov    %eax,-0xc(%rbp)
  lea    -0x10(%rbp),%rax
  mov    %rax,-0x18(%rbp)
L87:
  lea    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <FD_ZERO@plt>
  movl   $0x0,-0x24(%rbp)
  jmp    L6
L91:
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cmp    %eax,-0x1c(%rbp)
  jge    L92
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0x1c(%rbp)
L92:
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  lea    -0x28(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_SET@plt>
  addl   $0x1,-0x24(%rbp)
L6:
  mov    -0x24(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L91
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edi
  mov    -0x18(%rbp),%rdx
  lea    -0x28(%rbp),%rax
  mov    %rdx,%r8
  mov    $0x0,%ecx
  mov    $0x0,%edx
  mov    %rax,%rsi
  call   <select@plt>
  mov    %eax,-0x20(%rbp)
  cmpl   $0xffffffff,-0x20(%rbp)
  jne    L0
  lea    D0(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  mov    $0x1,%edi
  call   <sleep@plt>
  mov    $0xffffffff,%eax
  jmp    L113
L0:
  cmpl   $0x0,-0x20(%rbp)
  jne    L98
  mov    $0xffffffff,%eax
  jmp    L113
L98:
  movl   $0xffffffff,-0x20(%rbp)
  movl   $0x0,-0x24(%rbp)
  jmp    L70
L7:
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  lea    -0x28(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  je     L49
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0x20(%rbp)
L49:
  addl   $0x1,-0x24(%rbp)
L70:
  mov    -0x24(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L7
  mov    -0x20(%rbp),%eax
L113:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L118
  call   <__stack_chk_fail@plt>
L118:
  leave
  ret
```

tool_calls: name: read_data
arguments: data_tag: D0
type_guessed: string

tool: D0: plat_wait_event: select failed

assistant: ```c
int plat_wait_event(int *fds_hnds, int count, int timeout_ms) {
  struct timeval tv, *timeout = NULL;
  int i, ret, fdmax = -1;
  fd_set fdset;
  if (timeout_ms >= 0) {
    tv.tv_sec = timeout_ms / 1000;
    tv.tv_usec = (timeout_ms % 1000) * 1000;
    timeout = &tv;
  }
  FD_ZERO(&fdset);
  for (i = 0; i < count; i++) {
    if (fds_hnds[i] > fdmax)
      fdmax = fds_hnds[i];
    FD_SET(fds_hnds[i], &fdset);
  }
  ret = select(fdmax + 1, &fdset, NULL, NULL, timeout);
  if (ret == -1) {
    perror("plat_wait_event: select failed");
    sleep(1);
    return -1;
  }
  if (ret == 0)
    return -1;
  ret = -1;
  for (i = 0; i < count; i++)
    if (FD_ISSET(fds_hnds[i], &fdset))
      ret = fds_hnds[i];
  return ret;
}
```