// File: /workspace/github_cpp_makefile_star2_O3/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 0xaa16
movq %r8, %rbx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
leaq 0x3a3e(%rip), %rsi      # 0xe0cb
movq %rdx, %rdi
callq 0x3110
testl %eax, %eax
je 0xaa16
leaq 0x3a27(%rip), %rsi      # 0xe0cb
movq %rbx, %rdi
callq 0x3110
testl %eax, %eax
je 0xaa16
leaq 0x420(%rsp), %rdi
callq 0x3240
leaq 0x430(%rsp), %r12
leaq 0x40d5(%rip), %rsi      # 0xe7a5
movl $0x20, %edx
movq %r12, %rdi
callq 0x3400
movq %r12, %rdi
movl %ebp, %esi
callq 0x3600
movq %rax, %r12
leaq 0x40d5(%rip), %rsi      # 0xe7c6
movl $0x19, %edx
movq %rax, %rdi
callq 0x3400
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r12, %rdi
callq 0x3400
movq %rax, %r12
leaq 0x40c9(%rip), %rsi      # 0xe7e0
movl $0x10, %edx
movq %rax, %rdi
callq 0x3400
movl 0x4(%rsp), %esi
movq %r12, %rdi
callq 0x3600
movq %rax, %r12
leaq 0x40b7(%rip), %rsi      # 0xe7f1
movl $0x13, %edx
movq %rax, %rdi
callq 0x3400
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r12, %rdi
callq 0x3400
leaq 0x438(%rsp), %rsi
leaq 0x110(%rsp), %rdi
callq 0x3580
leaq 0x110(%rsp), %rdi
callq 0x54e4
leaq 0x120(%rsp), %r12
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0xa79a
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0xa8dd
cmpl $0x1, %eax
je 0xa876
cmpl $0x2, %eax
jne 0xaa28
movq (%rbx), %rdi
callq 0x3300
cmpl $-0x1, %eax
jne 0xa9f5
leaq 0x110(%rsp), %rdi
callq 0x3240
leaq 0x120(%rsp), %r14
leaq 0x4020(%rip), %rsi      # 0xe805
movl $0x2a, %edx
movq %r14, %rdi
callq 0x3400
movq %r14, %rdi
callq 0x31b0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x31b0
leaq 0x128(%rsp), %rsi
leaq 0x298(%rsp), %rdi
callq 0x3580
leaq 0x298(%rsp), %rdi
callq 0x58ec
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa850
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x8759(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
jmp 0xa9f5
leaq 0x110(%rsp), %rdi
movq %rbx, %rsi
movl $0x20, %edx
callq 0x3b95
movq 0x110(%rsp), %rax
movq 0x118(%rsp), %rcx
subq %rax, %rcx
cmpq $0x60, %rcx
jne 0xa8d0
movq (%rax), %rdi
callq 0x3570
leaq 0x298(%rsp), %rsi
movl %eax, (%rsi)
addq $0x158, %r15            # imm = 0x158
movq %r15, %rdi
callq 0xc21e
movq %rax, %rdi
movq %rbx, %rsi
callq 0x31e0
leaq 0x110(%rsp), %rdi
jmp 0xa9f0
leaq 0x298(%rsp), %rdi
movq %rbx, %rsi
movl $0x20, %edx
callq 0x3b95
movq 0x2a0(%rsp), %rax
subq 0x298(%rsp), %rax
cmpq $0x60, %rax
jne 0xa9e8
leaq 0x110(%rsp), %rdi
movq %r12, (%rdi)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
callq 0xc556
movq 0x298(%rsp), %rbx
movq (%rbx), %rdi
callq 0x3570
movl %eax, 0x130(%rsp)
movq 0x20(%rbx), %rdi
callq 0x3570
movl %eax, 0x134(%rsp)
movq 0x40(%rbx), %rdi
callq 0x3570
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 0xc556
leaq 0x130(%rsp), %rax
movl 0x8(%rax), %ecx
leaq 0xe0(%rsp), %rsi
movl %ecx, 0x28(%rsi)
movq (%rax), %rax
movq %rax, 0x20(%rsi)
movq %r15, %rdi
callq 0xb056
movq 0xe0(%rsp), %rdi
cmpq %r14, %rdi
je 0xa9cb
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x110(%rsp), %rdi
cmpq %r12, %rdi
je 0xa9e8
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x298(%rsp), %rdi
callq 0xbc26
movq 0x85b4(%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(%r15), %rcx
testq %rcx, %rcx
je 0xa9f5
leaq 0x158(%r15), %r14
addq $0x160, %r15            # imm = 0x160
movq %r15, %rdx
xorl %esi, %esi
cmpl %eax, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rdx
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0xaa45
cmpq %r15, %rdx
je 0xa9f5
cmpl 0x20(%rdx), %eax
jl 0xa9f5
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0xc21e
leaq 0x90(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0xc556
leaq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movl $0x20, %edx
callq 0x3b95
leaq 0x110(%rsp), %rdi
callq 0x3240
leaq 0x120(%rsp), %rdi
movq 0x892e(%rip), %rsi      # 0x133f8
movq 0x892f(%rip), %rdx      # 0x13400
callq 0x3400
movq 0x28(%rsp), %rcx
movq 0x20(%rcx), %rsi
movq 0x28(%rcx), %rdx
movq %rax, %rdi
callq 0x3400
leaq 0x386c(%rip), %rsi      # 0xe35e
movl $0x1, %edx
movq %rax, %rdi
callq 0x3400
leaq 0x128(%rsp), %r15
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
callq 0x3580
movq 0x28(%rsp), %rax
leaq 0x70(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0xc556
leaq 0x50(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0xc556
leaq 0xc0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x45c1
movl %eax, %ebx
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xab87
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0xab9e
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xabbf
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x3390
testb %bl, %bl
jne 0xac93
leaq 0x298(%rsp), %rdi
callq 0x3240
leaq 0x2a8(%rsp), %rbx
leaq 0x3c4d(%rip), %rsi      # 0xe830
movl $0x26, %edx
movq %rbx, %rdi
callq 0x3400
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x3580
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x3400
movq 0x28(%rsp), %rcx
movq 0x40(%rcx), %rsi
movq 0x48(%rcx), %rdx
movq %rax, %rdi
callq 0x3400
leaq 0x18(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0xac3f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x2b0(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x3580
leaq 0x8(%rsp), %rdi
callq 0x58ec
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0xac72
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x8337(%rip), %rsi      # 0x12fb0
leaq 0x298(%rsp), %rdi
callq 0x3260
leaq 0x318(%rsp), %rdi
callq 0x3150
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0xc284
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0x3580
leaq 0x3ba0(%rip), %rsi      # 0xe857
leaq 0x8(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0xc308
movq 0x28(%rsp), %rdx
addq $0x40, %rdx
leaq 0x298(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xc2ae
leaq 0x298(%rsp), %rdi
callq 0x56e8
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xad12
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xad2d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xad4e
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x825b(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
callq 0xbc26
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0xa9f5
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xa9f5
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
jne 0xae47
jmp 0xae54
jmp 0xadb9
jmp 0xadb9
movq %rax, %rbx
jmp 0xae54
jmp 0xaf7e
movq %rax, %rbx
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xadef
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xadef
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xae0f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xae0f
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf81
movq 0xb0(%rsp), %rsi
jmp 0xaed2
jmp 0xaf7e
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xae54
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x8155(%rip), %rsi      # 0x12fb0
leaq 0x298(%rsp), %rdi
callq 0x3260
leaq 0x318(%rsp), %rdi
callq 0x3150
jmp 0xaf81
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xae99
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xae99
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0xaeb5
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaeb5
movq %rax, %rbx
leaq 0xd0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf81
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaf81
movq %rax, %rbx
jmp 0xafa2
movq %rax, %rbx
jmp 0xafac
movq %rax, %rbx
leaq 0x2a8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xafde
movq 0x2a8(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xafde
jmp 0xafdb
jmp 0xb029
jmp 0xaf7e
jmp 0xb029
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
cmpq %r14, %rdi
je 0xaf52
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaf52
movq %rax, %rbx
movq 0x110(%rsp), %rdi
cmpq %r12, %rdi
je 0xaf74
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xaf74
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
jmp 0xafce
movq %rax, %rbx
movq 0x8028(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
callq 0xbc26
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0xb02c
movq 0x90(%rsp), %rsi
jmp 0xb01d
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xbc26
jmp 0xb02c
jmp 0xb029
jmp 0xb029
jmp 0xb029
movq %rax, %rbx
movq 0x7fcb(%rip), %rsi      # 0x12fb0
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x190(%rsp), %rdi
callq 0x3150
jmp 0xb02c
movq %rax, %rbx
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb02c
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0xb02c
jmp 0xb029
movq %rax, %rbx
movq 0x7f7d(%rip), %rsi      # 0x12fb0
leaq 0x420(%rsp), %rdi
callq 0x3260
leaq 0x4a0(%rsp), %rdi
callq 0x3150
movq %rbx, %rdi
callq 0x3640
nop