// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mmulti.c
// Function: lookuphost
static int lookuphost(const char *name, struct sockaddr *host, int warnifmany)
{
	struct addrinfo * result, *res;
	struct addrinfo hints;
	char *wname, *portch;
	int error, port = 0, found = 0;

	// ipv6 for future thought:
	//  [2001:db8::1]:1234

	wname = strdup(name);
	if (!wname) {
		return 0;
	}

	// Parse a port.
	portch = strrchr(wname, ':');
	if (portch) {
		*(portch++) = 0;
		if (*portch != 0) {
			port = (int)strtol(portch, NULL, 10);
		}
	}
	if (port < 1025 || port > 65534) port = NETPORT;

	memset(&hints, 0, sizeof(hints));
	hints.ai_flags = AI_ADDRCONFIG;
	hints.ai_family = domain;
	if (domain == PF_INET6) {
		hints.ai_flags |= AI_V4MAPPED;
	}
	hints.ai_socktype = SOCK_DGRAM;
	hints.ai_protocol = IPPROTO_UDP;

	error = getaddrinfo(wname, NULL, &hints, &result);
	if (error) {
		printf("mmulti error: problem resolving %s (%s)\n", name, gai_strerror(error));
		free(wname);
		return 0;
	}

	for (res = result; res; res = res->ai_next) {
		if (res->ai_family == PF_INET && !found) {
			memcpy((struct sockaddr_in *)host, (struct sockaddr_in *)res->ai_addr, sizeof(struct sockaddr_in));
			((struct sockaddr_in *)host)->sin_port = htons(port);
			found = 1;
		} else if (res->ai_family == PF_INET6 && !found) {
			memcpy((struct sockaddr_in6 *)host, (struct sockaddr_in6 *)res->ai_addr, sizeof(struct sockaddr_in6));
			((struct sockaddr_in6 *)host)->sin6_port = htons(port);
			found = 1;
		} else if (found && warnifmany) {
			printf("mmulti warning: host name %s has another address: %s\n", wname, presentaddress(res->ai_addr));
		}
	}

	freeaddrinfo(result);
	free(wname);
	return found;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8070
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x87d54
movl $0x0, -0x4(%rbp)
jmp 0x87f7a
movq -0x68(%rbp), %rdi
movl $0x3a, %esi
callq 0x8d00
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x87da2
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movb $0x0, (%rax)
movq -0x70(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x87da0
movq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x8c30
movl %eax, -0x78(%rbp)
jmp 0x87da2
cmpl $0x401, -0x78(%rbp)     # imm = 0x401
jl 0x87db4
cmpl $0xfffe, -0x78(%rbp)    # imm = 0xFFFE
jle 0x87dbb
movl $0x5bd9, -0x78(%rbp)    # imm = 0x5BD9
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x8410
movl $0x20, -0x60(%rbp)
movl 0x71c788(%rip), %eax    # 0x7a4560
movl %eax, -0x5c(%rbp)
cmpl $0xa, 0x71c77e(%rip)    # 0x7a4560
jne 0x87ded
movl -0x60(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x60(%rbp)
movl $0x2, -0x58(%rbp)
movl $0x11, -0x54(%rbp)
movq -0x68(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x60(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x8f10
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
je 0x87e59
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x74(%rbp), %edi
callq 0x9120
movq -0x88(%rbp), %rsi
movq %rax, %rdx
leaq 0x68fd2(%rip), %rdi     # 0xf0e0f
movb $0x0, %al
callq 0x52630
movq -0x68(%rbp), %rdi
callq 0x8260
movl $0x0, -0x4(%rbp)
jmp 0x87f7a
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x87f62
movq -0x30(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jne 0x87eb8
cmpl $0x0, -0x7c(%rbp)
jne 0x87eb8
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl -0x78(%rbp), %eax
movzwl %ax, %edi
callq 0x8990
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movl $0x1, -0x7c(%rbp)
jmp 0x87f4f
movq -0x30(%rbp), %rax
cmpl $0xa, 0x4(%rax)
jne 0x87f0f
cmpl $0x0, -0x7c(%rbp)
jne 0x87f0f
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movl -0x78(%rbp), %eax
movzwl %ax, %edi
callq 0x8990
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movl $0x1, -0x7c(%rbp)
jmp 0x87f4d
cmpl $0x0, -0x7c(%rbp)
je 0x87f4b
cmpl $0x0, -0x1c(%rbp)
je 0x87f4b
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x87f90
movq -0x90(%rbp), %rsi
movq %rax, %rdx
leaq 0x68ef4(%rip), %rdi     # 0xf0e38
movb $0x0, %al
callq 0x52630
jmp 0x87f4d
jmp 0x87f4f
jmp 0x87f51
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x87e61
movq -0x28(%rbp), %rdi
callq 0x88e0
movq -0x68(%rbp), %rdi
callq 0x8260
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)