// File: /workspace/github_c_makefile_star2_O1/aerospike[P]aerospike-common/src/main/aerospike/ssl_util.c
// Function: as_tls_match_san
bool as_tls_match_san(X509 *x509, const char *name) {
	STACK_OF(GENERAL_NAME) *san_names = X509_get_ext_d2i(x509,
			NID_subject_alt_name, NULL, NULL);

	if (san_names == NULL) {
		return false;
	}

	bool match = false;

	for (int j = 0; j < sk_GENERAL_NAME_num(san_names); j++) {
		GENERAL_NAME *san_ele = sk_GENERAL_NAME_value(san_names, j);

		if (san_ele->type == GEN_IPADD) {
			ASN1_OCTET_STRING *ip_str = san_ele->d.iPAddress;
			int ip_length = ASN1_STRING_length(ip_str);

#if OPENSSL_VERSION_NUMBER < 0x10100000
			const unsigned char *ip = ASN1_STRING_data(ip_str);
#else
			const unsigned char *ip = ASN1_STRING_get0_data(ip_str);
#endif

			if (ip_length == 4) {
				// IPv4 address.
				char san[INET_ADDRSTRLEN];

				if (inet_ntop(AF_INET, ip, san, INET_ADDRSTRLEN) == NULL) {
					continue;
				}

				if (strcmp(name, san) == 0) {
					match = true;
					break;
				}
			}
			else if (ip_length == 16) {
				// IPv6 address.
				char san[INET6_ADDRSTRLEN];
				char name_short[INET6_ADDRSTRLEN];
				struct in6_addr name_in6;

				if (inet_ntop(AF_INET6, ip, san, INET6_ADDRSTRLEN) == NULL) {
					continue;
				}

				// Convert peer name to short form and compare.

				if (inet_pton(AF_INET6, name, &name_in6) != 1) {
					continue;
				}

				if (inet_ntop(AF_INET6, &name_in6, name_short,
						INET6_ADDRSTRLEN) == NULL) {
					continue;
				}

				if (strcmp(name_short, san) == 0) {
					match = true;
					break;
				}
			}
		}
		else if (san_ele->type == GEN_DNS) {
			ASN1_STRING *dns_name = san_ele->d.dNSName;

#if OPENSSL_VERSION_NUMBER < 0x10100000
			char *san = (char*)ASN1_STRING_data(dns_name);
#else
			char *san = (char*)ASN1_STRING_get0_data(dns_name);
#endif

			if (strcmp(name, san) == 0) {
				match = true;
				break;
			}
		}
	}

	sk_GENERAL_NAME_pop_free(san_names, GENERAL_NAME_free);

	return match;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, 0x8(%rsp)
xorl %r15d, %r15d
movl $0x55, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8760
testq %rax, %rax
je 0x13cbd
movq %rax, %rbx
movq %rax, %rdi
callq 0x8860
xorl %ebp, %ebp
testl %eax, %eax
jle 0x13cab
leaq 0x50(%rsp), %r13
xorl %r15d, %r15d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8af0
movl (%rax), %ecx
cmpl $0x2, %ecx
je 0x13bb2
cmpl $0x7, %ecx
jne 0x13c8e
movq %r13, %r14
movq 0x8(%rax), %r12
movq %r12, %rdi
callq 0x80b0
movl %eax, %r13d
movq %r12, %rdi
callq 0x8880
cmpl $0x10, %r13d
je 0x13bee
cmpl $0x4, %r13d
jne 0x13c75
movl $0x2, %edi
movq %rax, %rsi
movq %r14, %r13
movq %r14, %rdx
movl $0x10, %ecx
callq 0x80a0
testq %rax, %rax
je 0x13c7a
movq 0x8(%rsp), %rdi
jmp 0x13c4f
movq 0x8(%rax), %rdi
callq 0x8880
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x8560
xorl %r12d, %r12d
testl %eax, %eax
sete %al
movzbl %r15b, %r15d
movl $0x1, %ecx
cmovel %ecx, %r15d
jne 0x13c8e
movb %al, %r12b
addl %r12d, %r12d
jmp 0x13c91
movl $0xa, %edi
movq %rax, %rsi
movq %r14, %r13
movq %r14, %rdx
movl $0x2e, %ecx
callq 0x80a0
movl $0x4, %r12d
testq %rax, %rax
je 0x13c80
movl $0xa, %edi
movq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdx
callq 0x85d0
cmpl $0x1, %eax
jne 0x13c80
movl $0xa, %edi
movq %r14, %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdx
movl $0x2e, %ecx
callq 0x80a0
testq %rax, %rax
je 0x13c80
movq %r14, %rdi
movq %r13, %rsi
callq 0x8560
xorl %r12d, %r12d
testl %eax, %eax
sete %r12b
setne %al
movzbl %r15b, %r15d
movl $0x1, %ecx
cmovel %ecx, %r15d
addl %r12d, %r12d
jmp 0x13c82
movq %r14, %r13
jmp 0x13c86
movl $0x4, %r12d
xorl %eax, %eax
testb %al, %al
je 0x13c89
xorl %r12d, %r12d
testl %r12d, %r12d
jne 0x13c91
xorl %r12d, %r12d
testb $0x3, %r12b
jne 0x13cae
incl %ebp
movq %rbx, %rdi
callq 0x8860
cmpl %eax, %ebp
jl 0x13b43
jmp 0x13cae
xorl %r15d, %r15d
movq 0xc2f3(%rip), %rsi      # 0x1ffa8
movq %rbx, %rdi
callq 0x87d0
andb $0x1, %r15b
movl %r15d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq