// File: /workspace/github_cpp_makefile_star2_O1/williewillus[P]panda_scratchpad/src/communication/ClientSocket.cpp
// Function: communication::ClientSocket::SendCommand(communication::SockMessage const&)
SockError ClientSocket::SendCommand(const SockMessage& msg) {
	SockError err = eNone;
	
	// First check if the client is connected
	if ( sockfd < 0 ) {
		cout << "Client not connected" << endl;
		err = eNotConnected;
		return err;
	}
	
	// Get the command and the arguments
	QemuCommand cmd = msg.q_cmd;
	CommandOpts options = *(msg.q_cmd_options);

	// Based on the command, build the actual message now
	string complete_command;
	bool isCustomStart = false;
	switch(cmd) {
		case cListPlugins : 
			complete_command = "list_plugins";
			break;
		case cLoadPlugin : 
			complete_command = "load_plugin ";
			// Let's see how to handle the available plugins
			switch(options.plugin_name) {
				case pWritetracker:
					complete_command += "writetracker";
					if (! options.start.empty()) {
						complete_command += " start=";
						complete_command += options.start;
						isCustomStart = true;
					}

					if (! options.end.empty()) {
						if (isCustomStart)
							complete_command += ",";
						complete_command += "end=";
						complete_command += options.end;
					}
					break;
				case pReplay:
					complete_command += "replayer";
					if (! options.start.empty()) {
						complete_command += " base=";
						complete_command += options.start;
					}
					break;
				default:
					cout << "Undefined Plugin" << endl;
					return eOther;
			}
			break;
		case cUnloadPlugin : 
			complete_command = "unload_plugin ";
			complete_command += to_string(options.id);
			break;
		default :
			cout << "Undefined qemu command" << endl;
			return eOther;
	}

	// The command doesn't execute at the monitor without a newline
	complete_command += "\n";
	cout << "Command being sent is : " << complete_command << endl;
	if ( send( sockfd, complete_command.c_str(), complete_command.length(), 0) < 0) {
		err = eOther;
		return err;
	}
	return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
cmpl $0x0, (%rdi)
js 0x841e
movq %rdi, %rbx
movl (%rsi), %r12d
movq 0x8(%rsi), %r13
movl (%r13), %eax
leaq -0x90(%rbp), %r15
movl %eax, -0x8(%r15)
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x8052
leaq -0x70(%rbp), %r14
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x28(%r13), %rsi
movq 0x30(%r13), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x8052
movl 0x48(%r13), %eax
movl %eax, -0x50(%rbp)
leaq -0x38(%rbp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
cmpl $0x2, %r12d
je 0x8514
cmpl $0x1, %r12d
je 0x8467
testl %r12d, %r12d
jne 0x858e
leaq 0xc127(%rip), %rcx      # 0x1452d
leaq -0x48(%rbp), %rdi
movl $0xc, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x56b0
jmp 0x8697
movq 0x13ba3(%rip), %rbx     # 0x1bfc8
leaq 0xc0ec(%rip), %rsi      # 0x14518
movl $0x14, %edx
movq %rbx, %rdi
callq 0x54f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x5470
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5300
xorl %ebx, %ebx
jmp 0x874d
leaq 0xc10b(%rip), %rcx      # 0x14579
leaq -0x48(%rbp), %rdi
movl $0xc, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x56b0
movl -0x98(%rbp), %eax
cmpl $0x1, %eax
je 0x859c
testl %eax, %eax
jne 0x85e8
leaq 0xc09b(%rip), %rsi      # 0x1453a
leaq -0x48(%rbp), %rdi
callq 0x5860
movq -0x88(%rbp), %r15
testq %r15, %r15
je 0x84db
leaq 0xc08c(%rip), %rsi      # 0x14547
leaq -0x48(%rbp), %rdi
callq 0x5860
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x5160
cmpq $0x0, -0x68(%rbp)
je 0x8697
testq %r15, %r15
je 0x84fb
leaq 0xc05d(%rip), %rsi      # 0x1454f
leaq -0x48(%rbp), %rdi
callq 0x5860
leaq 0xc04f(%rip), %rsi      # 0x14551
leaq -0x48(%rbp), %rdi
callq 0x5860
leaq -0x68(%rbp), %rax
jmp 0x85d4
leaq 0xc05c(%rip), %rcx      # 0x14577
leaq -0x48(%rbp), %rdi
movl $0xe, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x56b0
movl -0x50(%rbp), %r14d
movl $0x1, %eax
cmpl $0xa, %r14d
jb 0x863f
movl $0x4, %eax
movl $0xd1b71759, %ecx       # imm = 0xD1B71759
movl %r14d, %edx
cmpl $0x63, %edx
jbe 0x8638
cmpl $0x3e7, %edx            # imm = 0x3E7
jbe 0x863d
cmpl $0x2710, %edx           # imm = 0x2710
jb 0x863f
movl %edx, %esi
imulq %rcx, %rsi
shrq $0x2d, %rsi
addl $0x4, %eax
cmpl $0x1869f, %edx          # imm = 0x1869F
movl %esi, %edx
ja 0x854e
addl $-0x3, %eax
jmp 0x863f
movl $0x16, %edx
leaq 0xbfec(%rip), %rsi      # 0x14586
jmp 0x85f4
leaq 0xbfb3(%rip), %rsi      # 0x14556
leaq -0x48(%rbp), %rdi
callq 0x5860
cmpq $0x0, -0x88(%rbp)
je 0x8697
leaq 0xbf9e(%rip), %rsi      # 0x1455f
leaq -0x48(%rbp), %rdi
callq 0x5860
leaq -0x88(%rbp), %rax
movq %r15, %r14
movq (%r14), %rsi
movq (%rax), %rdx
leaq -0x48(%rbp), %rdi
callq 0x5160
jmp 0x8697
movl $0x10, %edx
leaq 0xbf72(%rip), %rsi      # 0x14566
movq 0x139cd(%rip), %rbx     # 0x1bfc8
movq %rbx, %rdi
callq 0x54f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x5470
movsbl %al, %esi
movq 0x139a7(%rip), %rdi     # 0x1bfc8
callq 0x5040
movl $0x2, %ebx
movq %rax, %rdi
callq 0x5300
jmp 0x8718
addl $-0x2, %eax
jmp 0x863f
decl %eax
movl %eax, %esi
leaq -0xa8(%rbp), %r15
movq %r15, -0x10(%r15)
leaq -0xb8(%rbp), %rdi
xorl %edx, %edx
callq 0x5510
movq -0xb8(%rbp), %rdi
movl -0xb0(%rbp), %esi
movl %r14d, %edx
callq 0x8896
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x5160
movq -0xb8(%rbp), %rdi
cmpq %r15, %rdi
je 0x8697
callq 0x5460
leaq 0xba6d(%rip), %rsi      # 0x1410b
leaq -0x48(%rbp), %rdi
callq 0x5860
movq 0x1391a(%rip), %rdi     # 0x1bfc8
leaq 0xbee8(%rip), %rsi      # 0x1459d
movl $0x18, %edx
callq 0x54f0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x138fa(%rip), %rdi     # 0x1bfc8
callq 0x54f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5470
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5300
movl (%rbx), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x5240
movq %rax, %rbx
shrq $0x3f, %rbx
xorl $0x3, %ebx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x8726
callq 0x5460
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x8738
callq 0x5460
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x874d
callq 0x5460
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
cmpq %r15, %rdi
je 0x8796
callq 0x5460
jmp 0x8796
jmp 0x8793
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x87b0
callq 0x5460
jmp 0x87b0
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x87a4
callq 0x5460
leaq -0x98(%rbp), %rdi
callq 0x8860
movq %rbx, %rdi
callq 0x57c0