// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x58(%rbp)
movl $0x0, -0xe4(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x2260
cmpl $-0x1, %eax
jne 0x3691
movl $0x1, %edi
leaq 0xab5d(%rip), %rsi      # 0xe1e7
movb $0x0, %al
callq 0x2240
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x38f1
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x38db
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x2a10
cmpl $0x0, %eax
je 0x3716
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x3e, %edx
callq 0x5c10
leaq -0xa0(%rbp), %r8
leaq 0xaaf9(%rip), %rdi      # 0xe1f2
movl $0x81, %esi
movl $0x3, %edx
leaq 0xaaf2(%rip), %rcx      # 0xe1fc
movb $0x0, %al
callq 0x5dc0
jmp 0x38ca
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x38c8
movq -0x58(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x3754
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
je 0x3759
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movzwl (%rax), %eax
cmpl $0xa, %eax
je 0x3759
jmp 0x38b8
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x3e, %edx
callq 0x5c10
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0xe0(%rbp), %rsi
movl $0x3e, %edx
callq 0x5c10
leaq -0xa0(%rbp), %r8
movq -0x58(%rbp), %rax
movq 0x8(%rax), %r9
leaq -0xe0(%rbp), %rax
leaq 0xaa4a(%rip), %rdi      # 0xe1f2
movl $0x8f, %esi
movl $0x3, %edx
leaq 0xaa5b(%rip), %rcx      # 0xe214
movq %rax, (%rsp)
movb $0x0, %al
callq 0x5dc0
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x24e0
cmpl $0x0, %eax
je 0x38b6
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movl -0x34(%rbp), %edx
callq 0x2f30
movl %eax, -0xe8(%rbp)
cmpl $0x1, -0xe8(%rbp)
je 0x3810
cmpl $0x2, -0xe8(%rbp)
jne 0x38b4
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3828
cmpl $0x0, -0xe4(%rbp)
jne 0x3828
jmp 0x3954
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x387b
movq -0x18(%rbp), %rax
movl $0x6, (%rax)
leaq 0xa98f(%rip), %rdi      # 0xe1f2
movl $0xa1, %esi
movl $0x3, %edx
leaq 0xa9b9(%rip), %rcx      # 0xe22d
movb $0x0, %al
callq 0x5dc0
cmpl $0x2, -0xe8(%rbp)
jne 0x38b2
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
leaq 0xa958(%rip), %rdi      # 0xe1f2
movl $0xa9, %esi
movl $0x3, %edx
leaq 0xa990(%rip), %rcx      # 0xe23b
movb $0x0, %al
callq 0x5dc0
jmp 0x38b4
jmp 0x38b6
jmp 0x38b8
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x371e
jmp 0x38ca
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x36b2
jmp 0x38dd
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x369c
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x3919
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3919
cmpl $0x1, -0xe4(%rbp)
jle 0x390f
jmp 0x3954
movq -0x18(%rbp), %rax
movl $0x4, (%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x392c
movl $0x0, -0x4(%rbp)
jmp 0x397a
leaq 0xa8bf(%rip), %rdi      # 0xe1f2
movl $0xbc, %esi
movl $0x2, %edx
leaq 0xa910(%rip), %rcx      # 0xe254
movb $0x0, %al
callq 0x5dc0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x397a
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edi
leaq 0xa8f7(%rip), %rsi      # 0xe26a
movb $0x0, %al
callq 0x20d0
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)