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

```asm
<PKCS5_pbe_set0_algor>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r14
  mov    %esi,%r15d
  mov    %edx,%r12d
  mov    %rcx,%r13
  mov    %r8d,%ebp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  movq   $0x0,(%rsp)
  call   <PBEPARAM_new@plt>
  test   %rax,%rax
  je     L29
  mov    %rax,%rbx
  test   %r12d,%r12d
  jle    L148
L4:
  mov    0x4(%rbx),%edi
  mov    %r12d,%esi
  call   <ASN1_INTEGER_set@plt>
  test   %eax,%eax
  je     L7
  test   %ebp,%ebp
  jne    L100
  mov    D48(%rip),%rax
  mov    (%rax),%ebp
L100:
  mov    %ebp,%edx
  mov    $0x0,%esi
  mov    (%rbx),%edi
  call   <ASN1_STRING_set@plt>
  test   %eax,%eax
  je     L64
  mov    (%rbx),%edi
  call   <ASN1_STRING_data@plt>
  mov    %rax,%rdi
  test   %r13,%r13
  je     L133
  mov    %ebp,%edx
  mov    %r13,%rsi
  call   <memcpy@plt>
L46:
  mov    %rsp,%rdx
  mov    D57(%rip),%rsi
  mov    %rbx,%rdi
  call   <ASN1_item_pack@plt>
  test   %eax,%eax
  je     L55
  mov    %rbx,%rdi
  call   <PBEPARAM_free@plt>
  mov    (%rsp),%rbp
  mov    D62(%rip),%rax
  mov    (%rax),%ebx
  mov    %r15d,%edi
  call   <OBJ_nid2obj@plt>
  mov    %eax,%esi
  mov    %rbp,%rcx
  mov    %ebx,%edx
  mov    %r14,%rdi
  call   <X509_ALGOR_set0@plt>
  mov    %rax,%rdx
  mov    $0x1,%eax
  test   %rdx,%rdx
  je     L113
  jmp    L101
L29:
  mov    D69(%rip),%rax
  mov    (%rax),%edi
  call   <ASN1error@plt>
  jmp    L113
L148:
  mov    D29(%rip),%rax
  mov    (%rax),%r12d
  jmp    L4
L7:
  mov    D69(%rip),%rax
  mov    (%rax),%edi
  call   <ASN1error@plt>
  jmp    L18
L64:
  mov    D69(%rip),%rax
  mov    (%rax),%edi
  call   <ASN1error@plt>
L18:
  mov    %rbx,%rdi
  call   <PBEPARAM_free@plt>
L113:
  mov    (%rsp),%rdi
  call   <ASN1_STRING_free@plt>
  mov    $0x0,%eax
L101:
  mov    0x8(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L38
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L133:
  mov    %ebp,%esi
  call   <arc4random_buf@plt>
  jmp    L46
L55:
  mov    D69(%rip),%rax
  mov    (%rax),%edi
  call   <ASN1error@plt>
  jmp    L18
L38:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, const unsigned char *salt, int saltlen) {
  PBEPARAM *pbe = NULL;
  ASN1_STRING *pbe_str = NULL;
  unsigned char *sstr;
  pbe = PBEPARAM_new();
  if (!pbe) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  if (iter <= 0)
    iter = PKCS5_DEFAULT_ITER;
  if (!ASN1_INTEGER_set(pbe->iter, iter)) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  if (!saltlen)
    saltlen = PKCS5_SALT_LEN;
  if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  sstr = ASN1_STRING_data(pbe->salt);
  if (salt)
    memcpy(sstr, salt, saltlen);
  else
    arc4random_buf(sstr, saltlen);
  if (!ASN1_item_pack(pbe, &PBEPARAM_it, &pbe_str)) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    goto err;
  }
  PBEPARAM_free(pbe);
  pbe = NULL;
  if (X509_ALGOR_set0(algor, OBJ_nid2obj(alg), V_ASN1_SEQUENCE, pbe_str))
    return 1;
err:
  if (pbe != NULL)
    PBEPARAM_free(pbe);
  ASN1_STRING_free(pbe_str);
  return 0;
}
```