user: 请将以下的汇编代码转换成C语言代码：

```asm
<CheckX509Hostname>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,0x8(%rsp)
  test   %rdi,%rdi
  je     L96
  mov    %rsi,%r13
  mov    %edx,%ebx
  test   %edx,%edx
  jle    L113
  test   %rsi,%rsi
  je     L115
L113:
  test   %ebx,%ebx
  js     L57
  mov    D15(%rip),%rax
  mov    0x8(%rsp),%rdi
  xor    %ecx,%ecx
  xor    %edx,%edx
  mov    (%rax),%eax
  mov    %eax,0x4(%rsp)
  mov    D21(%rip),%rax
  mov    (%rax),%r14d
  mov    D2(%rip),%rax
  mov    (%rax),%esi
  call   <X509_get_ext_d2i@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L62
  mov    %rax,%rdi
  call   <sk_GENERAL_NAME_num@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  jle    L180
  movb   $0x1,0x3(%rsp)
  xor    %r15d,%r15d
  jmp    L50
  nopl   (%rax)
L15:
  add    $0x1,%r15d
  cmp    %r15d,%r12d
  je     L67
L50:
  mov    %r15d,%esi
  mov    %rbp,%rdi
  call   <sk_GENERAL_NAME_value@plt>
  cmp    %r14d,(%rax)
  jne    L15
  mov    0x8(%rax),%rdi
  mov    $0x1,%ecx
  mov    %ebx,%edx
  mov    %r13,%rsi
  call   <CheckX509HostnameMatch@plt>
  test   %rax,%rax
  jne    L83
  add    $0x1,%r15d
  movb   $0x0,0x3(%rsp)
  cmp    %r15d,%r12d
  jne    L50
L67:
  mov    %rbp,%rdi
  call   <GENERAL_NAMES_free@plt>
  cmpb   $0x0,0x3(%rsp)
  jne    L62
L3:
  xor    %eax,%eax
L51:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L180:
  mov    %rbp,%rdi
  call   <GENERAL_NAMES_free@plt>
  nopl   0x0(%rax,%rax,1)
L62:
  mov    0x8(%rsp),%rdi
  mov    $0xffffffff,%r12d
  call   <X509_get_subject_name@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  jne    L12
  jmp    L3
  nopw   0x0(%rax,%rax,1)
L19:
  mov    %r12d,%esi
  mov    %rbp,%rdi
  call   <X509_NAME_get_entry@plt>
  mov    %rax,%rdi
  call   <X509_NAME_ENTRY_get_data@plt>
  xor    %ecx,%ecx
  mov    %ebx,%edx
  mov    %r13,%rsi
  mov    %rax,%rdi
  call   <CheckX509HostnameMatch@plt>
  test   %rax,%rax
  jne    L124
L12:
  mov    0x4(%rsp),%esi
  mov    %r12d,%edx
  mov    %rbp,%rdi
  call   <X509_NAME_get_index_by_NID@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  jns    L19
  jmp    L3
  nop
L83:
  mov    %rbp,%rdi
  call   <GENERAL_NAMES_free@plt>
L124:
  add    $0x18,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L115:
  mov    $0xfffffffd,%eax
  jmp    L51
L57:
  mov    $0xfffffffc,%eax
  jmp    L51
L96:
  mov    $0xfffffffe,%eax
  jmp    L51
```

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;
}
```