// File: /workspace/github_c_makefile_star2_O2/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 0x35e8
movl %esi, %ebx
leaq 0x5c50(%rip), %rdi      # 0x920e
leaq 0x5e2e(%rip), %rcx      # 0x93f3
pushq $0x2
popq %rdx
movl $0x1c1, %esi            # imm = 0x1C1
movl %ebx, %r8d
xorl %eax, %eax
callq 0x4998
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
movq %rdi, %r12
testq %rdx, %rdx
je 0x3717
movq %r15, %rdi
movq %rcx, %rsi
xorl %edx, %edx
callq 0x28d2
movq %rax, %r12
movq %rax, %rdi
callq 0x263f
movl %eax, %ebx
leaq 0x5bf3(%rip), %rdi      # 0x920e
leaq 0x5dfd(%rip), %rcx      # 0x941f
pushq $0x3
popq %rdx
movl $0x1c9, %esi            # imm = 0x1C9
movq %r15, %r8
movl %eax, %r9d
xorl %eax, %eax
callq 0x4998
movq %r12, %rdi
callq 0x2330
movq %r14, %r12
testl %ebx, %ebx
je 0x3717
cmpl $-0x1, %ebx
je 0x3818
leaq 0x5bb4(%rip), %r12      # 0x920e
leaq 0x5e05(%rip), %rcx      # 0x9466
pushq $0x2
popq %rdx
movq %r12, %rdi
movl $0x1d3, %esi            # imm = 0x1D3
movq %r15, %r8
movl %ebx, %r9d
xorl %eax, %eax
callq 0x4998
leaq 0x5da5(%rip), %r15      # 0x9425
pushq $0x3
popq %rbp
movq (%r14), %r14
testq %r14, %r14
je 0x35d7
movq (%r14), %rdi
callq 0x263f
movl %eax, %r13d
movq 0x80(%r14), %r8
movq %r12, %rdi
movl $0x1da, %esi            # imm = 0x1DA
movl %ebp, %edx
movq %r15, %rcx
movl %eax, %r9d
xorl %eax, %eax
callq 0x4998
testl %r13d, %r13d
je 0x36d0
cmpl $-0x1, %r13d
je 0x37c9
cmpl %ebx, %r13d
jne 0x37fb
addq $0x88, %r14
jmp 0x3683
movq (%r12), %rdi
callq 0x263f
movl %eax, %ebx
movq 0x80(%r12), %r8
leaq 0x5b1b(%rip), %rdi      # 0x920e
leaq 0x5d2b(%rip), %rcx      # 0x9425
pushq $0x3
popq %rdx
movl $0x1f2, %esi            # imm = 0x1F2
movl %eax, %r9d
xorl %eax, %eax
callq 0x4998
testl %ebx, %ebx
jne 0x3744
addq $0x88, %r12
movq (%r12), %r12
testq %r12, %r12
jne 0x36d9
leaq 0x5ae7(%rip), %rdi      # 0x920e
leaq 0x5dcd(%rip), %rcx      # 0x94fb
xorl %ebx, %ebx
pushq $0x2
popq %rdx
movl $0x201, %esi            # imm = 0x201
xorl %eax, %eax
callq 0x4998
jmp 0x35d7
cmpl $-0x1, %ebx
je 0x37bf
leaq 0x5abe(%rip), %r15      # 0x920e
leaq 0x5cce(%rip), %r12      # 0x9425
pushq $0x3
popq %rbp
movq (%r14), %r14
testq %r14, %r14
je 0x37a4
movq (%r14), %rdi
callq 0x263f
movl %eax, %r13d
movq 0x80(%r14), %r8
movq %r15, %rdi
movl $0x20c, %esi            # imm = 0x20C
movl %ebp, %edx
movq %r12, %rcx
movl %eax, %r9d
xorl %eax, %eax
callq 0x4998
testl %r13d, %r13d
je 0x379b
cmpl $-0x1, %r13d
je 0x37c9
cmpl %ebx, %r13d
jne 0x37e1
addq $0x88, %r14
jmp 0x375a
leaq 0x5a63(%rip), %rdi      # 0x920e
leaq 0x5d95(%rip), %rcx      # 0x9547
pushq $0x2
popq %rdx
movl $0x21c, %esi            # imm = 0x21C
jmp 0x35cd
movq 0x80(%r12), %rdx
jmp 0x37d0
movq 0x80(%r14), %rdx
leaq 0x5cc4(%rip), %rsi      # 0x949b
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x20f0
movq 0x80(%r14), %rdx
leaq 0x5d32(%rip), %rsi      # 0x9521
pushq $0x1
popq %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
movq 0x80(%r14), %rcx
leaq 0x5cb7(%rip), %rsi      # 0x94c0
pushq $0x1
popq %rdi
movl %ebx, %edx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x20f0
leaq 0x5c19(%rip), %rsi      # 0x9438
pushq $0x1
popq %rdi
movq %r15, %rdx
jmp 0x37da
nop