// File: /workspace/github_cpp_makefile_star2_O2/roberty65[P]bServer/frame/testServer/src/../../../serverd/src/Echo.cpp
// Function: Echo::doForward(beyondy::Async::Message*)
int Echo::doForward(Message *req)
{
	struct proto_h16_head *h = (struct proto_h16_head *)req->data();

	Message *rsp = Message::create(req->getWptr(), req->fd, req->flow);
	memcpy(rsp->data(), req->data(), req->getWptr());

	if (req->getWptr() >= (long)(sizeof(struct proto_h16_head) + 3 * sizeof(int))) {
		if (h->cmd == ECHO_CMD_FORWARD_REQ) {
			*(int *)(rsp->data() + sizeof(struct proto_h16_head) + 0) = *(int *)(req->data() + sizeof(struct proto_h16_head));
			*(int *)(rsp->data() + sizeof(struct proto_h16_head) + sizeof(int)) = req->flow;
			*(int *)(rsp->data() + sizeof(struct proto_h16_head) + 2* sizeof(int)) = req->fd;
			SYSLOG_DEBUG("Forward from fd=%d flow=%d size=%ld to flow=%d", req->fd, req->flow, (long)req->getWptr(), dstFlow);

			struct proto_h16_head *h = (struct proto_h16_head *)rsp->data();
			h->cmd = ECHO_CMD_MORE_REQ;

			rsp->fd = -1;
			rsp->flow = dstFlow;
		}
		else {
			int oldFlow = *(int *)(req->data() + sizeof(struct proto_h16_head) + sizeof(int));
			int oldFd = *(int *)(req->data() + sizeof(struct proto_h16_head) + 2 * sizeof(int));
			SYSLOG_DEBUG("Forward result from fd=%d flow=%d size=%ld replied to fd=%d flow=%d", \
				req->fd, req->flow, (long)req->getWptr(), oldFd, oldFlow);

			rsp->fd = oldFd;
			rsp->flow = oldFlow;
		}
	}
	else {
		SYSLOG_DEBUG("Forward replied directly");
	}

	/* set response size */
	rsp->setWptr(req->getWptr());

	Message::destroy(req);
	if (sendMessage(rsp) < 0) {
		Message::destroy(rsp);
		return -1;
	}

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r15
movq %rdi, %r14
movq (%rsi), %r12
movq 0x10(%rsi), %rdi
movl 0x24(%rsi), %esi
movl 0x28(%r15), %edx
callq 0x54d8
movq %rax, %rbx
movq (%rax), %rdi
movq (%r15), %rsi
movq 0x10(%r15), %rdx
callq 0x2200
movq 0x10(%r15), %r9
cmpq $0x1c, %r9
jl 0x2abd
cmpw $0x2, 0x4(%r12)
movq (%r15), %rax
jne 0x2adf
movl 0x10(%rax), %ecx
movq (%rbx), %rax
movl %ecx, 0x10(%rax)
movl 0x28(%r15), %ecx
movl %ecx, 0x14(%rax)
movl 0x24(%r15), %ecx
movl %ecx, 0x18(%rax)
leaq 0x980a(%rip), %rdx      # 0xc288
movq (%rdx), %rdi
cmpl $0x5, (%rdi)
jl 0x2aaa
movl 0x28(%r15), %r8d
movl 0x28(%r14), %r10d
subq $0x8, %rsp
leaq 0x45d8(%rip), %rdx      # 0x7071
pushq $0x5
popq %rsi
xorl %eax, %eax
pushq %r10
callq 0x527e
popq %rcx
popq %rdx
movq (%rbx), %rax
movw $0x4, 0x4(%rax)
orl $-0x1, 0x24(%rbx)
movl 0x28(%r14), %eax
movl %eax, 0x28(%rbx)
jmp 0x2b1d
leaq 0x97c4(%rip), %rax      # 0xc288
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x2b1d
leaq 0x4611(%rip), %rdx      # 0x70e4
pushq $0x5
popq %rsi
xorl %eax, %eax
callq 0x527e
jmp 0x2b1d
movl 0x14(%rax), %r12d
movl 0x18(%rax), %r13d
leaq 0x979a(%rip), %rax      # 0xc288
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x2b15
movl 0x24(%r15), %ecx
movl 0x28(%r15), %r8d
leaq 0x459b(%rip), %rdx      # 0x70a0
pushq $0x5
popq %rsi
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x527e
popq %rcx
popq %rdx
movl %r13d, 0x24(%rbx)
movl %r12d, 0x28(%rbx)
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0x552a
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x2b47
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq *%rax
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jns 0x2b52
movq %rbx, %rdi
callq 0x552a
pushq $-0x1
popq %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq