user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<BN_to_ASN1_INTEGER>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  jne    L99
  mov    $0x0,%eax
  call   <ASN1_INTEGER_new@plt>
  mov    %rax,-0x10(%rbp)
  jmp    L149
L99:
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x10(%rbp)
L149:
  cmpq   $0x0,-0x10(%rbp)
  jne    L134
  mov    D20(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,%edi
  call   <ASN1error@plt>
  jmp    L1
L134:
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <ASN1_INTEGER_valid@plt>
  test   %eax,%eax
  je     L9
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <BN_is_negative@plt>
  test   %rax,%rax
  je     L142
  mov    D12(%rip),%rax
  mov    (%rax),%edx
  mov    -0x10(%rbp),%rax
  mov    %edx,0x10(%rax)
  jmp    L96
L142:
  mov    D31(%rip),%rax
  mov    (%rax),%edx
  mov    -0x10(%rbp),%rax
  mov    %edx,0x10(%rax)
L96:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <BN_num_bits@plt>
  mov    %eax,-0x18(%rbp)
  cmpl   $0x0,-0x18(%rbp)
  je     L78
  mov    -0x18(%rbp),%eax
  lea    0x7(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0x3,%eax
  add    $0x1,%eax
  jmp    L35
L78:
  mov    $0x0,%eax
L35:
  mov    %eax,-0x14(%rbp)
  mov    -0x14(%rbp),%eax
  lea    0x3(%rax),%edx
  mov    -0x10(%rbp),%rax
  mov    (%rax),%eax
  cmp    %eax,%edx
  jl     L33
  mov    -0x14(%rbp),%eax
  lea    0x4(%rax),%edx
  mov    -0x10(%rbp),%rax
  mov    0x8(%rax),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x8(%rbp)
  cmpq   $0x0,-0x8(%rbp)
  jne    L23
  mov    D22(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,%edi
  call   <ASN1error@plt>
  jmp    L1
L23:
  mov    -0x10(%rbp),%rax
  mov    -0x8(%rbp),%rdx
  mov    %rdx,0x8(%rax)
L33:
  mov    -0x10(%rbp),%rax
  mov    0x8(%rax),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <BN_bn2bin@plt>
  mov    -0x10(%rbp),%rdx
  mov    %eax,(%rdx)
  mov    -0x10(%rbp),%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jne    L69
  mov    -0x10(%rbp),%rax
  mov    0x8(%rax),%rax
  movb   $0x0,(%rax)
  mov    -0x10(%rbp),%rax
  movl   $0x1,(%rax)
L69:
  mov    -0x10(%rbp),%rax
  jmp    L116
L9:
  nop
L1:
  mov    -0x10(%rbp),%rax
  cmp    -0x30(%rbp),%rax
  je     L22
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <ASN1_INTEGER_free@plt>
L22:
  mov    $0x0,%eax
L116:
  leave
  ret
```

assistant: ```c
ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) {
  ASN1_INTEGER *ret;
  int len, j;
  if (ai == NULL)
    ret = ASN1_INTEGER_new();
  else
    ret = ai;
  if (ret == NULL) {
    ASN1error(ERR_R_NESTED_ASN1_ERROR);
    goto err;
  }
  if (!ASN1_INTEGER_valid(ret))
    goto err;
  if (BN_is_negative(bn))
    ret->type = V_ASN1_NEG_INTEGER;
  else
    ret->type = V_ASN1_INTEGER;
  j = BN_num_bits(bn);
  len = ((j == 0) ? 0 : ((j / 8) + 1));
  if (ret->length < len + 4) {
    unsigned char *new_data = realloc(ret->data, len + 4);
    if (!new_data) {
      ASN1error(ERR_R_MALLOC_FAILURE);
      goto err;
    }
    ret->data = new_data;
  }
  ret->length = BN_bn2bin(bn, ret->data);
  if (!ret->length) {
    ret->data[0] = 0;
    ret->length = 1;
  }
  return (ret);
err:
  if (ret != ai)
    ASN1_INTEGER_free(ret);
  return (NULL);
}
```