// File: /workspace/github_cpp_makefile_star2_O2/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 $0x398, %rsp            # imm = 0x398
movl %esi, %ebp
movq %rdi, %rbx
callq 0x4f9c
leaq 0xb520(%rip), %rax      # 0x11d70
movq %rax, (%rbx)
leaq 0x100(%rbx), %rax
movq %rax, 0xf0(%rbx)
andq $0x0, 0xf8(%rbx)
xorl %eax, %eax
movb %al, 0x100(%rbx)
leaq 0x120(%rbx), %rcx
movq %rcx, 0x110(%rbx)
andq $0x0, 0x118(%rbx)
movb %al, 0x120(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x140(%rbx)
andq $0x0, 0x150(%rbx)
leaq 0x160(%rbx), %rcx
andl $0x0, 0x160(%rbx)
andq $0x0, 0x168(%rbx)
movq %rcx, 0x170(%rbx)
movq %rcx, 0x178(%rbx)
andq $0x0, 0x180(%rbx)
movb %al, 0x188(%rbx)
andq $0x0, 0x190(%rbx)
movups %xmm0, 0x130(%rbx)
testl %ebp, %ebp
je 0x6b0c
leaq 0xf0(%rbx), %r15
leaq 0x110(%rbx), %r13
leaq 0x88(%rsp), %rdi
movq %r15, (%rsp)
movq %r13, 0x28(%rsp)
callq 0x3ff4
leaq 0x88(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x3410
movq %r14, %rdi
callq 0x36e8
leaq 0x576d(%rip), %rsi      # 0xc09b
movq %r13, %rdi
callq 0x91d8
testb %al, %al
jne 0x6b1e
leaq 0x88(%rsp), %rdi
callq 0x3230
leaq 0x98(%rsp), %rdi
leaq 0x5a56(%rip), %rsi      # 0xc3b0
callq 0x3360
movq %rax, %rdi
movq %r13, %rsi
callq 0x3300
leaq 0xa0(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x3550
leaq 0x210(%rsp), %rdi
callq 0x4dbc
leaq 0x210(%rsp), %rdi
callq 0x36e8
leaq 0x88(%rsp), %rdi
callq 0x3260
movq %r15, %rdi
movq %r13, %rsi
callq 0x31e0
leaq 0x88(%rsp), %rdi
callq 0x3230
leaq 0x98(%rsp), %rdi
leaq 0xba23(%rip), %rsi      # 0x123f0
callq 0x3300
leaq 0xba57(%rip), %rsi      # 0x12430
movq %rax, %rdi
callq 0x3300
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xa0(%rsp), %r12
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x3550
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x4295
movl %eax, %ebp
leaq 0x68(%rsp), %rdi
callq 0x36e8
testb %bpl, %bpl
je 0x6b5c
leaq 0x210(%rsp), %rdi
leaq 0x48(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x3560
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x210(%rsp), %r12
leaq 0x8(%rsp), %r13
pushq $0xa
popq %rbp
leaq 0x30(%rsp), %r14
pushq $0x20
popq %r15
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x3660
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x6ade
movq %r14, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x3a53
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
subq %rdi, %rax
cmpq $0x81, %rax
jb 0x6abc
subq $-0x80, %rdi
leaq 0x5d95(%rip), %rsi      # 0xc848
callq 0x91d8
testb %al, %al
jne 0x6ac6
movq %r14, %rdi
callq 0x904e
jmp 0x6a6a
movq 0x30(%rsp), %rsi
movq (%rsp), %rdi
callq 0x31e0
leaq 0x30(%rsp), %rdi
callq 0x904e
leaq 0x8(%rsp), %rdi
callq 0x36e8
leaq 0x210(%rsp), %rdi
callq 0x3260
leaq 0x48(%rsp), %rdi
callq 0x36e8
leaq 0x88(%rsp), %rdi
callq 0x3260
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5858(%rip), %rsi      # 0xc37d
leaq 0x88(%rsp), %rdi
leaq 0x210(%rsp), %rdx
callq 0x915a
leaq 0x88(%rsp), %rdi
callq 0x4efc
leaq 0x88(%rsp), %rdi
callq 0x36e8
pushq $0x1
popq %rdi
callq 0x3400
leaq 0x210(%rsp), %rdi
callq 0x3230
leaq 0x220(%rsp), %rdi
leaq 0x5855(%rip), %rsi      # 0xc3cd
callq 0x3360
movq %rax, %r14
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x3550
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3300
leaq 0x8(%rsp), %rdi
callq 0x36e8
leaq 0x228(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x3550
leaq 0x8(%rsp), %rdi
callq 0x4efc
leaq 0x8(%rsp), %rdi
jmp 0x6b4f
jmp 0x6c32
jmp 0x6bcf
jmp 0x6c32
jmp 0x6bcf
movq %rax, %r12
jmp 0x6c3f
movq %rax, %r12
leaq 0x88(%rsp), %rdi
callq 0x36e8
jmp 0x6c63
movq %rax, %r12
leaq 0x30(%rsp), %rdi
callq 0x904e
jmp 0x6c35
jmp 0x6c0a
jmp 0x6c24
jmp 0x6c0a
movq %rax, %r12
leaq 0x68(%rsp), %rdi
callq 0x36e8
jmp 0x6c4c
movq %rax, %r12
jmp 0x6c4c
jmp 0x6c24
jmp 0x6c24
movq %rax, %r12
leaq 0x210(%rsp), %rdi
jmp 0x6c51
jmp 0x6c2b
jmp 0x6c24
movq %rax, %r12
jmp 0x6c63
jmp 0x6c2b
movq %rax, %r12
jmp 0x6c56
jmp 0x6c32
movq %rax, %r12
leaq 0x8(%rsp), %rdi
callq 0x36e8
leaq 0x210(%rsp), %rdi
callq 0x3260
leaq 0x48(%rsp), %rdi
callq 0x36e8
leaq 0x88(%rsp), %rdi
callq 0x3260
leaq 0x140(%rbx), %r14
leaq 0x158(%rbx), %rdi
callq 0x9666
movq %r14, %rdi
callq 0x940e
movq 0x28(%rsp), %rdi
callq 0x36e8
movq (%rsp), %rdi
callq 0x36e8
movq %rbx, %rdi
callq 0x502e
movq %r12, %rdi
callq 0x3610
nop