// File: /workspace/github_cpp_makefile_star2_O3/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 0x5be5
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 0x5715(%rip), %r8       # 0xab50
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
testl %esi, %esi
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5456(%rip), %rsi      # 0xa8b2
leaq 0x5452(%rip), %rdx      # 0xa8b5
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5548(%rip), %rsi      # 0xa9f4
leaq 0x5544(%rip), %rdx      # 0xa9f7
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x552b(%rip), %rsi      # 0xaa27
leaq 0x5526(%rip), %rdx      # 0xaa29
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %edx, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x530d(%rip), %rsi      # 0xa859
leaq 0x530b(%rip), %rdx      # 0xa85e
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x534e(%rip), %rsi      # 0xa8ea
leaq 0x534a(%rip), %rdx      # 0xa8ed
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %ecx, %esi
orl %eax, %esi
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x522b(%rip), %rsi      # 0xa819
leaq 0x5228(%rip), %rdx      # 0xa81d
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %esi, %esi
sete %cl
cmpl $0x20, %eax
setb %al
andb %cl, %al
cmpb $0x1, %al
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x532f(%rip), %rsi      # 0xa97a
leaq 0x532b(%rip), %rdx      # 0xa97d
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5337(%rip), %rsi      # 0xa9d2
leaq 0x5334(%rip), %rdx      # 0xa9d6
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x533b(%rip), %rsi      # 0xaa26
leaq 0x5337(%rip), %rdx      # 0xaa29
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %edx, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5110(%rip), %rsi      # 0xa84b
leaq 0x510d(%rip), %rdx      # 0xa84f
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5276(%rip), %rsi      # 0xaa01
leaq 0x5273(%rip), %rdx      # 0xaa05
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x51ba(%rip), %rsi      # 0xa995
leaq 0x51b7(%rip), %rdx      # 0xa999
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %edx, %ecx
orl %eax, %ecx
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x500e(%rip), %rsi      # 0xa83b
leaq 0x500b(%rip), %rdx      # 0xa83f
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x504c(%rip), %rsi      # 0xa8c9
leaq 0x5049(%rip), %rdx      # 0xa8cd
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %esi, %esi
sete %cl
cmpl $0x20, %eax
setb %al
andb %cl, %al
cmpb $0x1, %al
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x50e0(%rip), %rsi      # 0xa9ba
leaq 0x50dc(%rip), %rdx      # 0xa9bd
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5031(%rip), %rsi      # 0xa95b
leaq 0x502e(%rip), %rdx      # 0xa95f
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %eax, %ecx
orl %edx, %ecx
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4ddb(%rip), %rsi      # 0xa757
leaq 0x4dd6(%rip), %rdx      # 0xa759
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %eax, %ecx
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4d6f(%rip), %rsi      # 0xa73b
leaq 0x4d6c(%rip), %rdx      # 0xa73f
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %edx, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4ce6(%rip), %rsi      # 0xa702
leaq 0x4ce2(%rip), %rdx      # 0xa705
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %edx, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4ca1(%rip), %rsi      # 0xa70d
leaq 0x4c9e(%rip), %rdx      # 0xa711
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %edx, %ecx
orl %eax, %ecx
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4d6d(%rip), %rsi      # 0xa82b
leaq 0x4d6a(%rip), %rdx      # 0xa82f
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
orl %ecx, %esi
orl %eax, %esi
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4cf7(%rip), %rsi      # 0xa807
leaq 0x4cf4(%rip), %rdx      # 0xa80b
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4a34(%rip), %rsi      # 0xa594
leaq 0x4a31(%rip), %rdx      # 0xa598
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
jne 0x5be5
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4982(%rip), %rsi      # 0xa52e
leaq 0x497e(%rip), %rdx      # 0xa531
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
jmp 0x5c4a
testl %eax, %eax
je 0x5c07
movq 0x8(%r14), %rdx
leaq 0x50bc(%rip), %rcx      # 0xacac
movl $0x1a, %r8d
movq %r14, %rdi
xorl %esi, %esi
callq 0x32d0
movl $0x2005, %ebx           # imm = 0x2005
jmp 0x5c68
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x499d(%rip), %rsi      # 0xa5b4
leaq 0x4999(%rip), %rdx      # 0xa5b7
leaq 0x8(%rsp), %rdi
callq 0x40ba
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 0x664d
addq $0x10, %rsp
movl %eax, %ebx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5c68
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 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
jmp 0x5cc3
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5cfd
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x31e0
jmp 0x5cfd
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
jmp 0x5cfa
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3330