// File: /workspace/github_cpp_makefile_star2_O1/sjtuwrk[P]SunwayMR/tools/SunwayMRHelper.hpp
// Function: SunwayMRHelper::SunwayMRHelper(bool)
SunwayMRHelper::SunwayMRHelper(bool forUserApp) {
	masterListenPort = 0;
	threads = 0;
	memory = 0;
	listenPort = 0;
	listening = false;
	sendResourceInfoThread = pthread_t();

	// -a mode
	if (forUserApp)
	{
		localAddr = getLocalHost();
		if (localAddr == "") {
			Logging::logError("SunwayMRHelper: failed to obtain local IP address.");
			exit(1);
		} else {
			stringstream ipinfo;
			ipinfo << "SunwayMRHelper: local IP is " << localAddr;
			Logging::logInfo(ipinfo.str());
		}

		// find master in host resource file
		masterAddr = localAddr;
		stringstream hostFilePath;
		hostFilePath << fileSaveDir << allHostsFileName;
		//read resource file
		string fileContent;
		bool rd = readFile(hostFilePath.str(), fileContent);
		if (!rd) {
			stringstream error;
			error << "SunwayMRHelper: unable to read host resource file: " << hostFilePath.str();
			Logging::logError(error.str());
			exit(1);
		}

		stringstream fileContentStream(fileContent);
		string line;
		while(std::getline(fileContentStream,line,'\n')){
			vector<string> temp = splitString(line, ' ');
			if(temp.size() < 5) continue;
			if(temp[4] == "master") {
				masterAddr = temp[0];
				break;
			}
		}
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3a8, %rsp            # imm = 0x3A8
movl %esi, %ebp
movq %rdi, %rbx
callq 0x59fe
leaq 0xafb0(%rip), %rax      # 0x12d60
movq %rax, (%rbx)
leaq 0x100(%rbx), %r15
movq %r15, 0xf0(%rbx)
xorl %eax, %eax
movq %rax, 0xf8(%rbx)
movb %al, 0x100(%rbx)
leaq 0x120(%rbx), %r13
movq %r13, 0x110(%rbx)
movq %rax, 0x118(%rbx)
movb %al, 0x120(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x140(%rbx)
movq %rax, 0x150(%rbx)
leaq 0x160(%rbx), %rcx
movl $0x0, 0x160(%rbx)
movq %rax, 0x168(%rbx)
movq %rcx, 0x170(%rbx)
movq %rcx, 0x178(%rbx)
movq %rax, 0x180(%rbx)
movb %al, 0x188(%rbx)
movq %rax, 0x190(%rbx)
movups %xmm0, 0x130(%rbx)
testl %ebp, %ebp
je 0x8144
leaq 0xf0(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x110(%rbx), %r12
leaq 0x98(%rsp), %rdi
movq %r15, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x28(%rsp)
callq 0x4351
leaq 0x98(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x3450
movq (%r14), %rdi
leaq 0xa8(%rsp), %r14
cmpq %r14, %rdi
je 0x7ea7
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x61ed(%rip), %rsi      # 0xe09b
movq 0x28(%rsp), %rdi
callq 0x3110
testl %eax, %eax
je 0x8156
leaq 0x98(%rsp), %rdi
callq 0x3240
leaq 0xa8(%rsp), %r14
leaq 0x64d4(%rip), %rsi      # 0xe3b0
movl $0x1c, %edx
movq %r14, %rdi
callq 0x3400
movq 0x110(%rbx), %rsi
movq 0x118(%rbx), %rdx
movq %r14, %rdi
callq 0x3400
leaq 0xb0(%rsp), %rsi
leaq 0x220(%rsp), %rdi
callq 0x3590
leaq 0x220(%rsp), %rdi
movq 0x28(%rsp), %r14
callq 0x56f8
leaq 0x230(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7f47
movq 0x230(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xb062(%rip), %rsi      # 0x12fb0
leaq 0x98(%rsp), %rdi
callq 0x3260
leaq 0x118(%rsp), %rdi
callq 0x3150
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x31e0
leaq 0x98(%rsp), %rdi
callq 0x3240
leaq 0xa8(%rsp), %rdi
movq 0xb46f(%rip), %rsi      # 0x13400
movq 0xb470(%rip), %rdx      # 0x13408
callq 0x3400
movq 0xb49c(%rip), %rsi      # 0x13440
movq 0xb49d(%rip), %rdx      # 0x13448
movq %rax, %rdi
callq 0x3400
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xb0(%rsp), %r12
leaq 0x78(%rsp), %rdi
movq %r12, %rsi
callq 0x3590
leaq 0x78(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x46c2
movl %eax, %ebp
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x800e
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3390
testb %bpl, %bpl
je 0x8198
leaq 0x220(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x18, %edx
callq 0x35a0
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
leaq 0x220(%rsp), %r12
movq %rsp, %r13
leaq 0x60(%rsp), %rbp
leaq 0x67ee(%rip), %r14      # 0xe848
movq %r12, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x36a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x80d0
movq %rbp, %rdi
movq %r13, %rsi
movl $0x20, %edx
callq 0x3ba5
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rax
subq %rdi, %rax
cmpq $0x81, %rax
jb 0x80ad
subq $-0x80, %rdi
movq %r14, %rsi
callq 0x3110
testl %eax, %eax
je 0x80b7
movq %rbp, %rdi
callq 0xbd14
jmp 0x805a
movq 0x60(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x31e0
leaq 0x60(%rsp), %rdi
callq 0xbd14
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x80e6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xaec3(%rip), %rsi      # 0x12fb0
leaq 0x220(%rsp), %rdi
callq 0x3260
leaq 0x2a0(%rsp), %rdi
callq 0x3150
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x8123
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xae86(%rip), %rsi      # 0x12fb0
leaq 0x98(%rsp), %rdi
callq 0x3260
leaq 0x118(%rsp), %rdi
callq 0x3150
addq $0x3a8, %rsp            # imm = 0x3A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x98(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x6215(%rip), %rsi      # 0xe37d
leaq 0x6240(%rip), %rdx      # 0xe3af
callq 0xc5c2
leaq 0x98(%rsp), %rdi
callq 0x58fc
leaq 0x98(%rsp), %rdi
callq 0x3708
movl $0x1, %edi
callq 0x3440
leaq 0x220(%rsp), %rdi
callq 0x3240
leaq 0x230(%rsp), %r14
leaq 0x6219(%rip), %rsi      # 0xe3cd
movl $0x33, %edx
movq %r14, %rdi
callq 0x3400
movq %rsp, %rdi
movq %r12, %rsi
callq 0x3590
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x3400
leaq 0x10(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x81f8
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x238(%rsp), %rsi
movq %rsp, %rdi
callq 0x3590
movq %rsp, %rdi
callq 0x58fc
movq %rsp, %rdi
jmp 0x8189
movq %rax, %r12
movq (%rsp), %rdi
cmpq %r14, %rdi
jne 0x8303
jmp 0x8310
jmp 0x824b
movq %rax, %r12
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x8303
jmp 0x8310
jmp 0x824b
movq %rax, %r12
jmp 0x8310
movq %rax, %r12
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x836e
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0x836e
movq %rax, %r12
leaq 0x60(%rsp), %rdi
callq 0xbd14
jmp 0x82fa
jmp 0x82bb
jmp 0x82e6
jmp 0x82bb
movq %rax, %r12
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8331
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0x8331
movq %rax, %r12
jmp 0x8331
jmp 0x82e6
jmp 0x82e6
movq %rax, %r12
leaq 0x230(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x834d
movq 0x230(%rsp), %rsi
jmp 0x8345
jmp 0x82f0
jmp 0x82e6
movq %rax, %r12
jmp 0x836e
jmp 0x82f0
movq %rax, %r12
jmp 0x834d
jmp 0x82f7
movq %rax, %r12
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x8310
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xac99(%rip), %rsi      # 0x12fb0
leaq 0x220(%rsp), %rdi
callq 0x3260
leaq 0x2a0(%rsp), %rdi
callq 0x3150
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x834d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xac5c(%rip), %rsi      # 0x12fb0
leaq 0x98(%rsp), %rdi
callq 0x3260
leaq 0x118(%rsp), %rdi
callq 0x3150
leaq 0x140(%rbx), %r14
leaq 0x158(%rbx), %rdi
callq 0xc4ba
movq %r14, %rdi
callq 0xc144
movq 0x28(%rsp), %rax
movq (%rax), %rdi
cmpq 0x30(%rsp), %rdi
je 0x83a8
movq 0x30(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x3390
movq 0x20(%rsp), %rax
movq (%rax), %rdi
cmpq 0x38(%rsp), %rdi
je 0x83c7
movq 0x38(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x3390
movq %rbx, %rdi
callq 0x5a88
movq %r12, %rdi
callq 0x3650
nop