// File: 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 %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c90
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c70
movq %rax, %rdi
movq -0x18(%rbp), %rax
movl 0x24(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x28(%rax), %edx
callq 0x9ea0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4c90
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c90
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c70
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rax, %rdx
callq 0x3200
movq -0x18(%rbp), %rdi
callq 0x4c70
cmpq $0x1c, %rax
jl 0x4745
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %eax
cmpl $0x2, %eax
jne 0x469b
movq -0x18(%rbp), %rdi
callq 0x4c90
movl 0x10(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4c90
movl -0x5c(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4c90
movl -0x58(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4c90
movl -0x54(%rbp), %ecx
movl %ecx, 0x18(%rax)
leaq 0xec9f(%rip), %rax      # 0x13298
movq (%rax), %rdi
movl $0x5, %esi
callq 0x3910
cmpl $0x0, %eax
je 0x4661
leaq 0xec86(%rip), %rax      # 0x13298
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c70
movq -0x70(%rbp), %rdi
movl -0x64(%rbp), %ecx
movl -0x60(%rbp), %r8d
movq %rax, %r9
movq -0x50(%rbp), %rax
movl 0x28(%rax), %eax
movl $0x5, %esi
leaq 0x8a14(%rip), %rdx      # 0xd06b
movl %eax, (%rsp)
movb $0x0, %al
callq 0x9aa0
jmp 0x4663
movq -0x28(%rbp), %rdi
callq 0x4c90
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movw $0x4, 0x4(%rcx)
movq -0x28(%rbp), %rcx
movl $0xffffffff, 0x24(%rcx) # imm = 0xFFFFFFFF
movl 0x28(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x4743
movq -0x18(%rbp), %rdi
callq 0x4c90
movl 0x14(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c90
movl 0x18(%rax), %eax
movl %eax, -0x38(%rbp)
leaq 0xebd8(%rip), %rax      # 0x13298
movq (%rax), %rdi
movl $0x5, %esi
callq 0x3910
cmpl $0x0, %eax
je 0x472d
leaq 0xebbf(%rip), %rax      # 0x13298
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c70
movq -0x80(%rbp), %rdi
movl -0x78(%rbp), %ecx
movl -0x74(%rbp), %r8d
movq %rax, %r9
movl -0x38(%rbp), %r10d
movl -0x34(%rbp), %eax
movl $0x5, %esi
leaq 0x897c(%rip), %rdx      # 0xd09a
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x9aa0
jmp 0x472f
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x4781
jmp 0x4747
leaq 0xeb4a(%rip), %rax      # 0x13298
movq (%rax), %rdi
movl $0x5, %esi
callq 0x3910
cmpl $0x0, %eax
je 0x477d
leaq 0xeb31(%rip), %rax      # 0x13298
movq (%rax), %rdi
movl $0x5, %esi
leaq 0x8968(%rip), %rdx      # 0xd0de
movb $0x0, %al
callq 0x9aa0
jmp 0x477f
jmp 0x4781
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4c70
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x4cb0
movq -0x18(%rbp), %rdi
callq 0x9f10
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4cd0
cmpl $0x0, %eax
jge 0x47d1
movq -0x28(%rbp), %rdi
callq 0x9f10
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x47d8
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)