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

```asm
<KeyGen>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %edx,%r13d
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x88,%rsp
  mov    %rsi,0x28(%rsp)
  lea    0x60(%rsp),%r12
  lea    0x70(%rsp),%r14
  mov    0xc0(%rsp),%ebx
  mov    %ecx,0x3c(%rsp)
  mov    0xc8(%rsp),%rbp
  mov    %r8d,0x4(%rsp)
  mov    %r9d,0x38(%rsp)
  mov    %rdi,0x8(%rsp)
  xor    %edi,%edi
  mov    %fs:0x28,%rax
  mov    %rax,0x78(%rsp)
  xor    %eax,%eax
  call   <mpz_init@plt>
  xor    %edi,%edi
  call   <time@plt>
  mov    %eax,%edi
  call   <srand@plt>
  mov    %r12,0x20(%rsp)
  mov    %r12,0x40(%rsp)
  mov    %r14,0x48(%rsp)
L39:
  mov    (%r12),%edi
  add    $0x4,%r12
  call   <mpz_init@plt>
  cmp    %r14,%r12
  jne    L39
  test   %ebx,%ebx
  jle    L36
  movslq %ebx,%rax
  xor    %r12d,%r12d
  lea    D5(%rip),%r14
  mov    %rax,0x30(%rsp)
  lea    0x50(%rsp),%rax
  mov    %rax,0x10(%rsp)
  lea    0x58(%rsp),%rax
  mov    %rax,0x18(%rsp)
  jmp    L91
  nop
L118:
  mov    0x38(%rsp),%esi
  xor    %edi,%edi
  call   <mpz_legendre@plt>
  cmp    $0xffffffff,%eax
  je     L57
L77:
  mov    0x20(%rsp),%rdi
  mov    0x38(%rsp),%ecx
  xor    %esi,%esi
  mov    %rbp,%r9
  mov    0x4(%rsp),%edx
  mov    %r13d,%r8d
  call   <GetSquareRootsModulo@plt>
  mov    0x0(%rbp),%rdi
  mov    %r14,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L29
  mov    0x28(%rsp),%rax
  movslq %ebx,%rbx
  mov    0x60(%rsp,%rbx,4),%esi
  mov    (%rax,%r12,4),%edi
  add    $0x1,%r12
  call   <mpz_set@plt>
  mov    0x50(%rsp),%rdi
  call   <free@plt>
  mov    0x58(%rsp),%rdi
  call   <free@plt>
  cmp    0x30(%rsp),%r12
  je     L36
L91:
  mov    0x10(%rsp),%rsi
  mov    0x8(%rsp),%rdi
  mov    %rbp,%rcx
  mov    %r12d,%edx
  call   <GetHash@plt>
  mov    0x0(%rbp),%rdi
  mov    %r14,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L29
  mov    0x18(%rsp),%rsi
  mov    0x50(%rsp),%rdi
  mov    %rbp,%rdx
  call   <GetHexHash@plt>
  mov    0x0(%rbp),%rdi
  mov    %r14,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L29
  xor    %r15d,%r15d
  mov    0x58(%rsp),%rsi
  mov    $0x10,%edx
  mov    %r15d,%edi
  call   <mpz_set_str@plt>
  mov    %r13d,%edx
  mov    %r15d,%esi
  mov    %r15d,%edi
  call   <mpz_mod@plt>
  mov    %r15d,%esi
  mov    %r13d,%edi
  call   <GetJnHash@plt>
  xor    %eax,%eax
  call   <rand@plt>
  mov    0x4(%rsp),%esi
  mov    %r15d,%edi
  cltd
  shr    $0x1e,%edx
  lea    (%rax,%rdx,1),%ebx
  and    $0x3,%ebx
  sub    %edx,%ebx
  call   <mpz_legendre@plt>
  cmp    $0xffffffff,%eax
  jne    L118
L57:
  xor    %r15d,%r15d
  mov    0x3c(%rsp),%esi
  mov    %r15d,%edx
  mov    %r15d,%edi
  call   <mpz_mul@plt>
  mov    %r13d,%edx
  mov    %r15d,%esi
  mov    %r15d,%edi
  call   <mpz_mod@plt>
  jmp    L77
  nopw   0x0(%rax,%rax,1)
L36:
  mov    0x40(%rsp),%rbx
  mov    0x48(%rsp),%rbp
L32:
  mov    (%rbx),%edi
  add    $0x4,%rbx
  call   <mpz_clear@plt>
  cmp    %rbp,%rbx
  jne    L32
  xor    %edi,%edi
  call   <mpz_clear@plt>
L29:
  mov    0x78(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L7
  add    $0x88,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L7:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: data_tag: D5
data_type: string

tool: D5: success

assistant: ```c
void KeyGen(unsigned char *identity, mpz_t *rj, mpz_t n, mpz_t u, mpz_t p, mpz_t q, int l, char **error) {
  int i, w;
  mpz_t uRj, z[4];
  unsigned char *hash, *hex_hash;
  mpz_init(uRj);
  srand(time(NULL));
  for (i = 0; i < 4; i++)
    mpz_init(z[i]);
  for (i = 0; i < l; i++) {
    GetHash(identity, &hash, i, error);
    if (strcmp(*error, "success") != 0)
      return;
    GetHexHash(hash, &hex_hash, error);
    if (strcmp(*error, "success") != 0)
      return;
    mpz_set_str(uRj, hex_hash, 16);
    mpz_mod(uRj, uRj, n);
    GetJnHash(n, uRj);
    w = rand() % 4;
    if (mpz_legendre(uRj, p) == -1 || mpz_legendre(uRj, q) == -1) {
      mpz_mul(uRj, u, uRj);
      mpz_mod(uRj, uRj, n);
    }
    GetSquareRootsModulo(z, uRj, p, q, n, error);
    if (strcmp(*error, "success") != 0)
      return;
    mpz_set(rj[i], z[w]);
    free(hash);
    free(hex_hash);
  }
  for (i = 0; i < 4; i++)
    mpz_clear(z[i]);
  mpz_clear(uRj);
}
```