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

```asm
<cp>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x1028(%rsp)
  mov    D31(%rip),%rax
  mov    %rsi,%rbp
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <open@plt>
  test   %eax,%eax
  js     L57
  mov    %eax,%edi
  lea    0x1c(%rsp),%rsi
  mov    %eax,%r12d
  call   <fstat@plt>
  mov    0x1c(%rsp),%edi
  call   <S_ISDIR@plt>
  test   %rax,%rax
  jne    L108
  mov    D27(%rip),%rax
  mov    0x1c(%rsp),%edx
  mov    %rbp,%rdi
  mov    (%rax),%esi
  mov    D40(%rip),%rax
  or     (%rax),%esi
  mov    D9(%rip),%rax
  or     (%rax),%esi
  xor    %eax,%eax
  call   <open@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  js     L108
  lea    0x20(%rsp),%rbx
L119:
  mov    $0x1000,%edx
  mov    %rbx,%rsi
  mov    %r12d,%edi
  call   <read@plt>
  mov    %eax,%r13d
  test   %eax,%eax
  jle    L93
  mov    %rbx,%r14
  nopl   0x0(%rax)
L135:
  mov    %r13d,%edx
  mov    %r14,%rsi
  mov    %ebp,%edi
  call   <write@plt>
  test   %eax,%eax
  js     L89
  sub    %eax,%r13d
  cltq
  add    %rax,%r14
  test   %r13d,%r13d
  jg     L135
  jmp    L119
  nopl   0x0(%rax,%rax,1)
L89:
  mov    D49(%rip),%r15
  mov    D61(%rip),%rax
  mov    (%r15),%edx
  cmp    (%rax),%edx
  je     L135
L83:
  mov    %r12d,%edi
  mov    %edx,0xc(%rsp)
  call   <close@plt>
  mov    %ebp,%edi
  call   <close@plt>
  mov    0xc(%rsp),%edx
L17:
  mov    %edx,(%r15)
  mov    $0xffffffff,%r13d
L139:
  mov    0x1028(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L144
  add    $0x1038,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L93:
  jne    L68
  mov    %ebp,%edi
  call   <close@plt>
  test   %eax,%eax
  js     L108
  mov    %ebp,%edi
  call   <fsync@plt>
  mov    %r12d,%edi
  call   <close@plt>
  jmp    L139
L108:
  mov    D49(%rip),%r15
  mov    %r12d,%edi
  mov    (%r15),%edx
  mov    %edx,0xc(%rsp)
  call   <close@plt>
  mov    0xc(%rsp),%edx
  jmp    L17
L57:
  mov    $0xffffffff,%r13d
  jmp    L139
L68:
  mov    D49(%rip),%r15
  mov    (%r15),%edx
  jmp    L83
L144:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int cp(const char *from, const char *to) {
  int fd_to, fd_from;
  char buf[4096];
  ssize_t nread;
  int saved_errno;
  struct stat sb;
  fd_from = open(from, O_RDONLY);
  if (fd_from < 0)
    return -1;
  fstat(fd_from, &sb);
  if (S_ISDIR(sb.st_mode)) {
    fd_to = -1;
    goto out_error;
  }
  fd_to = open(to, O_WRONLY | O_CREAT | O_EXCL, sb.st_mode);
  if (fd_to < 0)
    goto out_error;
  while (nread = read(fd_from, buf, sizeof buf), nread > 0) {
    char *out_ptr = buf;
    ssize_t nwritten;
    do {
      nwritten = write(fd_to, out_ptr, nread);
      if (nwritten >= 0) {
        nread -= nwritten;
        out_ptr += nwritten;
      } else if (errno != EINTR) {
        goto out_error;
      }
    } while (nread > 0);
  }
  if (nread == 0) {
    if (close(fd_to) < 0) {
      fd_to = -1;
      goto out_error;
    } else {
      fsync(fd_to);
    }
    close(fd_from);
    return 0;
  }
out_error:
  saved_errno = errno;
  close(fd_from);
  if (fd_to >= 0)
    close(fd_to);
  errno = saved_errno;
  return -1;
}
```