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

```asm
<getkey>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    %rsi,-0x70(%rbp)
  mov    %edx,-0x74(%rbp)
  mov    %rcx,-0x80(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    %rsp,%rax
  mov    %rax,%rbx
  mov    $0x0,%eax
  call   <BN_CTX_new@plt>
  mov    %rax,-0x60(%rbp)
  mov    -0x80(%rbp),%rax
  mov    %rax,%rdi
  call   <BN_num_bytes@plt>
  sub    $0x1,%eax
  cltq
  mov    %rax,-0x58(%rbp)
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x50(%rbp)
  mov    D19(%rip),%rax
  mov    (%rax),%eax
  movslq %eax,%rdx
  sub    $0x1,%rdx
  mov    %rdx,-0x48(%rbp)
  movslq %eax,%rdx
  mov    %rdx,%r14
  mov    $0x0,%r15d
  movslq %eax,%rdx
  mov    %rdx,%r12
  mov    $0x0,%r13d
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    $0x10,%eax
  sub    $0x1,%rax
  add    %rdx,%rax
  mov    $0x10,%esi
  mov    $0x0,%edx
  div    %rsi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L5:
  cmp    %rdx,%rsp
  je     L2
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L5
L2:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L51
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L51:
  mov    %rsp,%rax
  add    $0x3,%rax
  shr    $0x2,%rax
  shl    $0x2,%rax
  mov    %rax,-0x40(%rbp)
  mov    -0x58(%rbp),%rcx
  mov    -0x50(%rbp),%rdx
  mov    -0x74(%rbp),%esi
  mov    -0x70(%rbp),%rax
  mov    %rax,%rdi
  call   <fdh@plt>
  mov    -0x68(%rbp),%rdx
  mov    -0x58(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <BN_bin2bn@plt>
  jmp    L16
L22:
  mov    D19(%rip),%rax
  mov    (%rax),%edx
  mov    -0x50(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    D19(%rip),%rax
  mov    (%rax),%esi
  mov    -0x58(%rbp),%rcx
  mov    -0x50(%rbp),%rdx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <fdh@plt>
  mov    -0x68(%rbp),%rdx
  mov    -0x58(%rbp),%rcx
  mov    -0x50(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <BN_bin2bn@plt>
L16:
  mov    -0x60(%rbp),%rdx
  mov    -0x80(%rbp),%rcx
  mov    -0x68(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <BN_kronecker@plt>
  cmp    $0x1,%eax
  jne    L22
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <BN_CTX_free@plt>
  mov    $0x0,%eax
  mov    %rbx,%rsp
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L8
  call   <__stack_chk_fail@plt>
L8:
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
```

assistant: ```c
int getkey(BIGNUM *a, const uint8_t *id, int len, const BIGNUM *N) {
  uint8_t *tmp;
  BN_CTX *ctx = BN_CTX_new();
  const size_t num_bytes = BN_num_bytes(N) - 1;
  uint8_t *buf = (uint8_t *)malloc(num_bytes);
  uint8_t hash[RIPEMD160_DIGEST_LENGTH];
  fdh(id, len, buf, num_bytes);
  BN_bin2bn(hash, num_bytes, a);
  while (BN_kronecker(a, N, ctx) != 1) {
    memcpy(hash, buf, RIPEMD160_DIGEST_LENGTH);
    fdh(hash, RIPEMD160_DIGEST_LENGTH, buf, num_bytes);
    BN_bin2bn(buf, num_bytes, a);
  }
  free(buf);
  BN_CTX_free(ctx);
  return 0;
}
```