// File: /workspace/github_c_makefile_star2_O3/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 0x36cc
movl %esi, %ebx
leaq 0x6b6e(%rip), %rdi      # 0xa20e
leaq 0x6d4c(%rip), %rcx      # 0xa3f3
movl $0x1c1, %esi            # imm = 0x1C1
movl $0x2, %edx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x4ad6
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
movq %rdi, %r14
testq %rdx, %rdx
je 0x37c6
movq %r15, %rdi
movq %rcx, %rsi
xorl %edx, %edx
callq 0x292d
movq %rax, %r12
movq %rax, %rdi
callq 0x2664
movl %eax, %ebx
leaq 0x6b12(%rip), %rdi      # 0xa20e
leaq 0x6d1c(%rip), %rcx      # 0xa41f
movl $0x1c9, %esi            # imm = 0x1C9
movl $0x3, %edx
movq %r15, %r8
movl %eax, %r9d
xorl %eax, %eax
callq 0x4ad6
movq %r12, %rdi
callq 0x2330
testl %ebx, %ebx
je 0x37c6
cmpl $-0x1, %ebx
je 0x3919
leaq 0x6ad4(%rip), %rdi      # 0xa20e
leaq 0x6d25(%rip), %rcx      # 0xa466
movl $0x1d3, %esi            # imm = 0x1D3
movl $0x2, %edx
movq %r15, %r8
movl %ebx, %r9d
xorl %eax, %eax
callq 0x4ad6
movq (%r14), %r12
testq %r12, %r12
je 0x36bb
leaq 0x6aa3(%rip), %r14      # 0xa20e
leaq 0x6cb3(%rip), %r15      # 0xa425
movq (%r12), %rdi
callq 0x2664
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 0x4ad6
testl %ebp, %ebp
je 0x37b4
cmpl $-0x1, %ebp
je 0x38c1
cmpl %ebx, %ebp
jne 0x38dc
movq 0x88(%r12), %r12
testq %r12, %r12
jne 0x3772
jmp 0x36bb
movq (%r14), %r13
testq %r13, %r13
je 0x3818
leaq 0x6a39(%rip), %r15      # 0xa20e
leaq 0x6c49(%rip), %r12      # 0xa425
movq (%r13), %rdi
callq 0x2664
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 0x4ad6
testl %ebx, %ebx
jne 0x383e
movq 0x88(%r13), %r13
testq %r13, %r13
jne 0x37dc
leaq 0x69ef(%rip), %rdi      # 0xa20e
leaq 0x6cd5(%rip), %rcx      # 0xa4fb
xorl %ebx, %ebx
movl $0x201, %esi            # imm = 0x201
movl $0x2, %edx
xorl %eax, %eax
callq 0x4ad6
jmp 0x36bb
cmpl $-0x1, %ebx
je 0x38b8
movq (%r14), %r12
testq %r12, %r12
je 0x38a0
leaq 0x69bc(%rip), %r14      # 0xa20e
leaq 0x6bcc(%rip), %r15      # 0xa425
movq (%r12), %rdi
callq 0x2664
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 0x4ad6
testl %ebp, %ebp
je 0x3893
cmpl $-0x1, %ebp
je 0x38c1
cmpl %ebx, %ebp
jne 0x38fc
movq 0x88(%r12), %r12
testq %r12, %r12
jne 0x3859
leaq 0x6967(%rip), %rdi      # 0xa20e
leaq 0x6c99(%rip), %rcx      # 0xa547
movl $0x21c, %esi            # imm = 0x21C
jmp 0x36ac
movq 0x80(%r13), %rdx
jmp 0x38c9
movq 0x80(%r12), %rdx
leaq 0x6bcb(%rip), %rsi      # 0xa49b
movl $0x1, %edi
xorl %eax, %eax
callq 0x20f0
movq 0x80(%r12), %rcx
leaq 0x6bd5(%rip), %rsi      # 0xa4c0
movl $0x1, %edi
movl %ebx, %edx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x20f0
movq 0x80(%r12), %rdx
leaq 0x6c16(%rip), %rsi      # 0xa521
movl $0x1, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
leaq 0x6b18(%rip), %rsi      # 0xa438
movl $0x1, %edi
movq %r15, %rdx
jmp 0x38d5
nop