// File: /workspace/github_c_makefile_star2_O0/uhlin[P]enhanced-duc/source/network.c
// Function: net_check_for_ip_change
ip_chg_t
net_check_for_ip_change(void)
{
	bool			 address_resolved = false;
	bool			 connected = false;
	char			 buf[1000] = { '\0' };
	char			 srv[255] = { '\0' };
	const char		*backup_srv = setting("backup_ip_lookup_srv");
	const char		*port = "80";
	const char		*primary_srv = setting("primary_ip_lookup_srv");
	struct addrinfo		*res, *rp;
	unsigned char		 nw_addr[sizeof(struct in_addr)];

	if (setting_bool("force_update", true))
		return IP_HAS_CHANGED;

	if ((res = net_addr_resolve(primary_srv, port)) != NULL) {
		(void) strlcpy(srv, primary_srv, sizeof srv);
		address_resolved = true;
		goto done;
	}
	if ((res = net_addr_resolve(backup_srv, port)) != NULL) {
		(void) strlcpy(srv, backup_srv, sizeof srv);
		address_resolved = true;
	}

  done:
	if (!address_resolved)
		return IP_HAS_CHANGED; /* force update */

	for (rp = res; rp; rp = rp->ai_next) {
		g_socket =
		    socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);

		if (g_socket == SOCKET_CREATION_FAILED) {
			continue;
		} else if (connect(g_socket, rp->ai_addr, rp->ai_addrlen) == 0) {
			connected = true;
			break;
		} else {
			(void) close(g_socket);
		}
	}

	freeaddrinfo(res);

	if (!connected) {
		if (g_socket >= 0)
			(void) close(g_socket);
		g_socket = -1;
		return IP_HAS_CHANGED;
	}

	(void) net_send_plain("GET /index.html HTTP/1.0\r\nHost: %s\r\n"
	    "User-Agent: %s/%s %s", srv, g_programName, g_programVersion,
	    g_maintainerEmail);
	(void) net_recv_plain(buf, sizeof buf);
	(void) close(g_socket);
	g_socket = -1;

	const char *cp = strrchr(trim(buf), '\n');

	if (!cp) {
		log_warn(0, "net_check_for_ip_change: warning: "
		    "cannot locate last occurrance of a newline");
		return IP_NO_CHANGE;
	} else if (inet_pton(AF_INET, ++cp, nw_addr) == 0) {
		log_warn(0, "net_check_for_ip_change: warning: "
		    "bogus ipv4 address");
		return IP_NO_CHANGE;
	} else if (strings_match(cp, g_last_ip_addr)) {
		log_debug("not updating (the external ip hasn't changed)");
		return IP_NO_CHANGE;
	}

	(void) strlcpy(g_last_ip_addr, cp, sizeof g_last_ip_addr);
	log_msg("ip has changed to %s", cp);
	return IP_HAS_CHANGED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movb $0x0, -0x5(%rbp)
