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

```asm
<listen>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x438,%rsp
  mov    %edi,%ebx
  mov    %rsi,(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x428(%rsp)
  xor    %eax,%eax
  lea    0x1(%rdi),%r13d
  lea    0x14(%rsp),%rdi
  call   <FD_ZERO@plt>
  movl   $0x2,0x18(%rsp)
  movl   $0x88b80,0x1c(%rsp)
  mov    $0x0,%r12d
  lea    0x14(%rsp),%r15
  jmp    L42
L264:
  lea    0x20(%rsp),%rsi
  mov    $0x400,%edx
  mov    %ebx,%edi
  call   <read@plt>
  mov    %eax,%edx
  mov    $0x0,%r14d
  test   %eax,%eax
  jle    L92
  movzbl 0x20(%rsp),%ecx
  mov    $0x1,%eax
  cmp    $0x18,%cl
  ja     L157
  mov    $0x1200040,%eax
  shr    %cl,%rax
  xor    $0x1,%rax
  and    $0x1,%eax
L157:
  cmp    $0xa5,%cl
  je     L162
  mov    $0x0,%r14d
  test   %al,%al
  jne    L92
L162:
  lea    0x20(%rsp),%rsi
  mov    %edx,%r14d
  mov    (%rsp),%rdi
  call   <memcpy@plt>
  add    %r14d,%r12d
  mov    $0x1,%r14d
L92:
  test   %ebp,%ebp
  je     L29
  test   %r14d,%r14d
  jne    L130
L42:
  mov    %r15,%rsi
  mov    %ebx,%edi
  call   <FD_SET@plt>
  lea    0x18(%rsp),%r8
  mov    $0x0,%ecx
  mov    $0x0,%edx
  mov    %r15,%rsi
  mov    %r13d,%edi
  call   <select@plt>
  mov    %eax,%ebp
  mov    %r15,%rsi
  mov    %ebx,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  jne    L264
  test   %ebp,%ebp
  jne    L42
L29:
  mov    $0xffffffff,%r12d
  jmp    L62
L219:
  cmp    $0x5,%r12d
  jg     L221
  lea    0x14(%rsp),%rdi
  call   <FD_ZERO@plt>
  movl   $0x2,0x18(%rsp)
  movl   $0x88b80,0x1c(%rsp)
L266:
  lea    0x14(%rsp),%r15
  jmp    L69
L221:
  mov    (%rsp),%rax
  lea    0x2(%rax),%rdi
  call   <getint@plt>
  mov    %eax,%ebp
  lea    0x14(%rsp),%rdi
  call   <FD_ZERO@plt>
  movl   $0x2,0x18(%rsp)
  movl   $0x88b80,0x1c(%rsp)
  lea    -0x6(%r12),%eax
  cmp    %ebp,%eax
  jne    L266
L217:
  mov    %r12d,%esi
  mov    (%rsp),%rdi
  call   <checksum@plt>
  cmp    $0x1,%eax
  mov    $0xfffffffe,%eax
  cmovne %eax,%r12d
L62:
  mov    0x428(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L118
  mov    %r12d,%eax
  add    $0x438,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L192:
  lea    0x20(%rsp),%rsi
  mov    $0x400,%edx
  mov    %ebx,%edi
  call   <read@plt>
  test   %eax,%eax
  jle    L47
  lea    0x20(%rsp),%rsi
  movslq %r12d,%rdi
  add    (%rsp),%rdi
  mov    %eax,0xc(%rsp)
  mov    %eax,%edx
  call   <memcpy@plt>
  add    0xc(%rsp),%r12d
  jmp    L47
L191:
  mov    $0x0,%ebp
  jmp    L172
L179:
  cmp    $0x5,%r12d
  jle    L217
  mov    %r14d,%ebp
L172:
  mov    (%rsp),%rax
  lea    0x2(%rax),%rdi
  call   <getint@plt>
  lea    -0x6(%r12),%edx
  cmp    %eax,%edx
  je     L217
L135:
  test   %ebp,%ebp
  jne    L217
L69:
  mov    %r15,%rsi
  mov    %ebx,%edi
  call   <FD_SET@plt>
  lea    0x18(%rsp),%r8
  mov    $0x0,%ecx
  mov    $0x0,%edx
  mov    %r15,%rsi
  mov    %r13d,%edi
  call   <select@plt>
  mov    %eax,%ebp
  mov    %r15,%rsi
  mov    %ebx,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  jne    L192
L47:
  test   %ebp,%ebp
  je     L179
  cmp    $0x5,%r12d
  jg     L191
  mov    $0x0,%ebp
  jmp    L135
L130:
  mov    (%rsp),%rax
  movzbl (%rax),%eax
  cmp    $0x18,%al
  ja     L219
  mov    $0x1200040,%edx
  bt     %rax,%rdx
  jae    L219
  mov    %r14d,%r12d
  jmp    L62
L118:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int listen(int fd, unsigned char *pak) {
  unsigned char buf[1024];
  fd_set readfs;
  struct timeval tout;
  int ret, res, STOP, TIMEOUT;
  int maxfd = fd + 1;
  int len = 0;
  STOP = 0;
  TIMEOUT = 0;
  FD_ZERO(&readfs);
  tout.tv_sec = 2;
  tout.tv_usec = 560000;
  while (STOP == 0) {
    FD_SET(fd, &readfs);
    ret = select(maxfd, &readfs, NULL, NULL, &tout);
    if (FD_ISSET(fd, &readfs)) {
      res = read(fd, buf, 1024);
      if (res > 0) {
        if (buf[0] == 0x06 || buf[0] == 0x15 || buf[0] == 0x18 || buf[0] == 0xa5) {
          STOP = 1;
          memcpy(pak, buf, res);
          len += res;
        }
      }
    }
    if (ret == 0) {
      STOP = 1;
      TIMEOUT = 1;
    }
  }
  if (TIMEOUT == 1)
    return -1;
  if (pak[0] == 0x06 || pak[0] == 0x15 || pak[0] == 0x18)
    return 1;
  STOP = 0;
  if (len >= 6 && (len - 6) == getint(&pak[2]))
    STOP = 1;
  TIMEOUT = 0;
  FD_ZERO(&readfs);
  tout.tv_sec = 2;
  tout.tv_usec = 560000;
  while (STOP == 0) {
    FD_SET(fd, &readfs);
    ret = select(maxfd, &readfs, NULL, NULL, &tout);
    if (FD_ISSET(fd, &readfs)) {
      res = read(fd, buf, 1024);
      if (res > 0) {
        memcpy(&pak[len], buf, res);
        len += res;
      }
    }
    if (ret == 0) {
      STOP = 1;
      TIMEOUT = 1;
    }
    if (len >= 6 && (len - 6) == getint(&pak[2]))
      STOP = 1;
  }
  if (checksum(pak, len) == 1)
    return len;
  else
    return -2;
}
```