// File: /workspace/github_cpp_makefile_star2_O1/DMLfor[P]TinyWebServer/./ServerBase.hpp
// Function: WebServer::ServerBase<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>>>>::respond(std::shared_ptr<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>>>>, std::shared_ptr<WebServer::Request>) const
void WebServer::ServerBase<socket_type>::respond(std::shared_ptr<socket_type> socket, std::shared_ptr<Request> request) const
{
	for(auto res_it : all_resources)
	{
		// 对请求路径和方法进行匹配查找, 并生成响应
		std::regex e(res_it->first);
		std::smatch sm_res;
		if(std::regex_match(request->path, sm_res, e))
		{
			if(res_it->second.count(request->method) > 0)
				request->path_match = move(sm_res);
			// 会被推导为 std::shared_ptr<boost::asio::streambuf>
			auto write_buffer = std::make_shared<boost::asio::streambuf>();
			std::ostream respondse(write_buffer.get());
			res_it->second[request->method](respondse, *request);

			// 在 lambda 中不糊 write_buffer 使其不会再 async_write 完成前被销毁
			boost::asio::async_write(*socket, *write_buffer,
					[this, socket, request, write_buffer](const boost::system::error_code &ec, size_t bytes_transferred)
					{
						// HTTP 持久连接(HTTP 1.1), 递归调用
						if(!ec && stof(request->http_version) > 1.05)
							process_request_and_respond(socket);
					});
			return ;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, 0x50(%rsp)
movq 0x108(%rdi), %r13
movq %rdi, 0x48(%rsp)
movq 0x110(%rdi), %r14
cmpq %r14, %r13
je 0x1d03e
movq %rdx, %rbx
leaq 0xa8(%rsp), %rbp
movq (%r13), %r15
leaq 0x20(%r15), %rsi
movq %rbp, %rdi
movl $0x10, %edx
callq 0x2d1a8
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq (%rbx), %rax
movq 0x20(%rax), %rdi
movq 0x28(%rax), %rsi
addq %rdi, %rsi
leaq 0x20(%rsp), %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x28561
movl %eax, %r12d
testb %al, %al
je 0x1cf0d
addq $0x40, %r15
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x2d23e
testq %rax, %rax
je 0x1ce5c
movq %r14, %rbp
movq (%rbx), %r14
movq 0xa8(%r14), %rdi
movaps 0x20(%rsp), %xmm0
movq 0x30(%rsp), %rax
movq %rdi, 0x20(%rsp)
movups 0xb0(%r14), %xmm1
movups %xmm0, 0xa8(%r14)
movq %rax, 0xb8(%r14)
movups %xmm1, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rdi, %rdi
je 0x1ce45
callq 0xa5d0
movq 0x38(%rsp), %rax
movq %rax, 0xc0(%r14)
movq %rbp, %r14
leaq 0xa8(%rsp), %rbp
movq %r13, 0x58(%rsp)
movl %r12d, %r13d
movq %rbp, %r12
movq %r14, %rbp
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0xc8(%rsp), %r14
movq %r14, %rdx
callq 0x18f66
movq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0xa2d0
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x2d33a
leaq 0xc8(%rsp), %rsi
movl %r13d, %r15d
movq 0x58(%rsp), %r13
cmpq $0x0, 0x10(%rax)
je 0x1d050
movq %rbp, %r14
movq %r12, %rbp
movq (%rbx), %rdx
movq %rax, %rdi
callq *0x18(%rax)
movq 0x50(%rsp), %rdx
movq (%rdx), %rax
movq 0x10(%rsp), %rcx
movq 0x48(%rsp), %rsi
movq %rsi, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movq 0x8(%rdx), %rdx
movq %rdx, 0x80(%rsp)
testq %rdx, %rdx
je 0x1cf3a
movq 0x2d0ad(%rip), %rsi     # 0x49fb0
cmpb $0x0, (%rsi)
je 0x1cf36
incl 0x8(%rdx)
jmp 0x1cf3a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1cf1c
callq 0xa5d0
movq %rbp, %rdi
callq 0x1d3e4
addq $0x8, %r13
cmpq %r14, %r13
jne 0x1cd93
jmp 0x1d03e
lock
incl 0x8(%rdx)
movq (%rbx), %rdx
movq %rdx, 0x88(%rsp)
movq 0x8(%rbx), %rdx
movq %rdx, 0x90(%rsp)
testq %rdx, %rdx
je 0x1cf6b
movq 0x2d053(%rip), %rsi     # 0x49fb0
cmpb $0x0, (%rsi)
je 0x1cf67
incl 0x8(%rdx)
jmp 0x1cf6b
lock
incl 0x8(%rdx)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rsi, 0x98(%rsp)
movq %rdx, 0xa0(%rsp)
testq %rdx, %rdx
je 0x1cf9f
movq 0x2d01f(%rip), %rsi     # 0x49fb0
cmpb $0x0, (%rsi)
je 0x1cf9b
incl 0x8(%rdx)
jmp 0x1cf9f
lock
incl 0x8(%rdx)
movq %rcx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x60(%rsp), %rdx
leaq 0xf(%rsp), %rcx
callq 0x2d676
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x1cfd4
callq 0x1d2a8
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1cfe6
callq 0x1d2a8
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1cff8
callq 0x1d2a8
leaq 0xd0(%rsp), %rdi
callq 0xa250
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1d014
callq 0x1d2a8
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1d023
callq 0xa5d0
movq %rbp, %rdi
callq 0x1d3e4
addq $0x8, %r13
cmpq %r14, %r13
sete %al
orb %al, %r15b
je 0x1cd93
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xa2a0
jmp 0x1d08e
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2d20c
jmp 0x1d070
movq %rax, %rbx
jmp 0x1d07d
jmp 0x1d06d
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xa250
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1d091
callq 0x1d2a8
jmp 0x1d091
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1d0a0
callq 0xa5d0
leaq 0xa8(%rsp), %rdi
callq 0x1d3e4
movq %rbx, %rdi
callq 0xaa80
nop