// File: /workspace/github_cpp_makefile_star2_O2/ys1998[P]spsim/src/queues.cpp
// Function: IntegerQueue::issue(int)
Instruction IntegerQueue::issue(int idx){
	switch(idx){
		case 0:
		// prefer branch
		for(size_t i=0; i < _q.size(); ++i){
			Instruction temp = _q[i];
			auto type = temp.type();
			if(temp.is_valid() && (std::get<0>(type) == OPCODE["beq"] || std::get<0>(type) == OPCODE["bne"])){
				auto regs = temp.physical_regs();
				if(!*(b + std::get<0>(regs)) && !*(b + std::get<1>(regs))){
					_q.erase(_q.begin() + i);
					return temp;
				}
			}
		}

		// send only an addition or subtraction operation
		for(size_t i=0; i < _q.size(); ++i){
			Instruction temp = _q[i];
			auto type = temp.type();
			if(temp.is_valid() && (std::get<1>(type) == FUNCT["add"] || std::get<1>(type) == FUNCT["sub"])){
				auto regs = temp.physical_regs();
				if(!*(b + std::get<0>(regs)) && !*(b + std::get<1>(regs))){
					_q.erase(_q.begin() + i);
					return temp;
				}
			}
		}
		break;

		case 1:
		// first preference to division and multiplication
		for(size_t i=0; i < _q.size(); ++i){
			Instruction temp = _q[i];
			auto type = temp.type();
			if(temp.is_valid() && (std::get<1>(type) == FUNCT["div"] || std::get<1>(type) == FUNCT["mult"])){
				auto regs = temp.physical_regs();
				if(!*(b + std::get<0>(regs)) && !*(b + std::get<1>(regs))){
					_q.erase(_q.begin() + i);
					return temp;
				}
			}
		}
		// but if neither operation is present, send addition or subtraction
		for(size_t i=0; i < _q.size(); ++i){
			Instruction temp = _q[i];
			auto type = temp.type();
			if(temp.is_valid() && (std::get<1>(type) == FUNCT["add"] || std::get<1>(type) == FUNCT["sub"])){
				auto regs = temp.physical_regs();
				if(!*(b + std::get<0>(regs)) && !*(b + std::get<1>(regs))){
					_q.erase(_q.begin() + i);
					return temp;
				}
			}
		}
		break;

		default:
		break;
	}
	// send an invalid operation/instruction if no match is found
	return Instruction();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, %r15
movq %rdi, %r14
testl %edx, %edx
je 0xca16
cmpl $0x1, %edx
jne 0xce08
leaq 0x10(%r15), %r12
leaq 0x50(%r14), %rbp
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
movq %rbp, 0x18(%rsp)
movq %r14, 0x88(%rsp)
movq %r15, %rdi
callq 0x5968
cmpq %rax, %r13
jae 0xcb6e
movq %r12, %rdi
movq %r13, %rsi
callq 0x5e92
movq %r14, %rdi
movq %rax, %rsi
callq 0x49ba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7c7c
cmpl $-0x1, 0x4(%r14)
je 0xca06
cmpl $-0x1, (%r14)
je 0xca06
movq %r13, 0x8(%rsp)
movq %r15, %r14
movq %r12, %r15
movq %rbx, %r12
movl 0x10(%rsp), %ebx
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x36e8(%rip), %rsi      # 0x10019
leaq 0x90(%rsp), %rdx
callq 0x4860
leaq 0xa8f3(%rip), %rdi      # 0x17238
movq %r13, %rsi
callq 0x47fa
cmpl (%rax), %ebx
jne 0xc973
leaq 0x30(%rsp), %rdi
callq 0x3100
movq %r12, %rbx
movq %r15, %r12
movq %r14, %r15
movq 0x88(%rsp), %r14
movq 0x8(%rsp), %r13
jmp 0xc9db
movl 0x10(%rsp), %ebx
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
leaq 0x368e(%rip), %rsi      # 0x10014
leaq 0x20(%rsp), %rdx
callq 0x4860
leaq 0xa8a1(%rip), %rdi      # 0x17238
movq %rbp, %rsi
callq 0x47fa
leaq 0x30(%rsp), %r13
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq %rbp, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3100
cmpl 0x4(%rsp), %ebx
movq 0x18(%rsp), %rbp
movq %r12, %rbx
movq %r15, %r12
movq %r14, %r15
movq 0x88(%rsp), %r14
movq 0x8(%rsp), %r13
jne 0xca06
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x7c52
movq 0x50(%r15), %rax
movslq 0x2c(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0xca06
movslq 0x28(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xce25
movq %rbp, %rdi
callq 0x3100
incq %r13
jmp 0xc8c9
leaq 0x10(%r15), %r12
leaq 0x50(%r14), %rbp
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
movq %rbp, 0x18(%rsp)
movq %r15, 0x58(%rsp)
movq %r15, %rdi
callq 0x5968
cmpq %rax, %r13
jae 0xccc2
movq %r12, %rdi
movq %r13, %rsi
callq 0x5e92
movq %r14, %rdi
movq %rax, %rsi
callq 0x49ba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7c7c
cmpl $-0x1, 0x4(%r14)
je 0xcb5e
cmpl $-0x1, (%r14)
je 0xcb5e
movq %r13, 0x8(%rsp)
movq %r12, %r15
movq %rbx, %r12
movl 0x14(%rsp), %ebx
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x3577(%rip), %rsi      # 0x1000c
leaq 0x90(%rsp), %rdx
callq 0x4860
leaq 0xa75f(%rip), %rdi      # 0x17208
movq %r13, %rsi
callq 0x47fa
cmpl (%rax), %ebx
jne 0xcad1
leaq 0x30(%rsp), %rdi
callq 0x3100
movq %r12, %rbx
movq %r15, %r12
movq 0x58(%rsp), %r15
movq 0x8(%rsp), %r13
jmp 0xcb33
movl 0x14(%rsp), %ebx
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
leaq 0x352c(%rip), %rsi      # 0x10010
leaq 0x20(%rsp), %rdx
callq 0x4860
leaq 0xa713(%rip), %rdi      # 0x17208
movq %rbp, %rsi
callq 0x47fa
leaq 0x30(%rsp), %r13
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq %rbp, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3100
cmpl 0x4(%rsp), %ebx
movq 0x18(%rsp), %rbp
movq %r12, %rbx
movq %r15, %r12
movq 0x58(%rsp), %r15
movq 0x8(%rsp), %r13
jne 0xcb5e
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x7c52
movq 0x50(%r15), %rax
movslq 0x2c(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0xcb5e
movslq 0x28(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xce77
movq %rbp, %rdi
callq 0x3100
incq %r13
jmp 0xca30
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
movq %r12, 0x80(%rsp)
movq %r15, %rdi
callq 0x5968
cmpq %rax, %r13
jae 0xce08
movq %r12, %rdi
movq %r13, %rsi
callq 0x5e92
movq %r14, %rdi
movq %rax, %rsi
callq 0x49ba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7c7c
cmpl $-0x1, 0x4(%r14)
je 0xccb2
cmpl $-0x1, (%r14)
je 0xccb2
movq %r13, 0x8(%rsp)
movq %r15, %r12
movq %rbx, %r15
movl 0x10(%rsp), %ebx
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x3421(%rip), %rsi      # 0x10004
leaq 0x90(%rsp), %rdx
callq 0x4860
leaq 0xa641(%rip), %rdi      # 0x17238
movq %r13, %rsi
callq 0x47fa
cmpl (%rax), %ebx
jne 0xcc22
leaq 0x30(%rsp), %rdi
callq 0x3100
movq %r15, %rbx
movq %r12, %r15
movq 0x80(%rsp), %r12
movq 0x8(%rsp), %r13
jmp 0xcc87
movl 0x10(%rsp), %ebx
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
leaq 0x33d3(%rip), %rsi      # 0x10008
leaq 0x20(%rsp), %rdx
callq 0x4860
leaq 0xa5f2(%rip), %rdi      # 0x17238
movq %rbp, %rsi
callq 0x47fa
leaq 0x30(%rsp), %r13
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq %rbp, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3100
cmpl 0x4(%rsp), %ebx
movq 0x18(%rsp), %rbp
movq %r15, %rbx
movq %r12, %r15
movq 0x80(%rsp), %r12
movq 0x8(%rsp), %r13
jne 0xccb2
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x7c52
movq 0x50(%r15), %rax
movslq 0x2c(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0xccb2
movslq 0x28(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xcf21
movq %rbp, %rdi
callq 0x3100
incq %r13
jmp 0xcb7e
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
movq %r15, %rdi
callq 0x5968
cmpq %rax, %r13
jae 0xce08
movq %r12, %rdi
movq %r13, %rsi
callq 0x5e92
movq %r14, %rdi
movq %rax, %rsi
callq 0x49ba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7c7c
cmpl $-0x1, 0x4(%r14)
je 0xcdf8
cmpl $-0x1, (%r14)
je 0xcdf8
movq %r13, 0x8(%rsp)
movq %r12, %r15
movq %rbx, %r12
movl 0x10(%rsp), %ebx
leaq 0x30(%rsp), %r13
movq %r13, %rdi
leaq 0x32d5(%rip), %rsi      # 0x10004
leaq 0x90(%rsp), %rdx
callq 0x4860
leaq 0xa4f5(%rip), %rdi      # 0x17238
movq %r13, %rsi
callq 0x47fa
cmpl (%rax), %ebx
jne 0xcd6b
leaq 0x30(%rsp), %rdi
callq 0x3100
movq %r12, %rbx
movq %r15, %r12
movq 0x58(%rsp), %r15
movq 0x8(%rsp), %r13
jmp 0xcdcd
movl 0x10(%rsp), %ebx
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
leaq 0x328a(%rip), %rsi      # 0x10008
leaq 0x20(%rsp), %rdx
callq 0x4860
leaq 0xa4a9(%rip), %rdi      # 0x17238
movq %rbp, %rsi
callq 0x47fa
leaq 0x30(%rsp), %r13
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq %rbp, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3100
cmpl 0x4(%rsp), %ebx
movq 0x18(%rsp), %rbp
movq %r12, %rbx
movq %r15, %r12
movq 0x58(%rsp), %r15
movq 0x8(%rsp), %r13
jne 0xcdf8
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x7c52
movq 0x50(%r15), %rax
movslq 0x2c(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0xcdf8
movslq 0x28(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xcecc
movq %rbp, %rdi
callq 0x3100
incq %r13
jmp 0xccca
movq %r14, %rdi
callq 0x6dd2
movq %r14, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movups 0x10(%r15), %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
movups 0x20(%r15), %xmm0
movaps %xmm0, 0x10(%rsi)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x59b0
movaps (%r12), %xmm0
movaps 0x10(%r12), %xmm1
leaq 0xd0(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm1, 0x10(%rdx)
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x5978
jmp 0xce10
movups 0x10(%r15), %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
movups 0x20(%r15), %xmm0
movaps %xmm0, 0x10(%rsi)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x59b0
movaps (%r12), %xmm0
movaps 0x10(%r12), %xmm1
leaq 0x110(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm1, 0x10(%rdx)
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x5978
jmp 0xce10
movups 0x10(%r15), %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
movups 0x20(%r15), %xmm0
movaps %xmm0, 0x10(%rsi)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x59b0
movaps (%r12), %xmm0
movaps 0x10(%r12), %xmm1
leaq 0xf0(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm1, 0x10(%rdx)
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x5978
jmp 0xce10
movups 0x10(%r15), %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
movups 0x20(%r15), %xmm0
movaps %xmm0, 0x10(%rsi)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x59b0
movaps (%r12), %xmm0
movaps 0x10(%r12), %xmm1
leaq 0xb0(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm1, 0x10(%rdx)
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x5978
jmp 0xce10
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfad
jmp 0xcf8c
jmp 0xcf8c
jmp 0xcfad
jmp 0xcfad
jmp 0xcfad
jmp 0xcf8c
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x3100
jmp 0xcfb0
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfad
jmp 0xcfcb
jmp 0xcfad
jmp 0xcfcb
jmp 0xcfad
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x3100
movq 0x18(%rsp), %rbp
jmp 0xcfce
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfcb
jmp 0xcfcb
movq %rax, %r14
movq %rbp, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3320