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

```asm
<flush_fd>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r12
  push   %rbx
  sub    $0x50,%rsp
  mov    %edi,-0x54(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x28(%rbp)
  xor    %eax,%eax
  mov    -0x54(%rbp),%eax
  mov    %eax,-0x30(%rbp)
  mov    D4(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x2c(%rbp)
L148:
  mov    %rsp,%rax
  mov    %rax,%r12
  mov    D36(%rip),%rax
  mov    (%rax),%ebx
  movslq %ebx,%rax
  sub    $0x1,%rax
  mov    %rax,-0x48(%rbp)
  movslq %ebx,%rax
  mov    %rax,%r14
  mov    $0x0,%r15d
  movslq %ebx,%rax
  mov    %rax,-0x70(%rbp)
  movq   $0x0,-0x68(%rbp)
  movslq %ebx,%rax
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%esi
  mov    $0x0,%edx
  div    %rsi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L110:
  cmp    %rdx,%rsp
  je     L175
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L110
L175:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L53
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L53:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x40(%rbp)
  lea    -0x30(%rbp),%rax
  mov    $0x0,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <poll@plt>
  mov    %eax,-0x4c(%rbp)
  cmpl   $0x0,-0x4c(%rbp)
  jns    L107
  mov    D7(%rip),%rax
  mov    (%rax),%edx
  mov    D40(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,%edx
  je     L94
  mov    D7(%rip),%rax
  mov    (%rax),%eax
  neg    %eax
  jmp    L84
L107:
  cmpl   $0x0,-0x4c(%rbp)
  jne    L128
  mov    $0x0,%eax
  jmp    L84
L128:
  mov    -0x40(%rbp),%rcx
  mov    -0x54(%rbp),%eax
  mov    %ebx,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jns    L67
  mov    D7(%rip),%rax
  mov    (%rax),%edx
  mov    D40(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,%edx
  je     L16
  mov    D7(%rip),%rax
  mov    (%rax),%edx
  mov    D55(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,%edx
  jne    L125
  mov    $0x0,%eax
  jmp    L84
L125:
  mov    D7(%rip),%rax
  mov    (%rax),%eax
  neg    %eax
  jmp    L84
L67:
  cmpq   $0x0,-0x38(%rbp)
  jne    L40
  mov    $0x0,%eax
  jmp    L84
L40:
  mov    %r12,%rsp
  jmp    L148
L16:
  nop
L94:
  mov    %r12,%rsp
  jmp    L148
L84:
  mov    %r12,%rsp
  mov    -0x28(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L146
  call   <__stack_chk_fail@plt>
L146:
  lea    -0x20(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
```

assistant: ```c
int flush_fd(int fd) {
  struct pollfd pollfd = {
      .fd = fd,
      .events = POLLIN,
  };
  for (;;) {
    char buf[LINE_MAX];
    ssize_t l;
    int r;
    r = poll(&pollfd, 1, 0);
    if (r < 0) {
      if (errno == EINTR)
        continue;
      return -errno;
    } else if (r == 0)
      return 0;
    l = read(fd, buf, sizeof(buf));
    if (l < 0) {
      if (errno == EINTR)
        continue;
      if (errno == EAGAIN)
        return 0;
      return -errno;
    } else if (l == 0)
      return 0;
  }
}
```