// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %rdi, %r14
movq %rcx, 0x18(%rsp)
movq $0x0, (%rcx)
leaq 0x28(%rsp), %rdi
callq 0x2260
cmpl $-0x1, %eax
je 0x3128
movq (%r14), %rax
testq %rax, %rax
je 0x30ae
leaq 0x80(%rsp), %r13
movl $0x0, 0x14(%rsp)
movq (%rax), %rbp
testq %rbp, %rbp
je 0x309e
movq %rax, %rbx
movq (%rax), %rdi
movq %rbp, %rsi
callq 0x272c
testl %eax, %eax
je 0x2f5d
movq 0x18(%rbp), %rdi
movq %r13, %rsi
movl $0x3e, %edx
callq 0x49a7
leaq 0x72dd(%rip), %rdi      # 0xa20e
movl $0x81, %esi
movl $0x3, %edx
leaq 0x72d6(%rip), %rcx      # 0xa218
movq %r13, %r8
xorl %eax, %eax
callq 0x4ad6
movq 0x28(%rbp), %rbp
testq %rbp, %rbp
movq %rbx, %rax
jne 0x2f07
jmp 0x309e
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0x2f4c
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x3096
movzwl (%rdi), %eax
orl $0x8, %eax
cmpl $0xa, %eax
jne 0x3096
movq %r13, %rsi
movl $0x3e, %edx
callq 0x49a7
movq 0x18(%rbp), %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
movl $0x3e, %edx
callq 0x49a7
movq 0x8(%r14), %r9
movq %r15, (%rsp)
leaq 0x7259(%rip), %rdi      # 0xa20e
movl $0x8f, %esi
movl $0x3, %edx
leaq 0x726a(%rip), %rcx      # 0xa230
movq %r13, %r8
xorl %eax, %eax
callq 0x4ad6
movq 0x18(%r14), %rdi
movq 0x18(%rbp), %rsi
callq 0x2474
testl %eax, %eax
je 0x3096
movq %r12, %r15
movl (%r12), %esi
movq %r14, %rdi
movl 0x24(%rsp), %edx
callq 0x2a76
movl %eax, %r12d
leal -0x1(%r12), %eax
cmpl $0x1, %eax
ja 0x3093
movq 0x18(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x3021
cmpl $0x0, 0x14(%rsp)
je 0x310d
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%rsp), %rax
movq %r14, (%rax)
movq 0x38(%rsp), %rax
movq %rbx, (%rax)
cmpl $0x0, (%r15)
jne 0x306a
movl $0x6, (%r15)
leaq 0x71bc(%rip), %rdi      # 0xa20e
movl $0xa1, %esi
movl $0x3, %edx
leaq 0x71e6(%rip), %rcx      # 0xa249
xorl %eax, %eax
callq 0x4ad6
cmpl $0x2, %r12d
jne 0x3093
incl 0x14(%rsp)
leaq 0x7193(%rip), %rdi      # 0xa20e
movl $0xa9, %esi
movl $0x3, %edx
leaq 0x71cb(%rip), %rcx      # 0xa257
xorl %eax, %eax
callq 0x4ad6
movq %r15, %r12
movq (%r14), %r14
jmp 0x2f62
movq 0x88(%rax), %rax
testq %rax, %rax
jne 0x2efb
cmpl $0x0, (%r12)
movq 0x18(%rsp), %rax
movq (%rax), %rcx
je 0x30c6
xorl %eax, %eax
testq %rcx, %rcx
jne 0x30fb
jmp 0x30d7
testq %rcx, %rcx
je 0x30d7
movl $0x4, (%r12)
xorl %eax, %eax
jmp 0x30fb
leaq 0x7130(%rip), %rdi      # 0xa20e
leaq 0x718b(%rip), %rcx      # 0xa270
movl $0xbc, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x4ad6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rdx
movq 0x8(%rax), %rcx
leaq 0x716a(%rip), %rsi      # 0xa286
movl $0x1, %edi
xorl %eax, %eax
callq 0x20f0
leaq 0x70d4(%rip), %rsi      # 0xa203
movl $0x1, %edi
xorl %eax, %eax
callq 0x2240