// File: /workspace/github_c_makefile_star2_O1/jfriesse[P]omping/aiifunc.c
// Function: aii_return_ip_ver
int
aii_return_ip_ver(struct aii_list *aii_list, int ip_ver, const char *mcast_addr, const char *port)
{
	struct addrinfo *ai_res;
	struct ai_item *aip;
	int mcast_ipver;
	int ipver_res, ipver_res2;

	if (ip_ver != 0) {
		DEBUG_PRINTF("user forced forced ip_ver is %d, using that", ip_ver);
		return (ip_ver);
	}

	if (mcast_addr != NULL) {
		ai_res = af_host_to_ai(mcast_addr, port, ip_ver);
		mcast_ipver = af_ai_deep_supported_ipv(ai_res);

		DEBUG2_PRINTF("mcast_ipver for %s is %d", mcast_addr, mcast_ipver);

		freeaddrinfo(ai_res);

		if (mcast_ipver == -1) {
			errx(1, "Mcast address %s doesn't support ipv4 or ipv6", mcast_addr);
		}

		if (mcast_ipver != 0) {
			DEBUG_PRINTF("mcast address for %s supports only ipv%d, using that",
			    mcast_addr, mcast_ipver);

			/*
			 * Walk thru all addresses to find out, what it supports
			 */
			TAILQ_FOREACH(aip, aii_list, entries) {
				ipver_res = af_ai_deep_supported_ipv(aip->ai);
				DEBUG2_PRINTF("ipver for %s is %d", aip->host_name, ipver_res);

				if (ipver_res == -1) {
					errx(1, "Host %s doesn't support ipv4 or ipv6",
					    aip->host_name);
				}

				if (ipver_res != 0 && ipver_res != mcast_ipver) {
					errx(1, "Multicast address is ipv%d but host %s supports"
					    " only ipv%d", mcast_ipver, aip->host_name, ipver_res);
				}
			}

			return (mcast_ipver);
		}
	}

	ipver_res = 0;

	/*
	 * Walk thru all addresses to find out, what it supports
	 */
	TAILQ_FOREACH(aip, aii_list, entries) {
		ipver_res = af_ai_deep_supported_ipv(aip->ai);
		DEBUG2_PRINTF("ipver for %s is %d", aip->host_name, ipver_res);

		if (ipver_res == -1) {
			errx(1, "Host %s doesn't support ipv4 or ipv6", aip->host_name);
		}

		if (ipver_res != 0) {
			break;
		}
	}

	if (ipver_res == 0) {
		/*
		 * Every address support every version
		 */
		DEBUG_PRINTF("Every address support all IP versions");
		return (0);
	}

	if (ipver_res != 0) {
		/*
		 * Host supports only one version.
		 * Test availability for that version on all hosts
		 */
		TAILQ_FOREACH(aip, aii_list, entries) {
			ipver_res2 = af_ai_deep_supported_ipv(aip->ai);
			DEBUG2_PRINTF("ipver for %s is %d", aip->host_name, ipver_res2);

			if (ipver_res2 == -1) {
				errx(1, "Host %s doesn't support ipv4 or ipv6", aip->host_name);
			}

			if (ipver_res2 != 0 && ipver_res2 != ipver_res) {
				/*
				 * Host doesn't support ip version of other members
				 */
				errx(1, "Host %s doesn't support IP version %d", aip->host_name,
				    ipver_res);
			}
		}
	}

	DEBUG_PRINTF("Every address support ipv%d", ipver_res);

	return (ipver_res);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testl %esi, %esi
je 0x36cd
movl %esi, %ebx
leaq 0x6b52(%rip), %rdi      # 0xa20e
leaq 0x6d30(%rip), %rcx      # 0xa3f3
movl $0x1c1, %esi            # imm = 0x1C1
jmp 0x38a2
movq %rdx, %r15
movq %rdi, %r14
testq %rdx, %rdx
je 0x37c7
movq %r15, %rdi
movq %rcx, %rsi
xorl %edx, %edx
callq 0x2928
movq %rax, %r12
movq %rax, %rdi
callq 0x2654
movl %eax, %ebx
leaq 0x6b11(%rip), %rdi      # 0xa20e
leaq 0x6d1b(%rip), %rcx      # 0xa41f
movl $0x1c9, %esi            # imm = 0x1C9
movl $0x3, %edx
movq %r15, %r8
movl %eax, %r9d
xorl %eax, %eax
callq 0x4ada
movq %r12, %rdi
callq 0x2320
testl %ebx, %ebx
je 0x37c7
cmpl $-0x1, %ebx
je 0x3946
leaq 0x6ad3(%rip), %rdi      # 0xa20e
leaq 0x6d24(%rip), %rcx      # 0xa466
movl $0x1d3, %esi            # imm = 0x1D3
movl $0x2, %edx
movq %r15, %r8
movl %ebx, %r9d
xorl %eax, %eax
callq 0x4ada
movq (%r14), %r12
testq %r12, %r12
je 0x38b1
leaq 0x6aa2(%rip), %r14      # 0xa20e
leaq 0x6cb2(%rip), %r15      # 0xa425
movq (%r12), %rdi
callq 0x2654
movl %eax, %ebp
movq 0x80(%r12), %r8
movq %r14, %rdi
movl $0x1da, %esi            # imm = 0x1DA
movl $0x3, %edx
movq %r15, %rcx
movl %eax, %r9d
xorl %eax, %eax
callq 0x4ada
testl %ebp, %ebp
je 0x37b5
cmpl $-0x1, %ebp
je 0x38e5
cmpl %ebx, %ebp
jne 0x3926
movq 0x88(%r12), %r12
testq %r12, %r12
jne 0x3773
jmp 0x38b1
movq (%r14), %r13
testq %r13, %r13
je 0x3819
leaq 0x6a38(%rip), %r15      # 0xa20e
leaq 0x6c48(%rip), %r12      # 0xa425
movq (%r13), %rdi
callq 0x2654
movl %eax, %ebx
movq 0x80(%r13), %r8
movq %r15, %rdi
movl $0x1f2, %esi            # imm = 0x1F2
movl $0x3, %edx
movq %r12, %rcx
movl %eax, %r9d
xorl %eax, %eax
callq 0x4ada
testl %ebx, %ebx
jne 0x381d
movq 0x88(%r13), %r13
testq %r13, %r13
jne 0x37dd
xorl %ebx, %ebx
jmp 0x3826
cmpl $-0x1, %ebx
je 0x38ef
testl %ebx, %ebx
je 0x38c2
movq (%r14), %r12
testq %r12, %r12
je 0x388f
leaq 0x69d1(%rip), %r14      # 0xa20e
leaq 0x6be1(%rip), %r15      # 0xa425
movq (%r12), %rdi
callq 0x2654
movl %eax, %ebp
movq 0x80(%r12), %r8
movq %r14, %rdi
movl $0x20c, %esi            # imm = 0x20C
movl $0x3, %edx
movq %r15, %rcx
movl %eax, %r9d
xorl %eax, %eax
callq 0x4ada
testl %ebp, %ebp
je 0x3882
cmpl $-0x1, %ebp
je 0x38e5
cmpl %ebx, %ebp
jne 0x3909
movq 0x88(%r12), %r12
testq %r12, %r12
jne 0x3844
leaq 0x6978(%rip), %rdi      # 0xa20e
leaq 0x6caa(%rip), %rcx      # 0xa547
movl $0x21c, %esi            # imm = 0x21C
movl $0x2, %edx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x4ada
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6945(%rip), %rdi      # 0xa20e
leaq 0x6c2b(%rip), %rcx      # 0xa4fb
xorl %ebx, %ebx
movl $0x201, %esi            # imm = 0x201
movl $0x2, %edx
xorl %eax, %eax
callq 0x4ada
jmp 0x38b1
movq 0x80(%r12), %rdx
jmp 0x38f6
movq 0x80(%r13), %rdx
leaq 0x6b9e(%rip), %rsi      # 0xa49b
movl $0x1, %edi
xorl %eax, %eax
callq 0x20f0
movq 0x80(%r12), %rdx
leaq 0x6c09(%rip), %rsi      # 0xa521
movl $0x1, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
movq 0x80(%r12), %rcx
leaq 0x6b8b(%rip), %rsi      # 0xa4c0
movl $0x1, %edi
movl %ebx, %edx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x20f0
leaq 0x6aeb(%rip), %rsi      # 0xa438
movl $0x1, %edi
movq %r15, %rdx
jmp 0x3902
nop