user: Please show me the C implementation that matches the assembly code listed below:

```asm
<main_loop>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x448,%rsp
  mov    %edi,0xc(%rsp)
  mov    %esi,%r12d
  mov    %edx,%ebp
  mov    %fs:0x28,%rax
  mov    %rax,0x438(%rsp)
  xor    %eax,%eax
  movl   $0x0,0x1c(%rsp)
  movl   $0x0,0x20(%rsp)
  movl   $0x0,0x24(%rsp)
  movl   $0xffffffff,0x28(%rsp)
  movl   $0xffffffff,0x2c(%rsp)
  lea    0x18(%rsp),%rbx
  lea    D25(%rip),%r15
  jmp    L243
L74:
  mov    %r15,%rdi
  call   <perror@plt>
L243:
  mov    %rbx,%rdi
  call   <FD_ZERO@plt>
  mov    0x28(%rsp),%edi
  test   %edi,%edi
  cmovs  %r12d,%edi
  mov    %rbx,%rsi
  call   <FD_SET@plt>
  mov    0x2c(%rsp),%edi
  test   %edi,%edi
  cmovs  %ebp,%edi
  mov    %rbx,%rsi
  call   <FD_SET@plt>
  mov    %rbx,%rsi
  mov    0xc(%rsp),%edi
  call   <FD_SET@plt>
  mov    0x28(%rsp),%edi
  mov    0x2c(%rsp),%eax
  cmp    %eax,%edi
  cmovl  %eax,%edi
  mov    0xc(%rsp),%eax
  cmp    %eax,%edi
  cmovl  %eax,%edi
  cmp    %ebp,%edi
  cmovl  %ebp,%edi
  cmp    %r12d,%edi
  cmovl  %r12d,%edi
  add    $0x1,%edi
  mov    $0x0,%r8d
  mov    $0x0,%ecx
  mov    $0x0,%edx
  mov    %rbx,%rsi
  call   <select@plt>
  test   %rax,%rax
  js     L74
  mov    %rbx,%rsi
  mov    %r12d,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  jne    L271
L109:
  mov    %rbx,%rsi
  mov    %ebp,%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  jne    L81
L22:
  cmpl   $0x0,0x1c(%rsp)
  jne    L233
  mov    0x28(%rsp),%edi
  test   %edi,%edi
  jns    L224
L219:
  cmpl   $0x0,0x20(%rsp)
  jne    L282
  mov    0x2c(%rsp),%edi
  test   %edi,%edi
  jns    L23
L157:
  cmpl   $0x0,0x24(%rsp)
  jne    L61
  mov    %rbx,%rsi
  mov    0xc(%rsp),%edi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  je     L243
L61:
  lea    0x24(%rsp),%rcx
  lea    0x30(%rsp),%rsi
  lea    0xc(%rsp),%rdi
  mov    $0x400,%edx
  call   <receive_data@plt>
  test   %rax,%rax
  je     L243
  lea    0x30(%rsp),%r13
  lea    0x0(%r13,%rax,1),%r14
  jmp    L75
L271:
  mov    0x28(%rsp),%edi
  shr    $0x1f,%edi
  call   <assert@plt>
  mov    %r12d,%edi
  call   <accept_conn@plt>
  mov    %eax,0x28(%rsp)
  jmp    L109
L81:
  mov    0x2c(%rsp),%edi
  shr    $0x1f,%edi
  call   <assert@plt>
  mov    %ebp,%edi
  call   <accept_conn@plt>
  mov    %eax,0x2c(%rsp)
  jmp    L22
L224:
  mov    %rbx,%rsi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  je     L219
L233:
  lea    0x1c(%rsp),%rcx
  lea    0x30(%rsp),%rsi
  lea    0x28(%rsp),%rdi
  mov    $0x400,%edx
  call   <receive_data@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L219
  lea    0x30(%rsp),%r14
  mov    %rax,%rsi
  mov    %r14,%rdi
  call   <clear_high_bit@plt>
  mov    %r13d,%edx
  mov    %r14,%rsi
  mov    0xc(%rsp),%edi
  call   <write@plt>
  test   %rax,%rax
  jns    L219
  lea    D34(%rip),%rdi
  call   <perror@plt>
  jmp    L219
L23:
  mov    %rbx,%rsi
  call   <FD_ISSET@plt>
  test   %rax,%rax
  je     L157
L282:
  lea    0x20(%rsp),%rcx
  lea    0x30(%rsp),%rsi
  lea    0x2c(%rsp),%rdi
  mov    $0x400,%edx
  call   <receive_data@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L157
  lea    0x30(%rsp),%r14
  mov    %rax,%rsi
  mov    %r14,%rdi
  call   <set_high_bit@plt>
  mov    %r13d,%edx
  mov    %r14,%rsi
  mov    0xc(%rsp),%edi
  call   <write@plt>
  test   %rax,%rax
  jns    L157
  lea    D34(%rip),%rdi
  call   <perror@plt>
  jmp    L157
L202:
  mov    0x2c(%rsp),%edi
  test   %edi,%edi
  jns    L203
L4:
  add    $0x1,%r13
  cmp    %r14,%r13
  je     L243
L75:
  mov    %r13,%rsi
  movzbl 0x0(%r13),%eax
  test   %al,%al
  js     L202
  mov    0x28(%rsp),%edi
  test   %edi,%edi
  js     L4
  mov    $0x1,%edx
  call   <write@plt>
  test   %rax,%rax
  jns    L4
  lea    D34(%rip),%rdi
  call   <perror@plt>
  lea    0x28(%rsp),%rdi
  call   <close_conn@plt>
  movl   $0x0,0x1c(%rsp)
  jmp    L4
L203:
  and    $0x7f,%eax
  mov    %al,0x0(%r13)
  mov    $0x1,%edx
  call   <write@plt>
  test   %rax,%rax
  jns    L4
  lea    D34(%rip),%rdi
  call   <perror@plt>
  lea    0x2c(%rsp),%rdi
  call   <close_conn@plt>
  movl   $0x0,0x20(%rsp)
  jmp    L4
```

