// File: /workspace/github_c_makefile_star2_O1/jfriesse[P]omping/aiifunc.c
// Function: aii_find_local
int
aii_find_local(const struct aii_list *aii_list, int *ip_ver, struct ifaddrs **ifa_list,
    struct ifaddrs **ifa_local, struct ai_item **ai_item, unsigned int if_flags)
{
	struct addrinfo *ai_i;
	struct ai_item *aip;
	struct ifaddrs *ifa, *ifa_i;
	char sa_str[LOGGING_SA_TO_STR_LEN];
	char sa_str2[LOGGING_SA_TO_STR_LEN];
	int ipv4_fallback;
	int res;

	*ifa_local = NULL;
	ifa_i = NULL;
	ipv4_fallback = 0;

	if (getifaddrs(&ifa) == -1) {
		err(1, "getifaddrs");
	}

	TAILQ_FOREACH(aip, aii_list, entries) {
		for (ai_i = aip->ai; ai_i != NULL; ai_i = ai_i->ai_next) {
			if (af_ai_is_dup(aip->ai, ai_i)) {
				logging_sa_to_str(ai_i->ai_addr, sa_str, sizeof(sa_str));
				DEBUG2_PRINTF("Found duplicate addr %s", sa_str);
				continue ;
			}

			for (ifa_i = ifa; ifa_i != NULL; ifa_i = ifa_i->ifa_next) {
				if (ifa_i->ifa_addr == NULL ||
				    (ifa_i->ifa_addr->sa_family != AF_INET &&
				    ifa_i->ifa_addr->sa_family != AF_INET6)) {
					continue ;
				}

				logging_sa_to_str(ifa_i->ifa_addr, sa_str, sizeof(sa_str));
				logging_sa_to_str(ai_i->ai_addr, sa_str2, sizeof(sa_str2));
				DEBUG2_PRINTF("Comparing %s(%s) with %s", sa_str, ifa_i->ifa_name,
				    sa_str2);

				if (af_sockaddr_eq(ifa_i->ifa_addr, ai_i->ai_addr)) {
					res = af_is_supported_local_ifa(ifa_i, *ip_ver, if_flags);

					if (res == 1 || res == 2) {
						if (*ifa_local != NULL && ipv4_fallback == 0)
							goto multiple_match_error;

						*ifa_list = ifa;
						*ifa_local = ifa_i;
						*ai_item = aip;

						if (*ip_ver == 0) {
							/*
							 * Device supports ipv6
							 */
							*ip_ver = 6;
							DEBUG2_PRINTF("Supports ipv6");
						}

						if (res == 2) {
							/*
							 * Set this item as ipv4 fallback
							 */
							ipv4_fallback++;
							DEBUG2_PRINTF("Supports ipv4 - fallback");
						}
					}
				}
			}
		}
	}

	if (*ip_ver == 0 && *ifa_local != NULL) {
		if (ipv4_fallback > 1)
			goto multiple_match_error;

		*ip_ver = 4;
	}

	if (*ifa_local != NULL) {
		return (0);
	}

	DEBUG_PRINTF("Can't find local addr");
	return (-1);

multiple_match_error:
	errx(1, "Multiple local interfaces (%s and %s) match parameters.",
	    ifa_i->ifa_name, (*ifa_local)->ifa_name);
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r9d, 0x24(%rsp)
movq %r8, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movq %rcx, 0x18(%rsp)
movq $0x0, (%rcx)
leaq 0x28(%rsp), %rdi
callq 0x2250
cmpl $-0x1, %eax
je 0x3130
movq (%rbx), %rax
testq %rax, %rax
je 0x30b2
leaq 0x80(%rsp), %r13
leaq 0x40(%rsp), %r15
movl $0x0, 0x14(%rsp)
movq (%rax), %rbx
testq %rbx, %rbx
je 0x30a2
movq %rax, %r14
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x2726
testl %eax, %eax
je 0x2f60
movq 0x18(%rbx), %rdi
movq %r13, %rsi
movl $0x3e, %edx
callq 0x49ab
leaq 0x72da(%rip), %rdi      # 0xa20e
movl $0x81, %esi
movl $0x3, %edx
leaq 0x72d3(%rip), %rcx      # 0xa218
movq %r13, %r8
xorl %eax, %eax
callq 0x4ada
movq 0x28(%rbx), %rbx
testq %rbx, %rbx
movq %r14, %rax
jne 0x2f0a
jmp 0x30a2
movq 0x28(%rsp), %rbp
testq %rbp, %rbp
je 0x2f4f
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
je 0x3099
movzwl (%rdi), %eax
orl $0x8, %eax
cmpl $0xa, %eax
jne 0x3099
movq %r13, %rsi
movl $0x3e, %edx
callq 0x49ab
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movl $0x3e, %edx
callq 0x49ab
movq 0x8(%rbp), %r9
movq %r15, (%rsp)
leaq 0x725b(%rip), %rdi      # 0xa20e
movl $0x8f, %esi
movl $0x3, %edx
leaq 0x726c(%rip), %rcx      # 0xa230
movq %r13, %r8
xorl %eax, %eax
callq 0x4ada
movq 0x18(%rbp), %rdi
movq 0x18(%rbx), %rsi
callq 0x2464
testl %eax, %eax
je 0x3099
movq 0x8(%rsp), %rax
movl (%rax), %esi
movq %rbp, %rdi
movl 0x24(%rsp), %edx
callq 0x2a72
movl %eax, %r12d
leal -0x1(%r12), %eax
cmpl $0x1, %eax
ja 0x3099
movq 0x18(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x301f
cmpl $0x0, 0x14(%rsp)
je 0x3115
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%rsp), %rax
movq %rbp, (%rax)
movq 0x38(%rsp), %rax
movq %r14, (%rax)
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x3070
movq 0x8(%rsp), %rax
movl $0x6, (%rax)
leaq 0x71b6(%rip), %rdi      # 0xa20e
movl $0xa1, %esi
movl $0x3, %edx
leaq 0x71e0(%rip), %rcx      # 0xa249
xorl %eax, %eax
callq 0x4ada
cmpl $0x2, %r12d
jne 0x3099
incl 0x14(%rsp)
leaq 0x718d(%rip), %rdi      # 0xa20e
movl $0xa9, %esi
movl $0x3, %edx
leaq 0x71c5(%rip), %rcx      # 0xa257
xorl %eax, %eax
callq 0x4ada
movq (%rbp), %rbp
jmp 0x2f65
movq 0x88(%rax), %rax
testq %rax, %rax
jne 0x2efe
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x30d2
movq 0x18(%rsp), %rax
cmpq $0x0, (%rax)
je 0x30d2
movq 0x8(%rsp), %rax
movl $0x4, (%rax)
xorl %eax, %eax
movq 0x18(%rsp), %rcx
cmpq $0x0, (%rcx)
jne 0x3103
leaq 0x7128(%rip), %rdi      # 0xa20e
leaq 0x7183(%rip), %rcx      # 0xa270
movl $0xbc, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x4ada
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbp), %rdx
movq 0x8(%rax), %rcx
leaq 0x7162(%rip), %rsi      # 0xa286
movl $0x1, %edi
xorl %eax, %eax
callq 0x20f0
leaq 0x70cc(%rip), %rsi      # 0xa203
movl $0x1, %edi
xorl %eax, %eax
callq 0x2230