// File: /workspace/github_cpp_makefile_star2_O1/sjtuwrk[P]SunwayMR/tools/SunwayMRHelper.hpp
// Function: SunwayMRHelper::messageReceived(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void SunwayMRHelper::messageReceived(int localListenPort, string fromHost, int msgType, string &msg) {
	if (localListenPort != this->listenPort || fromHost == "" || msg == "") return;

	stringstream received;
	received << "SunwayMRHelper: listening port: " << localListenPort
			<< ", message received from: " << fromHost
			<< ", message type: " << msgType
			<< ", message content: " << msg;
	Logging::logVerbose(received.str());

	switch(msgType) {
	case HOST_RESOURCE_INFO:
	{
		vector<string> ss = splitString(msg, ' ');
		if (ss.size() == 3) {
			HostResource hr = {
					fromHost,
					atoi(ss[0].c_str()),
					atoi(ss[1].c_str()),
					atoi(ss[2].c_str())
			};
			update(hr);
		}
		break;
	}

	case FILE_INFO:
	{
		vector<string> ss = splitString(msg, ' '); // msg: fileUID, appUID, fileName
		if (ss.size() == 3) {
			int file_uid = atoi(ss[0].c_str());
			fileInfoMap[file_uid] = msg;
		}
		break;
	}

	case SHELL_COMMAND:
	{
		int ret = system(msg.c_str());
		if (ret == -1) {
			stringstream error;
			error << "SunwayMRHelper:: failed to execute shell: " << endl << msg.c_str() << endl;
			Logging::logError(error.str());
		}
		break;
	}

	default:
	{
		if(fileInfoMap.find(msgType) != fileInfoMap.end()) {
			string file_info = fileInfoMap[msgType];
			vector<string> vs = splitString(file_info, ' ');
			stringstream sstr;
			sstr << fileSaveDir << vs[1] << "/";
			bool ret = writeFile(sstr.str(), vs[2], msg);
			if (!ret) {
				stringstream error;
				error << "SunwayMRHelper: unable to write file: " << sstr.str() << vs[2];
				Logging::	logError(error.str());
			}
			fileInfoMap.erase(msgType);
			Logging::logInfo("SunwayMRHelper: file received: "
					+ sstr.str() + vs[2]);
		}

	}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5a8, %rsp            # imm = 0x5A8
movl %ecx, 0x4(%rsp)
cmpl %esi, 0x13c(%rdi)
jne 0xaae2
movq %r8, %r14
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x3942(%rip), %rsi      # 0xe09b
movq %rdx, %rdi
callq 0x3110
testl %eax, %eax
je 0xaae2
leaq 0x392b(%rip), %rsi      # 0xe09b
movq %r14, %rdi
callq 0x3110
testl %eax, %eax
je 0xaae2
leaq 0x420(%rsp), %rdi
callq 0x3240
leaq 0x430(%rsp), %r12
leaq 0x3fd9(%rip), %rsi      # 0xe775
movl $0x20, %edx
movq %r12, %rdi
callq 0x3400
movq %r12, %rdi
movl %ebp, %esi
callq 0x3610
movq %rax, %r12
leaq 0x3fd9(%rip), %rsi      # 0xe796
movl $0x19, %edx
movq %rax, %rdi
callq 0x3400
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r12, %rdi
callq 0x3400
movq %rax, %r12
leaq 0x3fcd(%rip), %rsi      # 0xe7b0
movl $0x10, %edx
movq %rax, %rdi
callq 0x3400
movl 0x4(%rsp), %esi
movq %r12, %rdi
callq 0x3610
movq %rax, %r12
leaq 0x3fbb(%rip), %rsi      # 0xe7c1
movl $0x13, %edx
movq %rax, %rdi
callq 0x3400
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r12, %rdi
callq 0x3400
leaq 0x438(%rsp), %rsi
leaq 0x110(%rsp), %rdi
callq 0x3590
leaq 0x110(%rsp), %rdi
callq 0x54f4
leaq 0x120(%rsp), %r12
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0xa866
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0xa9a9
cmpl $0x1, %eax
je 0xa942
cmpl $0x2, %eax
jne 0xaaf4
movq (%r14), %rdi
callq 0x3300
cmpl $-0x1, %eax
jne 0xaac1
leaq 0x110(%rsp), %rdi
callq 0x3240
leaq 0x120(%rsp), %rbx
leaq 0x3f24(%rip), %rsi      # 0xe7d5
movl $0x2a, %edx
movq %rbx, %rdi
callq 0x3400
movq %rbx, %rdi
callq 0x31b0
movq (%r14), %rsi
movq %rax, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x31b0
leaq 0x128(%rsp), %rsi
leaq 0x298(%rsp), %rdi
callq 0x3590
leaq 0x298(%rsp), %rdi
callq 0x58fc
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa91c
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x868d(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
jmp 0xaac1
leaq 0x110(%rsp), %rdi
movq %r14, %rsi
movl $0x20, %edx
callq 0x3ba5
movq 0x110(%rsp), %rax
movq 0x118(%rsp), %rcx
subq %rax, %rcx
cmpq $0x60, %rcx
jne 0xa99c
movq (%rax), %rdi
callq 0x3580
leaq 0x298(%rsp), %rsi
movl %eax, (%rsi)
addq $0x158, %rbx            # imm = 0x158
movq %rbx, %rdi
callq 0xc1fc
movq %rax, %rdi
movq %r14, %rsi
callq 0x31e0
leaq 0x110(%rsp), %rdi
jmp 0xaabc
leaq 0x298(%rsp), %rdi
movq %r14, %rsi
movl $0x20, %edx
callq 0x3ba5
movq 0x2a0(%rsp), %rax
subq 0x298(%rsp), %rax
cmpq $0x60, %rax
jne 0xaab4
leaq 0x110(%rsp), %rdi
movq %r12, (%rdi)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
callq 0xc532
movq 0x298(%rsp), %r14
movq (%r14), %rdi
callq 0x3580
movl %eax, 0x130(%rsp)
movq 0x20(%r14), %rdi
callq 0x3580
movl %eax, 0x134(%rsp)
movq 0x40(%r14), %rdi
callq 0x3580
movl %eax, 0x138(%rsp)
leaq 0xf0(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x110(%rsp), %rsi
movq 0x118(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0xc532
leaq 0x130(%rsp), %rax
movl 0x8(%rax), %ecx
leaq 0xe0(%rsp), %rsi
movl %ecx, 0x28(%rsi)
movq (%rax), %rax
movq %rax, 0x20(%rsi)
movq %rbx, %rdi
callq 0xb13e
movq 0xe0(%rsp), %rdi
cmpq %r14, %rdi
je 0xaa97
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x110(%rsp), %rdi
cmpq %r12, %rdi
je 0xaab4
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x298(%rsp), %rdi
callq 0xbd14
movq 0x84e8(%rip), %rsi      # 0x12fb0
leaq 0x420(%rsp), %rdi
callq 0x3260
leaq 0x4a0(%rsp), %rdi
callq 0x3150
addq $0x5a8, %rsp            # imm = 0x5A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x168(%rbx), %rsi
leaq 0x160(%rbx), %rcx
movq %rcx, %rdx
testq %rsi, %rsi
je 0xab24
movq %rcx, %rdx
xorl %edi, %edi
cmpl %eax, 0x20(%rsi)
setl %dil
cmovgeq %rsi, %rdx
movq 0x10(%rsi,%rdi,8), %rsi
testq %rsi, %rsi
jne 0xab0d
movq %rcx, %rsi
cmpq %rcx, %rdx
je 0xab36
cmpl 0x20(%rdx), %eax
cmovlq %rcx, %rdx
movq %rdx, %rsi
cmpq %rcx, %rsi
je 0xaac1
addq $0x158, %rbx            # imm = 0x158
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0xc1fc
leaq 0x50(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0xc532
leaq 0x28(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x20, %edx
callq 0x3ba5
leaq 0x110(%rsp), %rdi
callq 0x3240
leaq 0x120(%rsp), %rdi
movq 0x8864(%rip), %rsi      # 0x13400
movq 0x8865(%rip), %rdx      # 0x13408
callq 0x3400
movq 0x28(%rsp), %rcx
movq 0x20(%rcx), %rsi
movq 0x28(%rcx), %rdx
movq %rax, %rdi
callq 0x3400
leaq 0x376a(%rip), %rsi      # 0xe32e
movl $0x1, %edx
movq %rax, %rdi
callq 0x3400
leaq 0x128(%rsp), %r15
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
callq 0x3590
movq 0x28(%rsp), %rax
leaq 0x90(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0xc532
leaq 0x70(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0xc532
leaq 0xc0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x45bb
movl %eax, %ebp
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0xac63
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0xac80
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaca1
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x3390
testb %bpl, %bpl
jne 0xad76
leaq 0x298(%rsp), %rdi
callq 0x3240
leaq 0x2a8(%rsp), %r14
leaq 0x3b3a(%rip), %rsi      # 0xe800
movl $0x26, %edx
movq %r14, %rdi
callq 0x3400
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x3590
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x3400
movq 0x28(%rsp), %rcx
movq 0x40(%rcx), %rsi
movq 0x48(%rcx), %rdx
movq %rax, %rdi
callq 0x3400
leaq 0x18(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0xad22
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x2b0(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x3590
leaq 0x8(%rsp), %rdi
callq 0x58fc
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xad55
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x8254(%rip), %rsi      # 0x12fb0
leaq 0x298(%rsp), %rdi
callq 0x3260
leaq 0x318(%rsp), %rdi
callq 0x3150
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0xc260
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0x3590
leaq 0x3a8d(%rip), %rsi      # 0xe827
leaq 0x8(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0xc2e4
movq 0x28(%rsp), %rdx
addq $0x40, %rdx
leaq 0x298(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xc28a
leaq 0x298(%rsp), %rdi
callq 0x56f8
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xadf5
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xae10
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xae31
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x8178(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
callq 0xbd14
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xaac1
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaac1
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
jne 0xafb4
jmp 0xafc1
jmp 0xae9b
jmp 0xae9b
movq %rax, %rbx
jmp 0xafc1
jmp 0xb0a6
movq %rax, %rbx
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb083
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xb083
jmp 0xb080
jmp 0xb112
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
cmpq %r14, %rdi
je 0xaf04
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaf04
movq %rax, %rbx
movq 0x110(%rsp), %rdi
cmpq %r12, %rdi
je 0xaf26
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaf26
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
jmp 0xb060
movq %rax, %rbx
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf5c
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaf5c
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf7c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaf7c
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb0a9
movq 0xb0(%rsp), %rsi
jmp 0xb041
jmp 0xb0a6
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xafc1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x7fe8(%rip), %rsi      # 0x12fb0
leaq 0x298(%rsp), %rdi
callq 0x3260
leaq 0x318(%rsp), %rdi
callq 0x3150
jmp 0xb0a9
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0xb006
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xb006
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0xb028
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xb028
movq %rax, %rbx
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb0a9
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xb0a9
movq %rax, %rbx
jmp 0xb0ca
movq %rax, %rbx
jmp 0xb0d4
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xbd14
jmp 0xb115
jmp 0xb112
jmp 0xb112
jmp 0xb112
jmp 0xb0a6
jmp 0xb112
movq %rax, %rbx
movq 0x7f26(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
jmp 0xb115
movq %rax, %rbx
movq 0x7f00(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
callq 0xbd14
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xb115
movq 0x50(%rsp), %rsi
jmp 0xb106
movq %rax, %rbx
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb115
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xb115
jmp 0xb112
movq %rax, %rbx
movq 0x7e94(%rip), %rsi      # 0x12fb0
leaq 0x420(%rsp), %rdi
callq 0x3260
leaq 0x4a0(%rsp), %rdi
callq 0x3150
movq %rbx, %rdi
callq 0x3650