// File: /workspace/github_cpp_makefile_star2_O1/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 0x95cc
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 0x950e
movq 0x5b1a(%rip), %r12      # 0xefe8
leaq 0x2123(%rip), %rsi      # 0xb5f8
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 0x5ae7(%rip), %rdi      # 0xefe8
callq 0x3040
movq %rax, %rdi
callq 0x32b0
xorps %xmm0, %xmm0
leaq -0x30(%rbp), %rsi
movaps %xmm0, (%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 0x9616
movl (%r14), %edi
movl $0x5, %esi
callq 0x33c0
testl %eax, %eax
js 0x9665
movq 0x5a60(%rip), %rdi      # 0xefc0
leaq 0x2100(%rip), %rsi      # 0xb667
movl $0x2d, %edx
callq 0x33e0
movzwl %r15w, %esi
movq 0x5a44(%rip), %rdi      # 0xefc0
callq 0x32a0
movq %rax, %r15
leaq 0x214e(%rip), %rsi      # 0xb6d9
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 0x1ff3(%rip), %rcx      # 0xb5e0
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x96f2
movq 0x597e(%rip), %rsi      # 0xef80
movq 0x599f(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3550
jmp 0x96b2
movl (%r14), %edi
callq 0x35c0
movl $0x20, %edi
callq 0x31e0
movq %rax, %r12
callq 0x3070
movl (%rax), %r15d
callq 0x3240
leaq 0x1ff7(%rip), %rcx      # 0xb636
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x96f2
movq 0x592c(%rip), %rsi      # 0xef80
movq 0x594d(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3550
jmp 0x96b2
movl (%r14), %edi
callq 0x35c0
movl $0x20, %edi
callq 0x31e0
movq %rax, %r12
callq 0x3070
movl (%rax), %r15d
callq 0x3240
leaq 0x1fbe(%rip), %rcx      # 0xb64c
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x96f2
movq 0x58dd(%rip), %rsi      # 0xef80
movq 0x58fe(%rip), %rdx      # 0xefa8
movq %r12, %rdi
callq 0x3550
jmp 0x96b6
jmp 0x96b6
movq %rax, %r15
movq %r12, %rdi
callq 0x32e0
jmp 0x96cc
jmp 0x96c9
jmp 0x96c9
jmp 0x96c9
movq %rax, %r15
movq 0x28(%r14), %rdi
testq %rdi, %rdi
je 0x96da
callq 0x3420
movq $0x0, 0x28(%r14)
movq %rbx, %rdi
callq 0x7c06
movq %r15, %rdi
callq 0x3570