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

```asm
<pkcs7_encode_rinfo>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %edx,-0x44(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x10(%rbp)
  movq   $0x0,-0x20(%rbp)
  movl   $0x0,-0x2c(%rbp)
  mov    -0x38(%rbp),%rax
  mov    0x4(%rax),%eax
  mov    %eax,%edi
  call   <X509_get_pubkey@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L65
  mov    $0x0,%eax
  jmp    L66
L65:
  mov    -0x10(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_new@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L102
  mov    $0x0,%eax
  jmp    L66
L102:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <EVP_PKEY_encrypt_init@plt>
  test   %rax,%rax
  jle    L9
  mov    D53(%rip),%rax
  mov    (%rax),%ecx
  mov    D9(%rip),%rax
  mov    (%rax),%edx
  mov    -0x38(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %rsi,%r9
  mov    $0x0,%r8d
  mov    $0xffffffff,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_ctrl@plt>
  test   %rax,%rax
  jg     L37
  mov    D51(%rip),%rax
  mov    (%rax),%edx
  mov    D20(%rip),%rax
  mov    (%rax),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <PKCS7err@plt>
  jmp    L71
L37:
  mov    -0x44(%rbp),%esi
  mov    -0x40(%rbp),%rcx
  lea    -0x28(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %esi,%r8d
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_encrypt@plt>
  test   %rax,%rax
  jle    L48
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <OPENSSL_malloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L17
  mov    D24(%rip),%rax
  mov    (%rax),%edx
  mov    D20(%rip),%rax
  mov    (%rax),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <PKCS7err@plt>
  jmp    L71
L17:
  mov    -0x44(%rbp),%edi
  mov    -0x40(%rbp),%rcx
  lea    -0x28(%rbp),%rdx
  mov    -0x20(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %edi,%r8d
  mov    %rax,%rdi
  call   <EVP_PKEY_encrypt@plt>
  test   %rax,%rax
  jle    L47
  mov    -0x28(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  mov    (%rax),%eax
  mov    -0x20(%rbp),%rcx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <ASN1_STRING_set0@plt>
  movq   $0x0,-0x20(%rbp)
  movl   $0x1,-0x2c(%rbp)
  jmp    L71
L9:
  nop
  jmp    L71
L48:
  nop
  jmp    L71
L47:
  nop
L71:
  cmpq   $0x0,-0x10(%rbp)
  je     L13
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <EVP_PKEY_free@plt>
L13:
  cmpq   $0x0,-0x18(%rbp)
  je     L106
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_free@plt>
L106:
  cmpq   $0x0,-0x20(%rbp)
  je     L43
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <OPENSSL_free@plt>
L43:
  mov    -0x2c(%rbp),%eax
L66:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L27
  call   <__stack_chk_fail@plt>
L27:
  leave
  ret
```

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;
}
```