// File: /workspace/github_cpp_makefile_star2_O1/martinferianc[P]CPUSimulator-EIE2/src/mips_cpu_execute.cpp
// Function: mips_execute_R(mips_cpu_impl*, unsigned int&, unsigned int&, unsigned int const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, unsigned int&, unsigned int&)
mips_error mips_execute_R(mips_cpu_h state, uint32_t& hi, uint32_t& lo, const uint32_t* instruction_data, string& instruction, uint32_t& pcN, uint32_t& pc){
	uint32_t source1 = instruction_data[1];
	uint32_t source2 = instruction_data[2];
	uint32_t destination = instruction_data[3];
	uint32_t shift = instruction_data[4];
	uint32_t function = instruction_data[5];

	switch(function){
		case 0b100001:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data,"ADDU", instruction, pcN, pc);
		break;
		case 0b100101:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data,"OR", instruction, pcN, pc);
		break;
		case 0b100100:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "AND", instruction, pcN, pc);
		break;
		case 0b100110:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "XOR", instruction, pcN, pc);
		break;
		case 0b100011:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SUBU", instruction, pcN, pc);
		break;
		case 0b100010:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SUB", instruction, pcN, pc);
		break;
		case 0b100000:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "ADD", instruction, pcN, pc);
		break;
		case 0b000010:
		if ((source1==0) && (shift<=31))
			return mips_execute_R_X(state, hi, lo, instruction_data, "SRL", instruction, pcN, pc);
		break;
		case 0b000011:
		if ((source1==0) && (shift<=31))
			return mips_execute_R_X(state, hi, lo, instruction_data, "SRA", instruction, pcN, pc);
		break;
		case 0b000111:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SRAV", instruction,pcN, pc);
		break;
		case 0b000110:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SRLV", instruction, pcN, pc);
		break;
		case 0b000000:
		if (source1==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SLL", instruction, pcN, pc);
		break;
		case 0b101011:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SLTU", instruction, pcN, pc);
		break;
		case 0b101010:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SLT", instruction, pcN, pc);
		break;
		case 0b000100:
		if (shift==0)
			return mips_execute_R_X(state, hi, lo, instruction_data, "SLLV", instruction, pcN, pc);
		break;
		case 0b010010:
		if ((source1==0) && (source2==0) && (shift==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "MFLO", instruction, pcN, pc);
		break;
		case 0b010000:
		if ((source1==0) && (source2==0) && (shift==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "MFHI", instruction, pcN, pc);
		break;
		case 0b010011:
		if ((source2==0) && (destination==0) && (shift==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "MTLO", instruction, pcN, pc);
		break;
		case 0b010001:
		if ((source2==0) && (destination==0) && (shift==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "MTHI", instruction, pcN, pc);
		break;
		case 0b011010:
		if ((shift==0) && (destination==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "DIV", instruction, pcN, pc);
		break;
		case 0b011011:
		if ((shift==0) && (destination==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "DIVU", instruction, pcN, pc);
		break;
		case 0b011001:
		if ((shift==0) && (destination==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "MULTU", instruction, pcN, pc);
		break;
		case 0b011000:
		if ((shift==0) && (destination==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "MULT", instruction, pcN, pc);
		break;
		case 0b001001:
		if ((source2==0) && (shift==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "JALR", instruction, pcN, pc);
		break;
		case 0b001000:
		if ((source2==0) && (shift==0) && (destination==0))
			return mips_execute_R_X(state, hi, lo, instruction_data, "JR", instruction, pcN, pc);
		break;
		default:
		break;
	}
	instruction = "Invalid instruction format";
	return mips_ExceptionInvalidInstruction;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r14
movq %rdi, %rbp
movl 0x14(%rcx), %edi
cmpq $0x2b, %rdi
ja 0x5bed
movq %r9, %rbx
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movl 0x4(%rcx), %esi
movl 0x8(%rcx), %ecx
movl 0xc(%r15), %edx
movl 0x10(%r15), %eax
leaq 0x570d(%rip), %r8       # 0xab50
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
testl %esi, %esi
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x544e(%rip), %rsi      # 0xa8b2
leaq 0x544a(%rip), %rdx      # 0xa8b5
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5540(%rip), %rsi      # 0xa9f4
leaq 0x553c(%rip), %rdx      # 0xa9f7
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5523(%rip), %rsi      # 0xaa27
leaq 0x551e(%rip), %rdx      # 0xaa29
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %edx, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5305(%rip), %rsi      # 0xa859
leaq 0x5303(%rip), %rdx      # 0xa85e
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5346(%rip), %rsi      # 0xa8ea
leaq 0x5342(%rip), %rdx      # 0xa8ed
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %ecx, %esi
orl %eax, %esi
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5223(%rip), %rsi      # 0xa819
leaq 0x5220(%rip), %rdx      # 0xa81d
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %esi, %esi
sete %cl
cmpl $0x20, %eax
setb %al
andb %cl, %al
cmpb $0x1, %al
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5327(%rip), %rsi      # 0xa97a
leaq 0x5323(%rip), %rdx      # 0xa97d
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x532f(%rip), %rsi      # 0xa9d2
leaq 0x532c(%rip), %rdx      # 0xa9d6
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5333(%rip), %rsi      # 0xaa26
leaq 0x532f(%rip), %rdx      # 0xaa29
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %edx, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5108(%rip), %rsi      # 0xa84b
leaq 0x5105(%rip), %rdx      # 0xa84f
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x526e(%rip), %rsi      # 0xaa01
leaq 0x526b(%rip), %rdx      # 0xaa05
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x51b2(%rip), %rsi      # 0xa995
leaq 0x51af(%rip), %rdx      # 0xa999
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %edx, %ecx
orl %eax, %ecx
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5006(%rip), %rsi      # 0xa83b
leaq 0x5003(%rip), %rdx      # 0xa83f
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5044(%rip), %rsi      # 0xa8c9
leaq 0x5041(%rip), %rdx      # 0xa8cd
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %esi, %esi
sete %cl
cmpl $0x20, %eax
setb %al
andb %cl, %al
cmpb $0x1, %al
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x50d8(%rip), %rsi      # 0xa9ba
leaq 0x50d4(%rip), %rdx      # 0xa9bd
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5029(%rip), %rsi      # 0xa95b
leaq 0x5026(%rip), %rdx      # 0xa95f
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %eax, %ecx
orl %edx, %ecx
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4dd3(%rip), %rsi      # 0xa757
leaq 0x4dce(%rip), %rdx      # 0xa759
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %eax, %ecx
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4d67(%rip), %rsi      # 0xa73b
leaq 0x4d64(%rip), %rdx      # 0xa73f
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %edx, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4cde(%rip), %rsi      # 0xa702
leaq 0x4cda(%rip), %rdx      # 0xa705
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %edx, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4c99(%rip), %rsi      # 0xa70d
leaq 0x4c96(%rip), %rdx      # 0xa711
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %edx, %ecx
orl %eax, %ecx
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4d65(%rip), %rsi      # 0xa82b
leaq 0x4d62(%rip), %rdx      # 0xa82f
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
orl %ecx, %esi
orl %eax, %esi
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4cef(%rip), %rsi      # 0xa807
leaq 0x4cec(%rip), %rdx      # 0xa80b
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4a2c(%rip), %rsi      # 0xa594
leaq 0x4a29(%rip), %rdx      # 0xa598
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
jne 0x5bed
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x497a(%rip), %rsi      # 0xa52e
leaq 0x4976(%rip), %rdx      # 0xa531
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
jmp 0x5c52
testl %eax, %eax
je 0x5c0f
movq 0x8(%r14), %rdx
leaq 0x50b4(%rip), %rcx      # 0xacac
movl $0x1a, %r8d
movq %r14, %rdi
xorl %esi, %esi
callq 0x32d0
movl $0x2005, %ebx           # imm = 0x2005
jmp 0x5c70
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4995(%rip), %rsi      # 0xa5b4
leaq 0x4991(%rip), %rdx      # 0xa5b7
leaq 0x8(%rsp), %rdi
callq 0x40c4
leaq 0x8(%rsp), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r9
pushq 0x60(%rsp)
pushq %rbx
callq 0x6655
addq $0x10, %rsp
movl %eax, %ebx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5c70
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x31e0
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
jmp 0x5ccb
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5d05
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x31e0
jmp 0x5d05
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
jmp 0x5d02
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3330