// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x55, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x8870
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1f1ec
movb $0x0, -0x1(%rbp)
jmp 0x1f3d7
movb $0x0, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0xe4(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1f3f0
movq %rax, %rdi
callq 0x8990
movl %eax, %ecx
movl -0xe4(%rbp), %eax
cmpl %ecx, %eax
jge 0x1f3a4
movq -0x20(%rbp), %rdi
callq 0x1f3f0
movq %rax, %rdi
movl -0x28(%rbp), %esi
callq 0x8c80
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x7, (%rax)
jne 0x1f34a
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x80c0
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
callq 0x89b0
movq %rax, -0x48(%rbp)
cmpl $0x4, -0x3c(%rbp)
jne 0x1f2b3
movq -0x48(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movl $0x2, %edi
movl $0x10, %ecx
callq 0x80b0
cmpq $0x0, %rax
jne 0x1f293
jmp 0x1f396
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x8610
cmpl $0x0, %eax
jne 0x1f2ae
movb $0x1, -0x21(%rbp)
jmp 0x1f3a4
jmp 0x1f348
cmpl $0x10, -0x3c(%rbp)
jne 0x1f346
movq -0x48(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movl $0xa, %edi
movl $0x2e, %ecx
callq 0x80b0
cmpq $0x0, %rax
jne 0x1f2e2
jmp 0x1f396
movq -0x18(%rbp), %rsi
movl $0xa, %edi
leaq -0xd0(%rbp), %rdx
callq 0x86d0
cmpl $0x1, %eax
je 0x1f301
jmp 0x1f396
leaq -0xc0(%rbp), %rdx
movl $0xa, %edi
leaq -0xd0(%rbp), %rsi
movl $0x2e, %ecx
callq 0x80b0
cmpq $0x0, %rax
jne 0x1f326
jmp 0x1f396
leaq -0xc0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x8610
cmpl $0x0, %eax
jne 0x1f344
movb $0x1, -0x21(%rbp)
jmp 0x1f3a4
jmp 0x1f346
jmp 0x1f348
jmp 0x1f394
movq -0x30(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x1f392
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x89b0
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x8610
cmpl $0x0, %eax
jne 0x1f390
movb $0x1, -0x21(%rbp)
jmp 0x1f3a4
jmp 0x1f392
jmp 0x1f394
jmp 0x1f396
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1f1f7
movq -0x20(%rbp), %rdi
callq 0x1f400
movq %rax, -0xf0(%rbp)
movq 0x10bf5(%rip), %rdi     # 0x2ffb0
callq 0x1f410
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x88f0
movb -0x21(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop