// File: /workspace/github_cpp_makefile_star2_O2/sjtuwrk[P]SunwayMR/include/Messaging.hpp
// Function: Messaging::sendMessageForReply(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool Messaging::sendMessageForReply(string addr, int targetPort, int msgType, string &msg, string &reply)
{
	int empty_reply_time = 0;
	int empty_reply_time_max = 100;
	bool ret = false;
	while(empty_reply_time < empty_reply_time_max) {
		int sockfd = socket(AF_INET, SOCK_STREAM, 0);

		if (sockfd < 0)
		{
			Logging::logError("Messaging::sendMessageForReply: failed to initialize socket");
			return false;
		}

		if(!sendMessageInternal(sockfd, addr, targetPort, msgType, msg)) {
			return false;
		}

		// read replied data
		readSocket(sockfd, reply);

		if(reply == "") { // failed
			empty_reply_time++;
			// release socket
			close(sockfd);
			usleep(300000 + rand()%300000); // sleep & reconnect later
			continue;
		}
		if(reply == EMPTY_MESSAGE) {
			reply = "";
		}
		ret = true;
		// release socket
		close(sockfd);
		break;
	}
	if(!ret) {
		char buffer[256];
		memset(buffer, 0, sizeof(buffer));
		snprintf(buffer,
				sizeof(buffer),
				"Messaging::sendMessageForReply: failed to send after recv %d empty reply",
				empty_reply_time_max);
		string log = buffer;
		Logging::logError(log);
	}

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %r9, %rbx
movq %r8, 0x18(%rsp)
movl %ecx, 0x14(%rsp)
movl %edx, 0x10(%rsp)
movq %rsi, %r12
pushq $0x64
popq %r15
leaq 0x40(%rsp), %r13
subl $0x1, %r15d
jb 0x55d4
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x30d0
testl %eax, %eax
js 0x5624
movl %eax, %r14d
movq %r13, %rdi
movq %r12, %rsi
callq 0x3490
movl %r14d, %esi
movq %r13, %rdx
movl 0x10(%rsp), %ecx
movl 0x14(%rsp), %r8d
movq 0x18(%rsp), %r9
callq 0x5328
movl %eax, %ebp
movq %r13, %rdi
callq 0x36e8
testb %bpl, %bpl
je 0x564e
movl %r14d, %edi
movq %rbx, %rsi
callq 0x51b5
movq %rbx, %rdi
leaq 0x6af6(%rip), %rsi      # 0xc09b
callq 0x91d8
testb %al, %al
je 0x5652
movl %r14d, %edi
callq 0x36c0
callq 0x3100
cltd
movl $0x493e0, %ecx          # imm = 0x493E0
idivl %ecx
leal (%rdx,%rcx), %edi
callq 0x34a0
jmp 0x5537
leaq 0x60(%rsp), %rbx
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31f0
leaq 0x6bde(%rip), %rdx      # 0xc1cd
pushq $0x64
popq %rcx
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3580
leaq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %rbx, %rsi
callq 0x915a
leaq 0x20(%rsp), %rdi
callq 0x4efc
leaq 0x20(%rsp), %rdi
jmp 0x5649
leaq 0x6b56(%rip), %rsi      # 0xc181
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x915a
leaq 0x60(%rsp), %rdi
callq 0x4efc
leaq 0x60(%rsp), %rdi
callq 0x36e8
xorl %eax, %eax
jmp 0x567e
leaq 0x6b64(%rip), %rsi      # 0xc1bd
movq %rbx, %rdi
callq 0x91d8
testb %al, %al
je 0x5674
leaq 0x6a2f(%rip), %rsi      # 0xc09b
movq %rbx, %rdi
callq 0x36a0
movl %r14d, %edi
callq 0x36c0
movb $0x1, %al
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x56b3
jmp 0x56a6
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x56b3
movq %rax, %rbx
jmp 0x56b8
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x36e8
movq %rbx, %rdi
callq 0x3610