// File: /workspace/github_cpp_makefile_star2_O3/ixchow[P]http-tweak/./http.hpp
// Function: http::server::server(unsigned short)
inline server::server(uint16_t port) {

	#ifdef _WIN32
	{ //init winsock:
		WSADATA info;
		if (WSAStartup((2 << 8) | 2, &info) != 0) {
			throw std::runtime_error("WSAStartup failed.");
		}
	}
	#endif

	//----------- socket setup -----------
	{ //create socket:
		listen_socket = ::socket(AF_INET, SOCK_STREAM, 0);
		if (listen_socket == -1) {
			throw std::system_error(errno, std::system_category(), "failed to create socket");
		}
	}
	{ //make it okay to reuse port:
		#ifdef _WIN32
		BOOL one = TRUE;
		int ret = setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast< const char * >(&one), sizeof(one));
		#else
		int one = 1;
		int ret = setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
		#endif
		if (ret != 0) {
			std::cerr << "[server::server] WARNING: Failed to set socket reuse address." << std::endl;
		}
	}
	{ //bind to address
		struct sockaddr_in addr;
		memset(&addr, 0, sizeof(addr));
		addr.sin_family = AF_INET;
		addr.sin_port = htons(port);
		addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
		int ret = bind(listen_socket, reinterpret_cast< sockaddr * >(&addr), sizeof(addr));
		if (ret < 0) {
			closesocket(listen_socket);
			throw std::system_error(errno, std::system_category(), "failed to bind socket");
		}
	}
	{ //listen on socket
		int ret = ::listen(listen_socket, 5);
		if (ret < 0) {
			closesocket(listen_socket);
			throw std::system_error(errno, std::system_category(), "failed to listen on socket");
		}
	}


	std::cout << "[server::server] Server started at localhost:" << port << "." << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %esi, %r15d
movq %rdi, %r14
movl $0xffffffff, (%rdi)     # imm = 0xFFFFFFFF
leaq 0x8(%rdi), %rbx
movq %rbx, 0x10(%rdi)
movq %rbx, 0x8(%rdi)
xorl %eax, %eax
movq %rax, 0x18(%rdi)
movb $0x0, 0x20(%rdi)
movq %rax, 0x28(%rdi)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x30e0
movl %eax, (%r14)
cmpl $-0x1, %eax
je 0x94da
leaq -0x30(%rbp), %rcx
movl $0x1, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x3580
testl %eax, %eax
je 0x941a
movq 0x5c0e(%rip), %r12      # 0xefe8
leaq 0x21f0(%rip), %rsi      # 0xb5d1
movl $0x3d, %edx
movq %r12, %rdi
callq 0x33e0
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x3360
movsbl %al, %esi
movq 0x5bdb(%rip), %rdi      # 0xefe8
callq 0x3040
movq %rax, %rdi
callq 0x32b0
leaq -0x30(%rbp), %rsi
movq $0x0, 0x8(%rsi)
movl %r15d, %eax
rolw $0x8, %ax
movw $0x2, (%rsi)
movw %ax, 0x2(%rsi)
movl $0x100007f, 0x4(%rsi)   # imm = 0x100007F
movl (%r14), %edi
movl $0x10, %edx
callq 0x30a0
testl %eax, %eax
js 0x9524
movl (%r14), %edi
movl $0x5, %esi
callq 0x33c0
testl %eax, %eax
js 0x9573
movq 0x5b52(%rip), %rdi      # 0xefc0
leaq 0x21cb(%rip), %rsi      # 0xb640
movl $0x2d, %edx
callq 0x33e0
movzwl %r15w, %esi
movq 0x5b36(%rip), %rdi      # 0xefc0
callq 0x32a0
movq %rax, %r15
leaq 0x2219(%rip), %rsi      # 0xb6b2
movl $0x1, %edx
movq %rax, %rdi
callq 0x33e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3360
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x32b0
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x31e0
movq %rax, %r12
callq 0x3070
movl (%rax), %r15d
callq 0x3240
leaq 0x20be(%rip), %rcx      # 0xb5b9
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x9600
movq 0x5a70(%rip), %rsi      # 0xef80
movq 0x5a91(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3550
jmp 0x95c0
movl (%r14), %edi
callq 0x35c0
movl $0x20, %edi
callq 0x31e0
movq %rax, %r12
callq 0x3070
movl (%rax), %r15d
callq 0x3240
leaq 0x20c2(%rip), %rcx      # 0xb60f
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x9600
movq 0x5a1e(%rip), %rsi      # 0xef80
movq 0x5a3f(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3550
jmp 0x95c0
movl (%r14), %edi
callq 0x35c0
movl $0x20, %edi
callq 0x31e0
movq %rax, %r12
callq 0x3070
movl (%rax), %r15d
callq 0x3240
leaq 0x2089(%rip), %rcx      # 0xb625
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x9600
movq 0x59cf(%rip), %rsi      # 0xef80
movq 0x59f0(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3550
jmp 0x95c4
jmp 0x95c4
movq %rax, %r15
movq %r12, %rdi
callq 0x32e0
jmp 0x95da
jmp 0x95d7
jmp 0x95d7
jmp 0x95d7
movq %rax, %r15
movq 0x28(%r14), %rdi
testq %rdi, %rdi
je 0x95e8
callq 0x3420
movq $0x0, 0x28(%r14)
movq %rbx, %rdi
callq 0x7b7e
movq %r15, %rdi
callq 0x3570