// File: /workspace/github_cpp_makefile_star2_O2/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 0x54e1
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 0x4cdd(%rip), %r8       # 0x9b50
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
testl %esi, %esi
jne 0x54e1
leaq 0x4a27(%rip), %rsi      # 0x98b2
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x4b26(%rip), %rsi      # 0x99f4
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x4b16(%rip), %rsi      # 0x9a27
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %edx, %eax
jne 0x54e1
leaq 0x4905(%rip), %rsi      # 0x9859
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x4953(%rip), %rsi      # 0x98ea
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %ecx, %esi
orl %eax, %esi
jne 0x54e1
leaq 0x483d(%rip), %rsi      # 0x9819
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %esi, %esi
sete %cl
cmpl $0x20, %eax
setb %al
andb %cl, %al
cmpb $0x1, %al
jne 0x54e1
leaq 0x494e(%rip), %rsi      # 0x997a
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x4963(%rip), %rsi      # 0x99d2
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x4974(%rip), %rsi      # 0x9a26
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %edx, %eax
jne 0x54e1
leaq 0x4756(%rip), %rsi      # 0x984b
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x48c9(%rip), %rsi      # 0x9a01
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x481a(%rip), %rsi      # 0x9995
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %edx, %ecx
orl %eax, %ecx
jne 0x54e1
leaq 0x467b(%rip), %rsi      # 0x983b
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x46c6(%rip), %rsi      # 0x98c9
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %esi, %esi
sete %cl
cmpl $0x20, %eax
setb %al
andb %cl, %al
cmpb $0x1, %al
jne 0x54e1
leaq 0x4767(%rip), %rsi      # 0x99ba
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x46c5(%rip), %rsi      # 0x995b
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %eax, %ecx
orl %edx, %ecx
jne 0x54e1
leaq 0x447c(%rip), %rsi      # 0x9757
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %eax, %ecx
jne 0x54e1
leaq 0x441d(%rip), %rsi      # 0x973b
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %edx, %eax
jne 0x54e1
leaq 0x43a1(%rip), %rsi      # 0x9702
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %edx, %eax
jne 0x54e1
leaq 0x4369(%rip), %rsi      # 0x970d
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %edx, %ecx
orl %eax, %ecx
jne 0x54e1
leaq 0x4442(%rip), %rsi      # 0x982b
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
orl %ecx, %esi
orl %eax, %esi
jne 0x54e1
leaq 0x43d9(%rip), %rsi      # 0x9807
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x4127(%rip), %rsi      # 0x9594
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
jne 0x54e1
leaq 0x4082(%rip), %rsi      # 0x952e
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
jmp 0x552d
testl %eax, %eax
je 0x54f7
leaq 0x47c4(%rip), %rsi      # 0x9cac
movq %r14, %rdi
callq 0x3360
movl $0x2005, %ebx           # imm = 0x2005
jmp 0x5539
leaq 0x40b6(%rip), %rsi      # 0x95b4
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3bee
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 0x5d73
popq %rcx
popq %rdx
movl %eax, %ebx
leaq 0x8(%rsp), %rdi
callq 0x30d0
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
jmp 0x5594
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x30d0
jmp 0x55bc
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
jmp 0x55b9
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3330