// File: dentiny[P]HTTP-Cache-Proxy/Proxy.cpp
// Function: Proxy::constructServer()
void constructServer()
    {
        // initialize host information
        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;
        host_info.ai_flags = AI_PASSIVE;

        // get address information
        status = getaddrinfo(NULL, listen_port, &host_info, &host_info_list);
        if(status != 0)
        {
            std::cerr << "Construct server getaddrinfo error" << std::endl;
            exit(EXIT_FAILURE);
        }

        // create a socket file descriptor
        socket_fd = socket(host_info_list->ai_family,
                        host_info_list->ai_socktype,
                        host_info_list->ai_protocol);
        if(socket_fd == -1) 
        {
        	freeaddrinfo(host_info_list);
            std::cerr << "Construct server create socket error" << std::endl;
            exit(EXIT_FAILURE);
        }

        // set socket option
        int yes = 1;
        status = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
        if(status == -1)
        {
        	freeaddrinfo(host_info_list);
        	close(socket_fd);
            std::cerr << "Construct server set socket option error" << std::endl;
            exit(EXIT_FAILURE);
        }

        // bind
        status = bind(socket_fd, host_info_list->ai_addr, host_info_list->ai_addrlen);
        if(status == -1) 
        {
        	freeaddrinfo(host_info_list);
        	close(socket_fd);
            std::cerr << "Construct server cannot bind socket" << std::endl;
            exit(EXIT_FAILURE);
        }

        // listen
        status = listen(socket_fd, BACKLOG);
        if(status == -1)
        {
        	freeaddrinfo(host_info_list);
        	close(socket_fd);
            std::cerr << "Construct server listen error" << std::endl;
            exit(EXIT_FAILURE);
        }

        // free allocated host_info_list
        freeaddrinfo(host_info_list);
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x4200
movq -0x50(%rbp), %rax
movl $0x0, -0x34(%rbp)
movl $0x1, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq 0x2a8(%rax), %rsi
xorl %eax, %eax
movl %eax, %edi
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x44b0
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x2b0(%rax)
cmpl $0x0, 0x2b0(%rax)
je 0x4e46
movq 0x1f1c7(%rip), %rdi     # 0x23fe8
leaq 0x14217(%rip), %rsi     # 0x1903f
callq 0x43c0
movq %rax, %rdi
movq 0x1f161(%rip), %rsi     # 0x23f98
callq 0x4400
movl $0x1, %edi
callq 0x4480
movq -0x40(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x40(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x40(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x40b0
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x2b4(%rax)
cmpl $-0x1, 0x2b4(%rax)
jne 0x4eaa
movq -0x40(%rbp), %rdi
callq 0x44d0
movq 0x1f163(%rip), %rdi     # 0x23fe8
leaq 0x141d6(%rip), %rsi     # 0x19062
callq 0x43c0
movq %rax, %rdi
movq 0x1f0fd(%rip), %rsi     # 0x23f98
callq 0x4400
movl $0x1, %edi
callq 0x4480
movq -0x50(%rbp), %rax
movl $0x1, -0x44(%rbp)
movl 0x2b4(%rax), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x44(%rbp), %rcx
movl $0x4, %r8d
callq 0x4660
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x2b0(%rax)
cmpl $-0x1, 0x2b0(%rax)
jne 0x4f2d
movq -0x40(%rbp), %rdi
callq 0x44d0
movq -0x50(%rbp), %rax
movl 0x2b4(%rax), %edi
callq 0x46d0
movq 0x1f0e0(%rip), %rdi     # 0x23fe8
leaq 0x14178(%rip), %rsi     # 0x19087
callq 0x43c0
movq %rax, %rdi
movq 0x1f07a(%rip), %rsi     # 0x23f98
callq 0x4400
movl $0x1, %edi
callq 0x4480
movq -0x50(%rbp), %rax
movl 0x2b4(%rax), %edi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x40(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x4080
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x2b0(%rax)
cmpl $-0x1, 0x2b0(%rax)
jne 0x4fa4
movq -0x40(%rbp), %rdi
callq 0x44d0
movq -0x50(%rbp), %rax
movl 0x2b4(%rax), %edi
callq 0x46d0
movq 0x1f069(%rip), %rdi     # 0x23fe8
leaq 0x1412a(%rip), %rsi     # 0x190b0
callq 0x43c0
movq %rax, %rdi
movq 0x1f003(%rip), %rsi     # 0x23f98
callq 0x4400
movl $0x1, %edi
callq 0x4480
movq -0x50(%rbp), %rax
movl 0x2b4(%rax), %edi
movl $0x64, %esi
callq 0x4460
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x2b0(%rax)
cmpl $-0x1, 0x2b0(%rax)
jne 0x5011
movq -0x40(%rbp), %rdi
callq 0x44d0
movq -0x50(%rbp), %rax
movl 0x2b4(%rax), %edi
callq 0x46d0
movq 0x1effc(%rip), %rdi     # 0x23fe8
leaq 0x140e1(%rip), %rsi     # 0x190d4
callq 0x43c0
movq %rax, %rdi
movq 0x1ef96(%rip), %rsi     # 0x23f98
callq 0x4400
movl $0x1, %edi
callq 0x4480
movq -0x40(%rbp), %rdi
callq 0x44d0
addq $0x50, %rsp
popq %rbp
retq