// File: dentiny[P]HTTP-Cache-Proxy/Proxy.cpp
// Function: Proxy::connectServer(Request const&, int&)
void connectServer(const Request & request, int & server_fd)
	{
		// initialize host info
		struct addrinfo host_info;
	    struct addrinfo * host_info_list;
	    memset(&host_info, 0, sizeof(host_info));
	    host_info.ai_family = AF_UNSPEC;
	    host_info.ai_socktype = SOCK_STREAM;

	    // get host information
	    const std::string & hostname = request.hostname;
	    const std::string & port = request.port;
	    status = getaddrinfo(hostname.c_str(), port.c_str(), &host_info, &host_info_list);
	    if(status != 0) 
	    {
	      	throw ProxyException("Connect server getaddrinfo error");
	    } 

	    // create socket
	    server_fd = socket(host_info_list->ai_family, 
	    					host_info_list->ai_socktype,
	                       	host_info_list->ai_protocol);
	    if(server_fd == -1) 
	    {
	    	freeaddrinfo(host_info_list);
	      	throw ProxyException("Connect server create socket error");
	    }

	    // connect a socket to a server
	    status = connect(server_fd, host_info_list->ai_addr, host_info_list->ai_addrlen);
	    if(status == -1) 
	    {
	    	freeaddrinfo(host_info_list);
	      	throw ProxyException("Connect socket to server error");
	    } 

	    // free address infor list
	    freeaddrinfo(host_info_list);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x4200
movl $0x0, -0x44(%rbp)
movl $0x1, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x4130
movq %rax, -0xf8(%rbp)
movq -0x60(%rbp), %rdi
callq 0x4130
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
leaq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x44b0
movl %eax, %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0x2b0(%rax)
cmpl $0x0, 0x2b0(%rax)
je 0x7f4b
movb $0x1, -0x95(%rbp)
movl $0x28, %edi
callq 0x41b0
movq %rax, -0x108(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x4650
movq -0x100(%rbp), %rdx
leaq 0x11325(%rip), %rsi     # 0x191d6
leaq -0x80(%rbp), %rdi
callq 0x4bf0
jmp 0x7ebc
movq -0x108(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9240
jmp 0x7ece
movq -0x108(%rbp), %rdi
movb $0x0, -0x95(%rbp)
leaq 0x1be15(%rip), %rsi     # 0x23cf8
leaq 0x13c6(%rip), %rdx      # 0x92b0
callq 0x4610
jmp 0x8192
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x7f23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4250
leaq -0x81(%rbp), %rdi
callq 0x4420
testb $0x1, -0x95(%rbp)
jne 0x7f3a
jmp 0x7f46
movq -0x108(%rbp), %rdi
callq 0x42d0
jmp 0x8186
movq -0x50(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x50(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x50(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x40b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x805f
movq -0x50(%rbp), %rdi
callq 0x44d0
movb $0x1, -0xba(%rbp)
movl $0x28, %edi
callq 0x41b0
movq %rax, -0x118(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x4650
movq -0x110(%rbp), %rdx
leaq 0x1123b(%rip), %rsi     # 0x191f7
leaq -0xb8(%rbp), %rdi
callq 0x4bf0
jmp 0x7fca
movq -0x118(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x9240
jmp 0x7fdf
movq -0x118(%rbp), %rdi
movb $0x0, -0xba(%rbp)
leaq 0x1bd04(%rip), %rsi     # 0x23cf8
leaq 0x12b5(%rip), %rdx      # 0x92b0
callq 0x4610
jmp 0x8192
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x8037
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4250
leaq -0xb9(%rbp), %rdi
callq 0x4420
testb $0x1, -0xba(%rbp)
jne 0x804e
jmp 0x805a
movq -0x118(%rbp), %rdi
callq 0x42d0
jmp 0x8186
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x50(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x4330
movl %eax, %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0x2b0(%rax)
cmpl $-0x1, 0x2b0(%rax)
jne 0x8174
movq -0x50(%rbp), %rdi
callq 0x44d0
movb $0x1, -0xe2(%rbp)
movl $0x28, %edi
callq 0x41b0
movq %rax, -0x128(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x4650
movq -0x120(%rbp), %rdx
leaq 0x11143(%rip), %rsi     # 0x1921a
leaq -0xe0(%rbp), %rdi
callq 0x4bf0
jmp 0x80e5
movq -0x128(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x9240
jmp 0x80fa
movq -0x128(%rbp), %rdi
movb $0x0, -0xe2(%rbp)
leaq 0x1bbe9(%rip), %rsi     # 0x23cf8
leaq 0x119a(%rip), %rdx      # 0x92b0
callq 0x4610
jmp 0x8192
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x814f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x4250
leaq -0xe1(%rbp), %rdi
callq 0x4420
testb $0x1, -0xe2(%rbp)
jne 0x8166
jmp 0x8172
movq -0x128(%rbp), %rdi
callq 0x42d0
jmp 0x8186
movq -0x50(%rbp), %rdi
callq 0x44d0
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x4640
nopw %cs:(%rax,%rax)
nopl (%rax)