// File: /workspace/github_cpp_makefile_star2_O3/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 0x5848
movq %rax, %rbx
movq (%rax), %rdi
movq (%r15), %rsi
movq 0x10(%r15), %rdx
callq 0x2200
movq 0x10(%r15), %r9
cmpq $0x1c, %r9
jl 0x2ab0
cmpw $0x2, 0x4(%r12)
movq (%r15), %rax
jne 0x2ad4
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 0x981e(%rip), %rdx      # 0xc288
movq (%rdx), %rdi
cmpl $0x5, (%rdi)
jl 0x2a9a
movl 0x28(%r15), %r8d
movl 0x28(%r14), %r10d
subq $0x8, %rsp
leaq 0x45ec(%rip), %rdx      # 0x7071
movl $0x5, %esi
xorl %eax, %eax
pushq %r10
callq 0x55c0
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 0x2b16
leaq 0x97d1(%rip), %rax      # 0xc288
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x2b16
leaq 0x461e(%rip), %rdx      # 0x70e4
movl $0x5, %esi
xorl %eax, %eax
callq 0x55c0
jmp 0x2b16
movl 0x14(%rax), %r12d
movl 0x18(%rax), %r13d
leaq 0x97a5(%rip), %rax      # 0xc288
movq (%rax), %rdi
cmpl $0x5, (%rdi)
jl 0x2b0e
movl 0x24(%r15), %ecx
movl 0x28(%r15), %r8d
leaq 0x45a6(%rip), %rdx      # 0x70a0
movl $0x5, %esi
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x55c0
addq $0x10, %rsp
movl %r13d, 0x24(%rbx)
movl %r12d, 0x28(%rbx)
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0x58b0
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x2b40
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq *%rax
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jns 0x2b4d
movq %rbx, %rdi
callq 0x58b0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop