// File: /workspace/github_cpp_makefile_star2_O3/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 0x59ee
leaq 0xb07e(%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 0x8076
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 0x4357
leaq 0x98(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x3450
movq (%r14), %rdi
leaq 0xa8(%rsp), %r14
cmpq %r14, %rdi
je 0x7dd9
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x62eb(%rip), %rsi      # 0xe0cb
movq 0x28(%rsp), %rdi
callq 0x3110
testl %eax, %eax
je 0x8088
leaq 0x98(%rsp), %rdi
callq 0x3240
leaq 0xa8(%rsp), %r14
leaq 0x65d2(%rip), %rsi      # 0xe3e0
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 0x3580
leaq 0x220(%rsp), %rdi
movq 0x28(%rsp), %r14
callq 0x56e8
leaq 0x230(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7e79
movq 0x230(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xb130(%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 0xb535(%rip), %rsi      # 0x133f8
movq 0xb536(%rip), %rdx      # 0x13400
callq 0x3400
movq 0xb562(%rip), %rsi      # 0x13438
movq 0xb563(%rip), %rdx      # 0x13440
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 0x3580
leaq 0x78(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x46c8
movl %eax, %ebp
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7f40
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3390
testb %bpl, %bpl
je 0x80ca
leaq 0x220(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x18, %edx
callq 0x3590
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 0x68ec(%rip), %r14      # 0xe878
movq %r12, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x3690
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x8002
movq %rbp, %rdi
movq %r13, %rsi
movl $0x20, %edx
callq 0x3b95
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rax
subq %rdi, %rax
cmpq $0x81, %rax
jb 0x7fdf
subq $-0x80, %rdi
movq %r14, %rsi
callq 0x3110
testl %eax, %eax
je 0x7fe9
movq %rbp, %rdi
callq 0xbc26
jmp 0x7f8c
movq 0x60(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x31e0
leaq 0x60(%rsp), %rdi
callq 0xbc26
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x8018
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xaf91(%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 0x8055
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xaf54(%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 0x6313(%rip), %rsi      # 0xe3ad
leaq 0x633e(%rip), %rdx      # 0xe3df
callq 0xc5ec
leaq 0x98(%rsp), %rdi
callq 0x58ec
leaq 0x98(%rsp), %rdi
callq 0x36f8
movl $0x1, %edi
callq 0x3440
leaq 0x220(%rsp), %rdi
callq 0x3240
leaq 0x230(%rsp), %r14
leaq 0x6317(%rip), %rsi      # 0xe3fd
movl $0x33, %edx
movq %r14, %rdi
callq 0x3400
movq %rsp, %rdi
movq %r12, %rsi
callq 0x3580
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x3400
leaq 0x10(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x812a
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3390
leaq 0x238(%rsp), %rsi
movq %rsp, %rdi
callq 0x3580
movq %rsp, %rdi
callq 0x58ec
movq %rsp, %rdi
jmp 0x80bb
movq %rax, %r12
movq (%rsp), %rdi
cmpq %r14, %rdi
jne 0x8235
jmp 0x8242
jmp 0x817d
movq %rax, %r12
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x8235
jmp 0x8242
jmp 0x817d
movq %rax, %r12
jmp 0x8242
movq %rax, %r12
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x82a0
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0x82a0
movq %rax, %r12
leaq 0x60(%rsp), %rdi
callq 0xbc26
jmp 0x822c
jmp 0x81ed
jmp 0x8218
jmp 0x81ed
movq %rax, %r12
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8263
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0x8263
movq %rax, %r12
jmp 0x8263
jmp 0x8218
jmp 0x8218
movq %rax, %r12
leaq 0x230(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x827f
movq 0x230(%rsp), %rsi
jmp 0x8277
jmp 0x8222
jmp 0x8218
movq %rax, %r12
jmp 0x82a0
jmp 0x8222
movq %rax, %r12
jmp 0x827f
jmp 0x8229
movq %rax, %r12
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x8242
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xad67(%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 0x827f
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xad2a(%rip), %rsi      # 0x12fb0
leaq 0x98(%rsp), %rdi
callq 0x3260
leaq 0x118(%rsp), %rdi
callq 0x3150
leaq 0x140(%rbx), %r14
leaq 0x158(%rbx), %rdi
callq 0xc4de
movq %r14, %rdi
callq 0xc164
movq 0x28(%rsp), %rax
movq (%rax), %rdi
cmpq 0x30(%rsp), %rdi
je 0x82da
movq 0x30(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x3390
movq 0x20(%rsp), %rax
movq (%rax), %rdi
cmpq 0x38(%rsp), %rdi
je 0x82f9
movq 0x38(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x3390
movq %rbx, %rdi
callq 0x5a78
movq %r12, %rdi
callq 0x3640
nop