movb $0x0, -0x6(%rbp)
leaq -0x3f0(%rbp), %rdi
xorl %esi, %esi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x4210
leaq -0x4f0(%rbp), %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0x4210
leaq 0x3f67(%rip), %rdi      # 0xc697
callq 0x9060
movq %rax, -0x4f8(%rbp)
leaq 0x3f69(%rip), %rax      # 0xc6ac
movq %rax, -0x500(%rbp)
leaq 0x3f5e(%rip), %rdi      # 0xc6af
callq 0x9060
movq %rax, -0x508(%rbp)
leaq 0x3f61(%rip), %rdi      # 0xc6c5
movl $0x1, %esi
callq 0x8ad0
testb $0x1, %al
jne 0x8774
jmp 0x8780
movl $0x0, -0x4(%rbp)
jmp 0x8a2a
movq -0x508(%rbp), %rdi
movq -0x500(%rbp), %rsi
callq 0x8550
movq %rax, -0x510(%rbp)
cmpq $0x0, %rax
je 0x87be
leaq -0x4f0(%rbp), %rdi
movq -0x508(%rbp), %rsi
movl $0xff, %edx
callq 0x9f30
movb $0x1, -0x5(%rbp)
jmp 0x87fc
movq -0x4f8(%rbp), %rdi
movq -0x500(%rbp), %rsi
callq 0x8550
movq %rax, -0x510(%rbp)
cmpq $0x0, %rax
je 0x87fa
leaq -0x4f0(%rbp), %rdi
movq -0x4f8(%rbp), %rsi
movl $0xff, %edx
callq 0x9f30
movb $0x1, -0x5(%rbp)
jmp 0x87fc
testb $0x1, -0x5(%rbp)
jne 0x880e
movl $0x0, -0x4(%rbp)
jmp 0x8a2a
movq -0x510(%rbp), %rax
movq %rax, -0x518(%rbp)
cmpq $0x0, -0x518(%rbp)
je 0x88af
movq -0x518(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x518(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x518(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x40e0
movl %eax, 0x7c55(%rip)      # 0x104a8
cmpl $-0x1, 0x7c4e(%rip)     # 0x104a8
jne 0x885e
jmp 0x8898
movl 0x7c44(%rip), %edi      # 0x104a8
movq -0x518(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x518(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x4350
cmpl $0x0, %eax
jne 0x8889
movb $0x1, -0x6(%rbp)
jmp 0x88af
movl 0x7c19(%rip), %edi      # 0x104a8
callq 0x47e0
jmp 0x8896
jmp 0x8898
movq -0x518(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x518(%rbp)
jmp 0x881c
movq -0x510(%rbp), %rdi
callq 0x4590
testb $0x1, -0x6(%rbp)
jne 0x88eb
cmpl $0x0, 0x7be0(%rip)      # 0x104a8
jl 0x88d5
movl 0x7bd8(%rip), %edi      # 0x104a8
callq 0x47e0
movl $0xffffffff, 0x7bc9(%rip) # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x8a2a
leaq -0x4f0(%rbp), %rsi
leaq 0x3dd9(%rip), %rdi      # 0xc6d2
leaq 0x2cc0(%rip), %rdx      # 0xb5c0
leaq 0x2cc6(%rip), %rcx      # 0xb5cd
leaq 0x2cd2(%rip), %r8       # 0xb5e0
movb $0x0, %al
callq 0x7fe0
leaq -0x3f0(%rbp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x81a0
movl 0x7b7c(%rip), %edi      # 0x104a8
callq 0x47e0
movl $0xffffffff, 0x7b6d(%rip) # imm = 0xFFFFFFFF
leaq -0x3f0(%rbp), %rdi
callq 0xa310
movq %rax, %rdi
movl $0xa, %esi
callq 0x44a0
movq %rax, -0x528(%rbp)
cmpq $0x0, -0x528(%rbp)
jne 0x8981
xorl %edi, %edi
leaq 0x3d9d(%rip), %rsi      # 0xc70b
movb $0x0, %al
callq 0x6300
movl $0x1, -0x4(%rbp)
jmp 0x8a2a
movq -0x528(%rbp), %rsi
addq $0x1, %rsi
movq %rsi, -0x528(%rbp)
leaq -0x51c(%rbp), %rdx
movl $0x2, %edi
callq 0x47c0
cmpl $0x0, %eax
jne 0x89c2
xorl %edi, %edi
leaq 0x3da6(%rip), %rsi      # 0xc758
movb $0x0, %al
callq 0x6300
movl $0x1, -0x4(%rbp)
jmp 0x8a2a
movq -0x528(%rbp), %rdi
leaq 0x7f60(%rip), %rsi      # 0x10930
callq 0x8a40
testb $0x1, %al
jne 0x89db
jmp 0x89f2
leaq 0x3dab(%rip), %rdi      # 0xc78d
movb $0x0, %al
callq 0x6170
movl $0x1, -0x4(%rbp)
jmp 0x8a2a
jmp 0x89f4
jmp 0x89f6
movq -0x528(%rbp), %rsi
leaq 0x7f2c(%rip), %rdi      # 0x10930
movl $0x64, %edx
callq 0x9f30
movq -0x528(%rbp), %rsi
leaq 0x3d9f(%rip), %rdi      # 0xc7bb
movb $0x0, %al
callq 0x6260
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
nopw %cs:(%rax,%rax)