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     L3
  mov    %rsi,%r13
  mov    %edx,%ebx
  test   %edx,%edx
  jle    L183
  test   %rsi,%rsi
  je     L87
L183:
  test   %ebx,%ebx
  js     L149
  mov    D12(%rip),%rax
  mov    0x8(%rsp),%rdi
  xor    %ecx,%ecx
  xor    %edx,%edx
  mov    (%rax),%eax
  mov    %eax,0x4(%rsp)
  mov    D26(%rip),%rax
  mov    (%rax),%r14d
  mov    D8(%rip),%rax
  mov    (%rax),%esi
  call   <X509_get_ext_d2i@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L23
  mov    %rax,%rdi
  call   <sk_GENERAL_NAME_num@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  jle    L52
  movb   $0x1,0x3(%rsp)
  xor    %r15d,%r15d
  jmp    L99
  nopl   (%rax)
L159:
  add    $0x1,%r15d
  cmp    %r15d,%r12d
  je     L82
L99:
  mov    %r15d,%esi
  mov    %rbp,%rdi
  call   <sk_GENERAL_NAME_value@plt>
  cmp    %r14d,(%rax)
  jne    L159
  mov    0x8(%rax),%rdi
  mov    $0x1,%ecx
  mov    %ebx,%edx
  mov    %r13,%rsi
  call   <CheckX509HostnameMatch@plt>
  test   %rax,%rax
  jne    L66
  add    $0x1,%r15d
  movb   $0x0,0x3(%rsp)
  cmp    %r15d,%r12d
  jne    L99
L82:
  mov    %rbp,%rdi
  call   <GENERAL_NAMES_free@plt>
  cmpb   $0x0,0x3(%rsp)
  jne    L23
L134:
  xor    %eax,%eax
L162:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L52:
  mov    %rbp,%rdi
  call   <GENERAL_NAMES_free@plt>
  nopl   0x0(%rax,%rax,1)
L23:
  mov    0x8(%rsp),%rdi
  mov    $0xffffffff,%r12d
  call   <X509_get_subject_name@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  jne    L194
  jmp    L134
  nopw   0x0(%rax,%rax,1)
L151:
  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    L188
L194:
  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    L151
  jmp    L134
  nop
L66:
  mov    %rbp,%rdi
  call   <GENERAL_NAMES_free@plt>
L188:
  add    $0x18,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L87:
  mov    $0xfffffffd,%eax
  jmp    L162
L149:
  mov    $0xfffffffc,%eax
  jmp    L162
L3:
  mov    $0xfffffffe,%eax
  jmp    L162
```

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