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

```asm
<cms_copy_content>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x1018(%rsp)
  xor    %eax,%eax
  mov    %rdi,%r13
  mov    %rsi,%rbp
  mov    %edx,%r14d
  test   %rdi,%rdi
  je     L22
  mov    D26(%rip),%rax
  mov    %edx,%ecx
  movb   $0x0,0xf(%rsp)
  mov    %rdi,%r12
  and    (%rax),%ecx
  jne    L65
L133:
  lea    0x10(%rsp),%rbx
  jmp    L110
  nopl   0x0(%rax,%rax,1)
L27:
  mov    %eax,%edx
  mov    %rbx,%rsi
  mov    %r12,%rdi
  call   <BIO_write@plt>
  cmp    %r15d,%eax
  jne    L178
L110:
  mov    $0x1000,%edx
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  call   <BIO_read@plt>
  mov    %eax,%r15d
  test   %eax,%eax
  jg     L27
  mov    %rbp,%rdi
  call   <BIO_method_type@plt>
  mov    D7(%rip),%rdx
  cmp    (%rdx),%rax
  je     L71
L51:
  test   %r15d,%r15d
  jne    L178
  mov    D26(%rip),%rax
  and    (%rax),%r14d
  jne    L158
L21:
  mov    $0x1,%r13d
  jmp    L79
  nopw   0x0(%rax,%rax,1)
L71:
  mov    %rbp,%rdi
  call   <BIO_get_cipher_status@plt>
  test   %eax,%eax
  jne    L51
  nopl   0x0(%rax)
L178:
  xor    %r13d,%r13d
L79:
  cmpb   $0x0,0xf(%rsp)
  je     L114
  mov    %r12,%rdi
  call   <BIO_free@plt>
L114:
  mov    0x1018(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L97
  add    $0x1028,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L65:
  xor    %eax,%eax
  call   <BIO_s_mem@plt>
  mov    %eax,%edi
  call   <BIO_new@plt>
  xor    %esi,%esi
  mov    %rax,%rdi
  mov    %rax,%r12
  call   <BIO_set_mem_eof_return@plt>
L179:
  test   %r12,%r12
  je     L101
  cmp    %r13,%r12
  setne  0xf(%rsp)
  jmp    L133
  nopl   (%rax)
L158:
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <SMIME_text@plt>
  mov    %eax,%r13d
  test   %eax,%eax
  jne    L21
  mov    D32(%rip),%rax
  mov    (%rax),%esi
  mov    D15(%rip),%rax
  mov    (%rax),%edi
  call   <CMSerr@plt>
  jmp    L79
  nopw   0x0(%rax,%rax,1)
L22:
  call   <BIO_s_null@plt>
  mov    %eax,%edi
  call   <BIO_new@plt>
  mov    %rax,%r12
  jmp    L179
  nopl   0x0(%rax)
L101:
  mov    D46(%rip),%rax
  xor    %r13d,%r13d
  mov    (%rax),%esi
  mov    D15(%rip),%rax
  mov    (%rax),%edi
  call   <CMSerr@plt>
  jmp    L114
L97:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int cms_copy_content(BIO *out, BIO *in, unsigned int flags) {
  unsigned char buf[4096];
  int r = 0, i;
  BIO *tmpout = NULL;
  if (out == NULL)
    tmpout = BIO_new(BIO_s_null());
  else if (flags & CMS_TEXT) {
    tmpout = BIO_new(BIO_s_mem());
    BIO_set_mem_eof_return(tmpout, 0);
  } else
    tmpout = out;
  if (!tmpout) {
    CMSerr(CMS_F_CMS_COPY_CONTENT, ERR_R_MALLOC_FAILURE);
    goto err;
  }
  for (;;) {
    i = BIO_read(in, buf, sizeof(buf));
    if (i <= 0) {
      if (BIO_method_type(in) == BIO_TYPE_CIPHER) {
        if (!BIO_get_cipher_status(in))
          goto err;
      }
      if (i < 0)
        goto err;
      break;
    }
    if (tmpout && (BIO_write(tmpout, buf, i) != i))
      goto err;
  }
  if (flags & CMS_TEXT) {
    if (!SMIME_text(tmpout, out)) {
      CMSerr(CMS_F_CMS_COPY_CONTENT, CMS_R_SMIME_TEXT_ERROR);
      goto err;
    }
  }
  r = 1;
err:
  if (tmpout && (tmpout != out))
    BIO_free(tmpout);
  return r;
}
```