tool_calls: name: parse_data
arguments: data_label: D25
type_infered: string
name: parse_data
arguments: data_label: D34
type_infered: string

tool: D25: select

tool: D34: write

assistant: ```c
void main_loop(int serial_fd, int low_listener, int high_listener) {
  fd_set rdfds;
  int low_poll = 0, high_poll = 0, serial_poll = 0;
  int low_fd = -1, high_fd = -1;
  while (1) {
    char buf[1024];
    ssize_t bytes;
    int max;
    FD_ZERO(&rdfds);
    FD_SET(low_fd < 0 ? low_listener : low_fd, &rdfds);
    FD_SET(high_fd < 0 ? high_listener : high_fd, &rdfds);
    FD_SET(serial_fd, &rdfds);
    max = ((low_fd) < (low_listener) ? (low_listener) : (low_fd));
    max = ((max) < (high_fd) ? (high_fd) : (max));
    max = ((max) < (high_listener) ? (high_listener) : (max));
    max = ((max) < (serial_fd) ? (serial_fd) : (max));
    if (select(max + 1, &rdfds, NULL, NULL, NULL) < 0) {
      perror("select");
      continue;
    }
    if (FD_ISSET(low_listener, &rdfds)) {
      assert(low_fd < 0);
      low_fd = accept_conn(low_listener);
    }
    if (FD_ISSET(high_listener, &rdfds)) {
      assert(high_fd < 0);
      high_fd = accept_conn(high_listener);
    }
    if (low_poll || (low_fd >= 0 && FD_ISSET(low_fd, &rdfds))) {
      if ((bytes = receive_data(&low_fd, &buf[0], sizeof(buf), &low_poll)) > 0) {
        clear_high_bit(&buf[0], bytes);
        if (write(serial_fd, &buf[0], bytes) < 0)
          perror("write");
      }
    }
    if (high_poll || (high_fd >= 0 && FD_ISSET(high_fd, &rdfds))) {
      if ((bytes = receive_data(&high_fd, &buf[0], sizeof(buf), &high_poll)) > 0) {
        set_high_bit(&buf[0], bytes);
        if (write(serial_fd, &buf[0], bytes) < 0)
          perror("write");
      }
    }
    if (serial_poll || FD_ISSET(serial_fd, &rdfds)) {
      if ((bytes = receive_data(&serial_fd, &buf[0], sizeof(buf), &serial_poll)) > 0) {
        ssize_t i;
        for (i = 0; i < bytes; ++i) {
          if (buf[i] & 0x80) {
            if (high_fd >= 0) {
              buf[i] &= 0x7f;
              if ((write(high_fd, &buf[i], 1)) < 0) {
                perror("write");
                close_conn(&high_fd);
                high_poll = 0;
              }
            }
          } else {
            if (low_fd >= 0) {
              if ((write(low_fd, &buf[i], 1)) < 0) {
                perror("write");
                close_conn(&low_fd);
                low_poll = 0;
              }
            }
          }
        }
      }
    }
  }
}
```