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

```asm
<pkcs7_encode_rinfo>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r12
  mov    %rsi,%r13
  mov    %edx,%r14d
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  mov    0x4(%rdi),%edi
  call   <X509_get_pubkey@plt>
  mov    $0x0,%r15d
  test   %rax,%rax
  je     L37
  mov    %rax,%rbx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_new@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L37
  mov    %rax,%rdi
  call   <EVP_PKEY_encrypt_init@plt>
  test   %rax,%rax
  jle    L126
  mov    %r12,%r9
  mov    $0x0,%r8d
  mov    D49(%rip),%rax
  mov    (%rax),%ecx
  mov    D22(%rip),%rax
  mov    (%rax),%edx
  mov    $0xffffffff,%esi
  mov    %rbp,%rdi
  call   <EVP_PKEY_CTX_ctrl@plt>
  test   %rax,%rax
  jle    L43
  mov    %rsp,%rdx
  mov    %r14d,%r8d
  mov    %r13,%rcx
  mov    $0x0,%esi
  mov    %rbp,%rdi
  call   <EVP_PKEY_encrypt@plt>
  test   %rax,%rax
  jle    L92
  mov    (%rsp),%rdi
  call   <OPENSSL_malloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L51
  mov    %rsp,%rdx
  mov    %r14d,%r8d
  mov    %r13,%rcx
  mov    %rax,%rsi
  mov    %rbp,%rdi
  call   <EVP_PKEY_encrypt@plt>
  test   %rax,%rax
  jle    L128
  mov    (%rsp),%rdx
  mov    %r15,%rsi
  mov    (%r12),%edi
  call   <ASN1_STRING_set0@plt>
  mov    $0x1,%r15d
  jmp    L17
L43:
  mov    D36(%rip),%rax
  mov    (%rax),%esi
  mov    D25(%rip),%rax
  mov    (%rax),%edi
  call   <PKCS7err@plt>
  jmp    L17
L51:
  mov    D19(%rip),%rax
  mov    (%rax),%esi
  mov    D25(%rip),%rax
  mov    (%rax),%edi
  call   <PKCS7err@plt>
  jmp    L17
L126:
  mov    $0x0,%r15d
L17:
  mov    %rbx,%rdi
  call   <EVP_PKEY_free@plt>
  mov    %rbp,%rdi
  call   <EVP_PKEY_CTX_free@plt>
  jmp    L37
L92:
  mov    $0x0,%r15d
  jmp    L17
L128:
  mov    %rbx,%rdi
  call   <EVP_PKEY_free@plt>
  mov    %rbp,%rdi
  call   <EVP_PKEY_CTX_free@plt>
  mov    %r15,%rdi
  call   <OPENSSL_free@plt>
  mov    $0x0,%r15d
L37:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L68
  mov    %r15d,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L68:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri, unsigned char *key, int keylen) {
  EVP_PKEY_CTX *pctx = NULL;
  EVP_PKEY *pkey = NULL;
  unsigned char *ek = NULL;
  int ret = 0;
  size_t eklen;
  pkey = X509_get_pubkey(ri->cert);
  if (!pkey)
    return 0;
  pctx = EVP_PKEY_CTX_new(pkey, NULL);
  if (!pctx)
    return 0;
  if (EVP_PKEY_encrypt_init(pctx) <= 0)
    goto err;
  if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT, EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0) {
    PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, PKCS7_R_CTRL_ERROR);
    goto err;
  }
  if (EVP_PKEY_encrypt(pctx, NULL, &eklen, key, keylen) <= 0)
    goto err;
  ek = OPENSSL_malloc(eklen);
  if (ek == NULL) {
    PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, ERR_R_MALLOC_FAILURE);
    goto err;
  }
  if (EVP_PKEY_encrypt(pctx, ek, &eklen, key, keylen) <= 0)
    goto err;
  ASN1_STRING_set0(ri->enc_key, ek, eklen);
  ek = NULL;
  ret = 1;
err:
  if (pkey)
    EVP_PKEY_free(pkey);
  if (pctx)
    EVP_PKEY_CTX_free(pctx);
  if (ek)
    OPENSSL_free(ek);
  return ret;
}
```