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

```asm
<CheckX509Hostname>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x70,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %rsi,-0x60(%rbp)
  mov    %edx,-0x64(%rbp)
  cmpq   $0x0,-0x58(%rbp)
  jne    L193
  mov    $0xfffffffe,%eax
  jmp    L115
L193:
  cmpl   $0x0,-0x64(%rbp)
  jle    L159
  cmpq   $0x0,-0x60(%rbp)
  jne    L159
  mov    $0xfffffffd,%eax
  jmp    L115
L159:
  cmpl   $0x0,-0x64(%rbp)
  jns    L175
  mov    $0xfffffffc,%eax
  jmp    L115
L175:
  mov    D3(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x34(%rbp)
  mov    D2(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x30(%rbp)
  mov    D4(%rip),%rax
  mov    (%rax),%esi
  mov    -0x58(%rbp),%rax
  mov    $0x0,%ecx
  mov    $0x0,%edx
  mov    %rax,%rdi
  call   <X509_get_ext_d2i@plt>
  mov    %rax,-0x28(%rbp)
  movb   $0x1,-0x41(%rbp)
  movl   $0x0,-0x40(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  je     L67
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <sk_GENERAL_NAME_num@plt>
  mov    %eax,-0x2c(%rbp)
  movl   $0x0,-0x3c(%rbp)
  jmp    L194
L134:
  mov    -0x3c(%rbp),%edx
  mov    -0x28(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <sk_GENERAL_NAME_value@plt>
  mov    %rax,-0x20(%rbp)
  mov    -0x20(%rbp),%rax
  mov    (%rax),%eax
  cmp    %eax,-0x30(%rbp)
  jne    L149
  movb   $0x0,-0x41(%rbp)
  mov    -0x20(%rbp),%rax
  mov    0x8(%rax),%rax
  mov    -0x64(%rbp),%edx
  mov    -0x60(%rbp),%rsi
  mov    $0x1,%ecx
  mov    %rax,%rdi
  call   <CheckX509HostnameMatch@plt>
  test   %rax,%rax
  je     L60
  movl   $0x1,-0x40(%rbp)
  jmp    L89
L149:
  nop
L60:
  addl   $0x1,-0x3c(%rbp)
L194:
  mov    -0x3c(%rbp),%eax
  cmp    -0x2c(%rbp),%eax
  jl     L134
L89:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <GENERAL_NAMES_free@plt>
L67:
  cmpb   $0x0,-0x41(%rbp)
  je     L16
  cmpl   $0x0,-0x40(%rbp)
  jne    L16
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <X509_get_subject_name@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  je     L16
  movl   $0xffffffff,-0x38(%rbp)
  jmp    L48
L165:
  mov    -0x38(%rbp),%edx
  mov    -0x18(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <X509_NAME_get_entry@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <X509_NAME_ENTRY_get_data@plt>
  mov    %rax,-0x8(%rbp)
  mov    -0x64(%rbp),%edx
  mov    -0x60(%rbp),%rsi
  mov    -0x8(%rbp),%rax
  mov    $0x0,%ecx
  mov    %rax,%rdi
  call   <CheckX509HostnameMatch@plt>
  test   %rax,%rax
  je     L48
  movl   $0x1,-0x40(%rbp)
  jmp    L16
L48:
  mov    -0x38(%rbp),%edx
  mov    -0x34(%rbp),%ecx
  mov    -0x18(%rbp),%rax
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <X509_NAME_get_index_by_NID@plt>
  mov    %eax,-0x38(%rbp)
  cmpl   $0x0,-0x38(%rbp)
  jns    L165
L16:
  mov    -0x40(%rbp),%eax
L115:
  leave
  ret
```

assistant: ```c
int32_t CheckX509Hostname(X509 *x509, const char *hostname, int32_t cchHostname) {
  if (!x509)
    return -2;
  if (cchHostname > 0 && !hostname)
    return -3;
  if (cchHostname < 0)
    return -4;
  int subjectNid = NID_commonName;
  int sanGenType = GEN_DNS;
  GENERAL_NAMES *san = X509_get_ext_d2i(x509, NID_subject_alt_name, NULL, NULL);
  char readSubject = 1;
  int success = 0;
  if (san) {
    int i;
    int count = sk_GENERAL_NAME_num(san);
    for (i = 0; i < count; ++i) {
      GENERAL_NAME *sanEntry = sk_GENERAL_NAME_value(san, i);
      if (sanEntry->type != sanGenType) {
        continue;
      }
      readSubject = 0;
      if (CheckX509HostnameMatch(sanEntry->d.dNSName, hostname, cchHostname, 1)) {
        success = 1;
        break;
      }
    }
    GENERAL_NAMES_free(san);
  }
  if (readSubject && !success) {
    X509_NAME *subject = X509_get_subject_name(x509);
    if (subject) {
      int i = -1;
      while ((i = X509_NAME_get_index_by_NID(subject, subjectNid, i)) >= 0) {
        X509_NAME_ENTRY *nameEnt = X509_NAME_get_entry(subject, i);
        ASN1_STRING *cn = X509_NAME_ENTRY_get_data(nameEnt);
        if (CheckX509HostnameMatch(cn, hostname, cchHostname, 0)) {
          success = 1;
          break;
        }
      }
    }
  }
  return success;
}
```