// File: /workspace/github_cpp_makefile_star2_O1/tmtxt[P]microcontroller-emulation/main.cpp
// Function: optionModifyMemoryHandler(mcontroller::Microcontroller**)
void optionModifyMemoryHandler(mcontroller::Microcontroller** microcontroller){

	// display the message for user
	cout << "Message: Modify memory." << endl;
	cout << "Message: Enter the memory location to modify (hexadeciaml format)." << endl;
	
	// The input memory address
	int location;

	// input address from user
	location = (*microcontroller)->lookUpMemoryAddress();

	// check if the location is valid
	if(location != Microcontroller::memoryLocationInvalid){
		// print the old value
		unsigned int oldValue = (*microcontroller)->getMemoryValueAtLocation(location);
		cout << "Message: Old value: ";
		cout << hex << oldValue;
		cout << endl;

		// print the message
		cout << "Message: Enter the new value (hexadecimal format)." << endl;
		cout << "new? ";

		// read the input value from user
		unsigned int inputNewValue;
		// validate input
		while(!(cin >> hex >> inputNewValue)){
			cerr << "Error: Please input a valid hexadecimal integer!" << endl;
			cin.clear();
			cin.ignore(1000, '\n');
			cout << "news? ";
		}

		// As each memory location is a byte size (unsigned char), only the
		// lower 8 bits of input should be stored.
		unsigned char newValue = (inputNewValue & 0xFF);
		(*microcontroller)->setMemoryValueAtLocation(location, newValue);

		// clear the cin
		cin.clear();
		cin.ignore(1000, '\n');
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x8147(%rip), %r14      # 0xafc8
leaq 0x44b0(%rip), %rsi      # 0x7338
movl $0x17, %edx
movq %r14, %rdi
callq 0x2190
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
leaq 0x448d(%rip), %rsi      # 0x7350
movl $0x42, %edx
movq %r14, %rdi
callq 0x2190
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rdi
callq 0x376a
cmpl $-0x1, %eax
je 0x30fe
movq %rbx, 0x10(%rsp)
movq (%rbx), %rdi
movl %eax, 0xc(%rsp)
movl %eax, %esi
callq 0x3740
movl %eax, %ebx
leaq 0x446f(%rip), %rsi      # 0x7393
movl $0x14, %edx
movq %r14, %rdi
callq 0x2190
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r14,%rax)
movzbl %bl, %esi
movq %r14, %rdi
callq 0x20d0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
leaq 0x4427(%rip), %rsi      # 0x73a8
movl $0x32, %edx
movq %r14, %rdi
callq 0x2190
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
leaq 0x441f(%rip), %rsi      # 0x73db
movl $0x5, %edx
movq %r14, %rdi
callq 0x2190
movq 0x8008(%rip), %r14      # 0xafd8
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r14,%rax)
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x2240
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x30c5
movq 0x7fe3(%rip), %r15      # 0xaff0
leaq 0x43cd(%rip), %r12      # 0x73e1
movq 0x7fad(%rip), %r13      # 0xafc8
leaq 0x43f0(%rip), %rbx      # 0x7412
leaq 0x8(%rsp), %rbp
movl $0x30, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2190
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x2220
movl $0x3e8, %esi            # imm = 0x3E8
movq %r14, %rdi
movl $0xa, %edx
callq 0x20c0
movl $0x6, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2190
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r14,%rax)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2240
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3027
movzbl 0x8(%rsp), %edx
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movl 0xc(%rsp), %esi
callq 0x3756
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x2220
movl $0x3e8, %esi            # imm = 0x3E8
movq %r14, %rdi
movl $0xa, %edx
callq 0x20c0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq