// File: /workspace/github_c_makefile_star2_O0/uhlin[P]enhanced-duc/source/network.c
// Function: net_connect
int
net_connect(void)
{
	bool			 connected = false;
	const char		*host = setting("sp_hostname");
	const char		*port = setting("port");
	struct addrinfo		*res, *rp;

	log_debug("connecting to %s (%s)...", host, port);

	if ((res = net_addr_resolve(host, port)) == NULL) {
		log_warn(0, "unable to get a list of ip addresses. "
		    "bogus hostname?");
		return -1;
	} else {
		log_debug("get a list of ip addresses complete");
	}

	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) {
			log_debug("connected!");
			connected = true;
			break;
		} else {
			(void) close(g_socket);
		}
	}

	freeaddrinfo(res);

	if (!connected || (ssl_is_enabled() && net_ssl_begin() == -1)) {
		log_warn(0, "failed to establish a connection");
		return -1;
	}
	if (ssl_is_enabled() &&
	    net_ssl_check_hostname(host, 0) == HOSTNAME_MISMATCH) {
		log_warn(0, "net_ssl_check_hostname: warning: "
		    "hostname checking failed: "
		    "hostname specified by 'sp_hostname' mismatch: "
		    "failed to establish a connection");
		return -1;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb $0x0, -0x5(%rbp)
leaq 0x3b72(%rip), %rdi      # 0xbf35
callq 0x9060
movq %rax, -0x10(%rbp)
leaq 0x40c9(%rip), %rdi      # 0xc49c
callq 0x9060
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x40b6(%rip), %rdi      # 0xc4a1
movb $0x0, %al
callq 0x6170
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x8550
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x8425
xorl %edi, %edi
leaq 0x40a8(%rip), %rsi      # 0xc4ba
movb $0x0, %al
callq 0x6300
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8538
leaq 0x40c4(%rip), %rdi      # 0xc4f0
movb $0x0, %al
callq 0x6170
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x84c0
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x28(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x40e0
movl %eax, 0x8046(%rip)      # 0x104a8
cmpl $-0x1, 0x803f(%rip)     # 0x104a8
jne 0x846d
jmp 0x84af
movl 0x8035(%rip), %edi      # 0x104a8
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x4350
cmpl $0x0, %eax
jne 0x84a0
leaq 0x4081(%rip), %rdi      # 0xc514
movb $0x0, %al
callq 0x6170
movb $0x1, -0x5(%rbp)
jmp 0x84c0
movl 0x8002(%rip), %edi      # 0x104a8
callq 0x47e0
jmp 0x84ad
jmp 0x84af
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x843b
movq -0x20(%rbp), %rdi
callq 0x4590
testb $0x1, -0x5(%rbp)
je 0x84e4
callq 0x8600
testb $0x1, %al
jne 0x84da
jmp 0x84fd
callq 0x7ad0
cmpl $-0x1, %eax
jne 0x84fd
xorl %edi, %edi
leaq 0x409b(%rip), %rsi      # 0xc588
movb $0x0, %al
callq 0x6300
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8538
callq 0x8600
testb $0x1, %al
jne 0x8508
jmp 0x8531
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7470
cmpl $0x1, %eax
jne 0x8531
xorl %edi, %edi
leaq 0x3ffe(%rip), %rsi      # 0xc51f
movb $0x0, %al
callq 0x6300
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8538
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)