// File: huanghuide[P]SimpleNetworkTunnel/OuterRunner.cpp
// Function: OuterRunner::SendPendingMsg()
void OuterRunner::SendPendingMsg()
{
    if (mSendStatus == INIT)
    {
        ProcessInitStatus();
    }
    else if (mSendStatus == ESTABLISHED)
    {
        for (int index = 0; index < mSendMsg.size(); index++)
        {
        	char* msgPos = ((char*)(mSendMsg[index].c_str()));
        	int msgLen = mSendMsg[index].length();

        	char* msgBuf = new char[msgLen + 1];

        	memset(msgBuf, 0, msgLen + 1);
        	memcpy(msgBuf, msgPos, msgLen);

            //printf("Sending message to the remote server. SockFd %d, msgLen %d\n", mSockFd, msgLen);
            //PrintBuf(msgBuf, msgLen);

        	if ((gRoleType == MIDDLE) || (gRoleType == CLIENT))
        	{
        		for (int index = 0; index < msgLen; index++)
        		{
        			msgBuf[index] = msgBuf[index] ^ SIMPLE_XOR_VALUE;
        		}
        	}

            int sendBytes = SockSendPacket(mSockFd, msgBuf, msgLen);
                        
            if (sendBytes != mSendMsg[index].length())
            {
            	delete [] msgBuf;
                HandleError();

                return;
            }

            delete [] msgBuf;
        }

        mSendMsg.clear();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, 0x30(%rax)
jne 0x7578
movq -0x38(%rbp), %rdi
callq 0x77e0
jmp 0x770f
movq -0x38(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x770d
movl $0x0, -0xc(%rbp)
movq -0x38(%rbp), %rdi
movslq -0xc(%rbp), %rax
movq %rax, -0x40(%rbp)
addq $0x10, %rdi
callq 0x5750
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jae 0x7700
movq -0x38(%rbp), %rdi
addq $0x10, %rdi
movslq -0xc(%rbp), %rsi
callq 0x5770
movq %rax, %rdi
callq 0x3160
movq -0x38(%rbp), %rdi
movq %rax, -0x18(%rbp)
addq $0x10, %rdi
movslq -0xc(%rbp), %rsi
callq 0x5770
movq %rax, %rdi
callq 0x3490
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3030
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x31c0
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x32a0
leaq 0x8c77(%rip), %rax      # 0x102a0
cmpl $0x1, (%rax)
je 0x763a
leaq 0x8c6b(%rip), %rax      # 0x102a0
cmpl $0x0, (%rax)
jne 0x7674
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7672
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
xorl $0xa5, %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x7641
jmp 0x7674
movq -0x38(%rbp), %rax
movl 0xc(%rax), %edi
movq -0x28(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x3c00
movq -0x38(%rbp), %rdi
movl %eax, -0x30(%rbp)
movslq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
addq $0x10, %rdi
movslq -0xc(%rbp), %rsi
callq 0x5770
movq %rax, %rdi
callq 0x3490
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
je 0x76d9
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x76ce
movq -0x50(%rbp), %rdi
callq 0x3440
movq -0x38(%rbp), %rdi
callq 0x73b0
jmp 0x770f
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x76f0
movq -0x58(%rbp), %rdi
callq 0x3440
jmp 0x76f2
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x758d
movq -0x38(%rbp), %rdi
addq $0x10, %rdi
callq 0x5790
jmp 0x770f
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)