// File: /workspace/github_cpp_makefile_star2_O1/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 0x5944
movq %rax, %rbx
movq (%rax), %rdi
movq (%r15), %rsi
movq 0x10(%r15), %rdx
callq 0x2200
movq 0x10(%r15), %r9
cmpq $0x1c, %r9
jl 0x2abc
cmpw $0x2, 0x4(%r12)
movq (%r15), %rax
jne 0x2ae0
movl 0x10(%rax), %eax
movq (%rbx), %rcx
movl %eax, 0x10(%rcx)
movl 0x28(%r15), %eax
movl %eax, 0x14(%rcx)
movl 0x24(%r15), %eax
movl %eax, 0x18(%rcx)
leaq 0x9816(%rip), %rax      # 0xc288
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x2aa3
movl 0x24(%r15), %ecx
movl 0x28(%r15), %r8d
movl 0x28(%r14), %r10d
subq $0x8, %rsp
leaq 0x45e0(%rip), %rdx      # 0x7071
movl $0x5, %esi
xorl %eax, %eax
pushq %r10
callq 0x56bc
addq $0x10, %rsp
movq (%rbx), %rax
movw $0x4, 0x4(%rax)
movl $0xffffffff, 0x24(%rbx) # imm = 0xFFFFFFFF
movl 0x28(%r14), %eax
movl %eax, 0x28(%rbx)
jmp 0x2b22
leaq 0x97c5(%rip), %rax      # 0xc288
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x2b22
leaq 0x4612(%rip), %rdx      # 0x70e4
movl $0x5, %esi
xorl %eax, %eax
callq 0x56bc
jmp 0x2b22
movl 0x14(%rax), %r12d
movl 0x18(%rax), %r13d
leaq 0x9799(%rip), %rax      # 0xc288
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x2b1a
movl 0x24(%r15), %ecx
movl 0x28(%r15), %r8d
leaq 0x459a(%rip), %rdx      # 0x70a0
movl $0x5, %esi
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x56bc
addq $0x10, %rsp
movl %r13d, 0x24(%rbx)
movl %r12d, 0x28(%rbx)
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0x59ac
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x2b4c
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq *%rax
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jns 0x2b59
movq %rbx, %rdi
callq 0x59ac
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop