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

```asm
<BN_generate_prime_ex>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,%r14
  mov    %esi,0x24(%rsp)
  mov    %edx,0x20(%rsp)
  mov    %rcx,0x10(%rsp)
  mov    %r8,0x28(%rsp)
  mov    %r9,%rbp
  mov    %esi,%edi
  call   <BN_prime_checks_for_size@plt>
  mov    %eax,%r13d
  mov    $0x0,%eax
  call   <BN_CTX_new@plt>
  mov    $0x0,%ebx
  test   %rax,%rax
  je     L299
  mov    %rax,%r12
  mov    %rax,%rdi
  call   <BN_CTX_start@plt>
  mov    %r12,%rdi
  call   <BN_CTX_get@plt>
  mov    %rax,0x8(%rsp)
  test   %rax,%rax
  je     L331
  mov    $0x0,%r15d
  mov    %r13d,%ebx
  jmp    L90
L141:
  mov    0x24(%rsp),%esi
  mov    %r14,%rdi
  call   <probable_prime@plt>
  test   %eax,%eax
  je     L40
  lea    0x1(%r15),%eax
  mov    %eax,0x1c(%rsp)
  mov    %r15d,%edx
  mov    $0x0,%esi
  mov    %rbp,%rdi
  call   <BN_GENCB_call@plt>
  test   %eax,%eax
  je     L126
  cmpl   $0x0,0x20(%rsp)
  je     L54
  jmp    L237
L40:
  mov    %eax,%ebx
  jmp    L360
L4:
  mov    %eax,%ebx
  jmp    L360
L358:
  mov    %r12,%r8
  mov    0x28(%rsp),%rcx
  mov    0x10(%rsp),%rdx
  mov    0x24(%rsp),%esi
  mov    %r14,%rdi
  call   <probable_prime_dh@plt>
  test   %eax,%eax
  je     L354
  lea    0x1(%r15),%eax
  mov    %eax,0x1c(%rsp)
  mov    %r15d,%edx
  mov    $0x0,%esi
  mov    %rbp,%rdi
  call   <BN_GENCB_call@plt>
  test   %eax,%eax
  je     L203
L54:
  mov    %rbp,%r8
  mov    $0x0,%ecx
  mov    %r12,%rdx
  mov    %ebx,%esi
  mov    %r14,%rdi
  call   <BN_is_prime_fasttest_ex@plt>
  cmp    $0xffffffff,%eax
  je     L98
  test   %eax,%eax
  jne    L300
L179:
  mov    0x1c(%rsp),%r15d
L90:
  cmpq   $0x0,0x10(%rsp)
  je     L141
  cmpl   $0x0,0x20(%rsp)
  je     L358
  mov    %r12,%r8
  mov    0x28(%rsp),%rcx
  mov    0x10(%rsp),%rdx
  mov    0x24(%rsp),%esi
  mov    %r14,%rdi
  call   <probable_prime_dh_safe@plt>
  test   %eax,%eax
  je     L4
  lea    0x1(%r15),%eax
  mov    %eax,0x1c(%rsp)
  mov    %r15d,%edx
  mov    $0x0,%esi
  mov    %rbp,%rdi
  call   <BN_GENCB_call@plt>
  test   %eax,%eax
  je     L364
L237:
  mov    %r14,%rsi
  mov    0x8(%rsp),%rdi
  call   <BN_rshift1@plt>
  test   %eax,%eax
  je     L65
  test   %ebx,%ebx
  jle    L0
  mov    $0x0,%r13d
L93:
  mov    %rbp,%r8
  mov    $0x0,%ecx
  mov    %r12,%rdx
  mov    $0x1,%esi
  mov    %r14,%rdi
  call   <BN_is_prime_fasttest_ex@plt>
  cmp    $0xffffffff,%eax
  je     L258
  test   %eax,%eax
  je     L179
  mov    %rbp,%r8
  mov    $0x0,%ecx
  mov    %r12,%rdx
  mov    $0x1,%esi
  mov    0x8(%rsp),%rdi
  call   <BN_is_prime_fasttest_ex@plt>
  cmp    $0xffffffff,%eax
  je     L147
  test   %eax,%eax
  je     L179
  mov    %r15d,%edx
  mov    $0x2,%esi
  mov    %rbp,%rdi
  call   <BN_GENCB_call@plt>
  test   %eax,%eax
  je     L316
  add    $0x1,%r13d
  cmp    %r13d,%ebx
  jne    L93
  mov    $0x1,%ebx
  jmp    L360
L354:
  mov    %eax,%ebx
  jmp    L360
L300:
  mov    $0x1,%ebx
  jmp    L360
L331:
  mov    $0x0,%ebx
  jmp    L360
L98:
  mov    $0x0,%ebx
  jmp    L360
L0:
  mov    $0x1,%ebx
  jmp    L360
L258:
  mov    $0x0,%ebx
  jmp    L360
L147:
  mov    $0x0,%ebx
  jmp    L360
L126:
  mov    %eax,%ebx
  jmp    L360
L65:
  mov    %eax,%ebx
  jmp    L360
L316:
  mov    %eax,%ebx
  jmp    L360
L364:
  mov    %eax,%ebx
L360:
  mov    %r12,%rdi
  call   <BN_CTX_end@plt>
  mov    %r12,%rdi
  call   <BN_CTX_free@plt>
L299:
  mov    %r14,%rdi
  call   <bn_check_top@plt>
  mov    %ebx,%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L203:
  mov    %eax,%ebx
  jmp    L360
```

assistant: ```c
int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb) {
  BIGNUM *t;
  int found = 0;
  int i, j, c1 = 0;
  BN_CTX *ctx;
  int checks = BN_prime_checks_for_size(bits);
  ctx = BN_CTX_new();
  if (ctx == NULL)
    goto err;
  BN_CTX_start(ctx);
  t = BN_CTX_get(ctx);
  if (!t)
    goto err;
loop:
  if (add == NULL) {
    if (!probable_prime(ret, bits))
      goto err;
  } else {
    if (safe) {
      if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))
        goto err;
    } else {
      if (!probable_prime_dh(ret, bits, add, rem, ctx))
        goto err;
    }
  }
  if (!BN_GENCB_call(cb, 0, c1++))
    goto err;
  if (!safe) {
    i = BN_is_prime_fasttest_ex(ret, checks, ctx, 0, cb);
    if (i == -1)
      goto err;
    if (i == 0)
      goto loop;
  } else {
    if (!BN_rshift1(t, ret))
      goto err;
    for (i = 0; i < checks; i++) {
      j = BN_is_prime_fasttest_ex(ret, 1, ctx, 0, cb);
      if (j == -1)
        goto err;
      if (j == 0)
        goto loop;
      j = BN_is_prime_fasttest_ex(t, 1, ctx, 0, cb);
      if (j == -1)
        goto err;
      if (j == 0)
        goto loop;
      if (!BN_GENCB_call(cb, 2, c1 - 1))
        goto err;
    }
  }
  found = 1;
err:
  if (ctx != NULL) {
    BN_CTX_end(ctx);
    BN_CTX_free(ctx);
  }
  bn_check_top(ret);
  return found;
}
```