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

```asm
<EVP_BytesToKey>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  mov    %rsi,%r13
  push   %r12
  push   %rbx
  sub    $0x58,%rsp
  mov    0x10(%rbp),%rax
  mov    %rdx,-0x50(%rbp)
  mov    %rcx,-0x58(%rbp)
  mov    %rsp,%rcx
  mov    %rax,-0x78(%rbp)
  mov    0x18(%rbp),%rax
  mov    %rdi,-0x70(%rbp)
  mov    %r8d,-0x5c(%rbp)
  mov    %r9d,-0x44(%rbp)
  mov    %rax,-0x80(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  mov    D5(%rip),%rax
  movslq (%rax),%rax
  mov    %eax,-0x60(%rbp)
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L310
L355:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L355
L310:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L337
L132:
  mov    -0x70(%rbp),%r15
  movl   $0x0,-0x3c(%rbp)
  mov    %rsp,%r12
  mov    %r15,%rdi
  call   <EVP_CIPHER_key_length@plt>
  mov    %r15,%rdi
  mov    %eax,%ebx
  mov    %eax,-0x48(%rbp)
  call   <EVP_CIPHER_iv_length@plt>
  xor    %edi,%edi
  mov    %eax,-0x68(%rbp)
  mov    %eax,%r15d
  mov    D39(%rip),%rax
  cmp    %ebx,(%rax)
  setge  %dil
  call   <OPENSSL_assert@plt>
  mov    D21(%rip),%rax
  xor    %edi,%edi
  cmp    %r15d,(%rax)
  setge  %dil
  call   <OPENSSL_assert@plt>
  cmpq   $0x0,-0x58(%rbp)
  je     L100
  xor    %eax,%eax
  lea    -0x3c(%rbp),%r15
  call   <EVP_MD_CTX_new@plt>
  movl   $0x0,-0x64(%rbp)
  mov    %rax,%r14
  test   %rax,%rax
  je     L187
L49:
  xor    %edx,%edx
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <EVP_DigestInit_ex@plt>
  test   %eax,%eax
  je     L187
  mov    -0x64(%rbp),%edi
  test   %edi,%edi
  je     L270
  mov    -0x3c(%rbp),%edx
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <EVP_DigestUpdate@plt>
  test   %eax,%eax
  je     L187
L270:
  mov    -0x5c(%rbp),%edx
  mov    -0x58(%rbp),%rsi
  mov    %r14,%rdi
  call   <EVP_DigestUpdate@plt>
  test   %eax,%eax
  je     L187
  cmpq   $0x0,-0x50(%rbp)
  je     L198
  mov    D33(%rip),%rax
  mov    -0x50(%rbp),%rsi
  mov    %r14,%rdi
  mov    (%rax),%edx
  call   <EVP_DigestUpdate@plt>
  test   %eax,%eax
  je     L187
L198:
  mov    %r15,%rdx
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <EVP_DigestFinal_ex@plt>
  test   %eax,%eax
  je     L187
  cmpl   $0x1,-0x44(%rbp)
  mov    $0x1,%ebx
  ja     L246
  jmp    L227
  nop
L191:
  mov    -0x3c(%rbp),%edx
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <EVP_DigestUpdate@plt>
  test   %eax,%eax
  je     L187
  mov    %r15,%rdx
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <EVP_DigestFinal_ex@plt>
  test   %eax,%eax
  je     L187
  add    $0x1,%ebx
  cmp    -0x44(%rbp),%ebx
  je     L227
L246:
  xor    %edx,%edx
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <EVP_DigestInit_ex@plt>
  test   %eax,%eax
  jne    L191
L187:
  movl   $0x0,-0x48(%rbp)
L269:
  mov    %r14,%rdi
  call   <EVP_MD_CTX_free@plt>
  mov    -0x60(%rbp),%esi
  mov    %r12,%rdi
  call   <OPENSSL_cleanse@plt>
L100:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L75
  mov    -0x48(%rbp),%eax
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   0x0(%rax)
L337:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L132
  nopl   0x0(%rax,%rax,1)
L227:
  mov    -0x48(%rbp),%esi
  xor    %edx,%edx
  test   %esi,%esi
  jne    L219
L73:
  mov    -0x68(%rbp),%eax
  test   %eax,%eax
  je     L363
  movl   $0x0,-0x48(%rbp)
L276:
  mov    -0x3c(%rbp),%eax
  cmp    %edx,%eax
  jne    L110
L245:
  addl   $0x1,-0x64(%rbp)
  jmp    L49
L219:
  mov    -0x48(%rbp),%r8d
  mov    -0x3c(%rbp),%edi
  xor    %eax,%eax
  mov    -0x78(%rbp),%rcx
  mov    %r8,%rsi
  nopl   0x0(%rax,%rax,1)
L195:
  mov    %esi,%r9d
  mov    %eax,%edx
  sub    %eax,%r9d
  cmp    %rdi,%rax
  je     L243
  test   %rcx,%rcx
  je     L175
  movzbl (%r12,%rax,1),%r9d
  add    $0x1,%rcx
  mov    %r9b,-0x1(%rcx)
L175:
  add    $0x1,%rax
  add    $0x1,%edx
  cmp    %r8,%rax
  jne    L195
  mov    %rcx,-0x78(%rbp)
  jmp    L73
L110:
  mov    -0x68(%rbp),%esi
  mov    -0x80(%rbp),%rcx
  jmp    L163
  nopw   0x0(%rax,%rax,1)
L83:
  cmp    %edx,%eax
  je     L317
L163:
  test   %rcx,%rcx
  je     L66
  mov    %edx,%edi
  add    $0x1,%rcx
  movzbl (%r12,%rdi,1),%edi
  mov    %dil,-0x1(%rcx)
L66:
  add    $0x1,%edx
  sub    $0x1,%esi
  jne    L83
  mov    %rcx,-0x80(%rbp)
L135:
  mov    -0x48(%rbp),%edx
  test   %edx,%edx
  je     L363
  movl   $0x0,-0x68(%rbp)
  jmp    L245
L243:
  mov    %rcx,-0x78(%rbp)
  mov    -0x68(%rbp),%ecx
  mov    %r9d,-0x48(%rbp)
  test   %ecx,%ecx
  je     L135
  jmp    L276
  nopl   0x0(%rax,%rax,1)
L317:
  mov    %esi,-0x68(%rbp)
  mov    %rcx,-0x80(%rbp)
  jmp    L245
L363:
  mov    -0x70(%rbp),%rdi
  call   <EVP_CIPHER_key_length@plt>
  mov    %eax,-0x48(%rbp)
  jmp    L269
L75:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, const unsigned char *salt, const unsigned char *data, int datal, int count, unsigned char *key, unsigned char *iv) {
  EVP_MD_CTX *c;
  unsigned char md_buf[EVP_MAX_MD_SIZE];
  int niv, nkey, addmd = 0;
  unsigned int mds = 0, i;
  int rv = 0;
  nkey = EVP_CIPHER_key_length(type);
  niv = EVP_CIPHER_iv_length(type);
  OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
  OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
  if (data == NULL)
    return nkey;
  c = EVP_MD_CTX_new();
  if (c == NULL)
    goto err;
  for (;;) {
    if (!EVP_DigestInit_ex(c, md, NULL))
      goto err;
    if (addmd++)
      if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
        goto err;
    if (!EVP_DigestUpdate(c, data, datal))
      goto err;
    if (salt != NULL)
      if (!EVP_DigestUpdate(c, salt, PKCS5_SALT_LEN))
        goto err;
    if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
      goto err;
    for (i = 1; i < (unsigned int)count; i++) {
      if (!EVP_DigestInit_ex(c, md, NULL))
        goto err;
      if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
        goto err;
      if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
        goto err;
    }
    i = 0;
    if (nkey) {
      for (;;) {
        if (nkey == 0)
          break;
        if (i == mds)
          break;
        if (key != NULL)
          *(key++) = md_buf[i];
        nkey--;
        i++;
      }
    }
    if (niv && (i != mds)) {
      for (;;) {
        if (niv == 0)
          break;
        if (i == mds)
          break;
        if (iv != NULL)
          *(iv++) = md_buf[i];
        niv--;
        i++;
      }
    }
    if ((nkey == 0) && (niv == 0))
      break;
  }
  rv = EVP_CIPHER_key_length(type);
err:
  EVP_MD_CTX_free(c);
  OPENSSL_cleanse(md_buf, sizeof(md_buf));
  return rv;
}
```