// File: ys1998[P]spsim/src/queues.cpp
// Function: AddressQueue::MEMissue()
std::tuple<Instruction, int ,int> AddressQueue::MEMissue(){
	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["lw"])){
			auto regs = temp.physical_regs();
			if(!*(b + std::get<1>(regs)) && (_addr[i] != -2) && (_addr[i] != -1) && findswaddr(i)){
				_q.erase(_q.begin() + i);
				int addr = _addr[i];
				_addr.erase(_addr.begin() + i);
				return std::make_tuple(temp, addr , i);
			}
		}
		if(temp.is_valid() && (std::get<0>(type) == OPCODE["sw"])  && findswaddr(i) && no_notcalculated_branch_above(temp))
		{
			auto regs = temp.physical_regs();
			if(!*(b + std::get<1>(regs)) && (_addr[i] != -2) && (_addr[i] != -1)){
				if (!*(b + std::get<0>(regs))){
					_q.erase(_q.begin() + i);
					int addr = _addr[i];
					_addr.erase(_addr.begin() + i);
					return std::make_tuple(temp, addr , i);
				}
			}
            else {
                break;
            }
		}
	}
	return std::make_tuple(Instruction(), -1, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x660, %rsp            # imm = 0x660
movq %rdi, -0x558(%rbp)
movq %rdi, %rax
movq %rax, -0x550(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x548(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x548(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x560(%rbp)
callq 0xac70
movq %rax, %rcx
movq -0x560(%rbp), %rax
cmpq %rcx, %rax
jae 0x1cff1
movq -0x548(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xaca0
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
movq %rdi, -0x568(%rbp)
callq 0x6c70
movq -0x568(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x105b0
jmp 0x1c7ec
movb $0x0, -0xca(%rbp)
movb $0x0, -0xcb(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x6280
movb %al, -0x569(%rbp)
jmp 0x1c80e
movb -0x569(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x56a(%rbp)
jne 0x1c826
jmp 0x1c8ab
leaq -0x98(%rbp), %rdi
callq 0xa9d0
movl (%rax), %eax
movl %eax, -0x57c(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x578(%rbp)
callq 0x3490
movq -0x578(%rbp), %rdx
movb $0x1, -0xca(%rbp)
leaq 0x580b(%rip), %rsi      # 0x2206d
leaq -0xc8(%rbp), %rdi
callq 0x6020
jmp 0x1c870
movb $0x1, -0xcb(%rbp)
leaq 0x12a4a(%rip), %rdi     # 0x2f2c8
leaq -0xc8(%rbp), %rsi
callq 0x5f40
movq %rax, -0x588(%rbp)
jmp 0x1c893
movl -0x57c(%rbp), %eax
movq -0x588(%rbp), %rcx
cmpl (%rcx), %eax
sete %al
movb %al, -0x56a(%rbp)
movb -0x56a(%rbp), %al
movb %al, -0x589(%rbp)
testb $0x1, -0xcb(%rbp)
jne 0x1c8c2
jmp 0x1c8ce
leaq -0xc8(%rbp), %rdi
callq 0x31e0
testb $0x1, -0xca(%rbp)
jne 0x1c8d9
jmp 0x1c8e5
leaq -0xc9(%rbp), %rdi
callq 0x3300
movb -0x589(%rbp), %al
testb $0x1, %al
jne 0x1c8f4
jmp 0x1cb5f
leaq -0xdc(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x10520
jmp 0x1c909
movq -0x548(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x598(%rbp)
leaq -0xdc(%rbp), %rdi
callq 0x10ad0
movq %rax, %rcx
movq -0x598(%rbp), %rax
movslq (%rcx), %rcx
testb $0x1, (%rax,%rcx)
jne 0x1cb5d
movq -0x548(%rbp), %rdi
addq $0x58, %rdi
movq -0x18(%rbp), %rsi
callq 0x12560
cmpl $-0x2, (%rax)
je 0x1cb5d
movq -0x548(%rbp), %rdi
addq $0x58, %rdi
movq -0x18(%rbp), %rsi
callq 0x12560
cmpl $-0x1, (%rax)
je 0x1cb5d
movq -0x548(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x1d090
movb %al, -0x599(%rbp)
jmp 0x1c98f
movb -0x599(%rbp), %al
testb $0x1, %al
jne 0x1c99e
jmp 0x1cb5d
movq -0x548(%rbp), %rsi
leaq -0x140(%rbp), %rdi
movq %rdi, -0x5b8(%rbp)
callq 0xad70
movq -0x5b8(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x120(%rbp), %rdi
movq %rdi, -0x5b0(%rbp)
callq 0xad30
movq -0x5b0(%rbp), %rsi
leaq -0x100(%rbp), %rdi
movq %rdi, -0x5a8(%rbp)
callq 0xada0
movq -0x548(%rbp), %rsi
movq -0x5a8(%rbp), %rdx
leaq -0x160(%rbp), %rdi
callq 0xacd0
jmp 0x1ca0c
movq -0x548(%rbp), %rdi
addq $0x58, %rdi
movq %rdi, -0x5c8(%rbp)
movq -0x18(%rbp), %rsi
callq 0x12560
movq -0x5c8(%rbp), %rsi
movl (%rax), %eax
movl %eax, -0x164(%rbp)
leaq -0x1c8(%rbp), %rdi
movq %rdi, -0x5d8(%rbp)
callq 0x1a050
movq -0x5d8(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x5d0(%rbp)
callq 0x12920
movq -0x5d0(%rbp), %rsi
leaq -0x188(%rbp), %rdi
movq %rdi, -0x5c0(%rbp)
callq 0x1d9a0
movq -0x5c8(%rbp), %rsi
movq -0x5c0(%rbp), %rdx
leaq -0x1e8(%rbp), %rdi
callq 0x1d940
jmp 0x1ca9d
leaq -0x270(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x164(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x1d9e0
jmp 0x1cabd
movq -0x558(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x1da20
leaq -0x270(%rbp), %rdi
callq 0x1da50
movl $0x1, -0x274(%rbp)
jmp 0x1cf9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1cfe0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1cb41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
testb $0x1, -0xcb(%rbp)
jne 0x1cb33
jmp 0x1cb3f
leaq -0xc8(%rbp), %rdi
callq 0x31e0
jmp 0x1cb41
testb $0x1, -0xca(%rbp)
jne 0x1cb4c
jmp 0x1cb58
leaq -0xc9(%rbp), %rdi
callq 0x3300
jmp 0x1cfe0
jmp 0x1cb5f
movb $0x0, -0x29a(%rbp)
movb $0x0, -0x29b(%rbp)
movb $0x0, -0x319(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x6280
movb %al, -0x5d9(%rbp)
jmp 0x1cb88
movb -0x5d9(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x5da(%rbp)
jne 0x1cba0
jmp 0x1cc97
leaq -0x98(%rbp), %rdi
callq 0xa9d0
movl (%rax), %eax
movl %eax, -0x5ec(%rbp)
leaq -0x299(%rbp), %rdi
movq %rdi, -0x5e8(%rbp)
callq 0x3490
movq -0x5e8(%rbp), %rdx
movb $0x1, -0x29a(%rbp)
leaq 0x5441(%rip), %rsi      # 0x2201d
leaq -0x298(%rbp), %rdi
callq 0x6020
jmp 0x1cbea
movb $0x1, -0x29b(%rbp)
leaq 0x126d0(%rip), %rdi     # 0x2f2c8
leaq -0x298(%rbp), %rsi
callq 0x5f40
movq %rax, -0x5f8(%rbp)
jmp 0x1cc0d
movl -0x5ec(%rbp), %ecx
movq -0x5f8(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x5da(%rbp)
jne 0x1cc97
movq -0x548(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x1d090
movb %al, -0x5f9(%rbp)
jmp 0x1cc3d
movb -0x5f9(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x5da(%rbp)
jne 0x1cc52
jmp 0x1cc97
leaq -0x318(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x6c70
jmp 0x1cc67
movq -0x548(%rbp), %rdi
movb $0x1, -0x319(%rbp)
leaq -0x318(%rbp), %rsi
callq 0x1d280
movb %al, -0x5fa(%rbp)
jmp 0x1cc89
movb -0x5fa(%rbp), %al
movb %al, -0x5da(%rbp)
jmp 0x1cc97
movb -0x5da(%rbp), %al
movb %al, -0x5fb(%rbp)
testb $0x1, -0x319(%rbp)
jne 0x1ccae
jmp 0x1ccba
leaq -0x318(%rbp), %rdi
callq 0x61d0
testb $0x1, -0x29b(%rbp)
jne 0x1ccc5
jmp 0x1ccd1
leaq -0x298(%rbp), %rdi
callq 0x31e0
testb $0x1, -0x29a(%rbp)
jne 0x1ccdc
jmp 0x1cce8
leaq -0x299(%rbp), %rdi
callq 0x3300
movb -0x5fb(%rbp), %al
testb $0x1, %al
jne 0x1ccf7
jmp 0x1cf92
leaq -0x32c(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x10520
jmp 0x1cd0c
movq -0x548(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x608(%rbp)
leaq -0x32c(%rbp), %rdi
callq 0x10ad0
movq %rax, %rcx
movq -0x608(%rbp), %rax
movslq (%rcx), %rcx
testb $0x1, (%rax,%rcx)
jne 0x1cf84
movq -0x548(%rbp), %rdi
addq $0x58, %rdi
movq -0x18(%rbp), %rsi
callq 0x12560
cmpl $-0x2, (%rax)
je 0x1cf84
movq -0x548(%rbp), %rdi
addq $0x58, %rdi
movq -0x18(%rbp), %rsi
callq 0x12560
cmpl $-0x1, (%rax)
je 0x1cf84
movq -0x548(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x610(%rbp)
leaq -0x32c(%rbp), %rdi
callq 0x10b30
movq %rax, %rcx
movq -0x610(%rbp), %rax
movslq (%rcx), %rcx
testb $0x1, (%rax,%rcx)
jne 0x1cf82
movq -0x548(%rbp), %rsi
leaq -0x390(%rbp), %rdi
movq %rdi, -0x628(%rbp)
callq 0xad70
movq -0x628(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x370(%rbp), %rdi
movq %rdi, -0x620(%rbp)
callq 0xad30
movq -0x620(%rbp), %rsi
leaq -0x350(%rbp), %rdi
movq %rdi, -0x618(%rbp)
callq 0xada0
movq -0x548(%rbp), %rsi
movq -0x618(%rbp), %rdx
leaq -0x3b0(%rbp), %rdi
callq 0xacd0
jmp 0x1ce1e
movq -0x548(%rbp), %rdi
addq $0x58, %rdi
movq %rdi, -0x638(%rbp)
movq -0x18(%rbp), %rsi
callq 0x12560
movq -0x638(%rbp), %rsi
movl (%rax), %eax
movl %eax, -0x3b4(%rbp)
leaq -0x418(%rbp), %rdi
movq %rdi, -0x648(%rbp)
callq 0x1a050
movq -0x648(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x3f8(%rbp), %rdi
movq %rdi, -0x640(%rbp)
callq 0x12920
movq -0x640(%rbp), %rsi
leaq -0x3d8(%rbp), %rdi
movq %rdi, -0x630(%rbp)
callq 0x1d9a0
movq -0x638(%rbp), %rsi
movq -0x630(%rbp), %rdx
leaq -0x438(%rbp), %rdi
callq 0x1d940
jmp 0x1ceaf
leaq -0x4c0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x3b4(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x1d9e0
jmp 0x1cecf
movq -0x558(%rbp), %rdi
leaq -0x4c0(%rbp), %rsi
callq 0x1da20
leaq -0x4c0(%rbp), %rdi
callq 0x1da50
movl $0x1, -0x274(%rbp)
jmp 0x1cf9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1cf69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1cf50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
testb $0x1, -0x319(%rbp)
jne 0x1cf42
jmp 0x1cf4e
leaq -0x318(%rbp), %rdi
callq 0x61d0
jmp 0x1cf50
testb $0x1, -0x29b(%rbp)
jne 0x1cf5b
jmp 0x1cf67
leaq -0x298(%rbp), %rdi
callq 0x31e0
jmp 0x1cf69
testb $0x1, -0x29a(%rbp)
jne 0x1cf74
jmp 0x1cf80
leaq -0x299(%rbp), %rdi
callq 0x3300
jmp 0x1cfe0
jmp 0x1cf90
movl $0x2, -0x274(%rbp)
jmp 0x1cf9c
jmp 0x1cf92
movl $0x0, -0x274(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x61d0
movl -0x274(%rbp), %eax
movl %eax, -0x64c(%rbp)
testl %eax, %eax
je 0x1cfcd
jmp 0x1cfba
movl -0x64c(%rbp), %eax
subl $0x1, %eax
je 0x1d069
jmp 0x1cfcb
jmp 0x1cff1
jmp 0x1cfcf
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x1c787
leaq -0x90(%rbp), %rdi
callq 0x61d0
jmp 0x1d079
leaq -0x538(%rbp), %rdi
movq %rdi, -0x658(%rbp)
callq 0xe8a0
movq -0x558(%rbp), %rdi
movq -0x658(%rbp), %rsi
movl $0xffffffff, -0x53c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x540(%rbp) # imm = 0xFFFFFFFF
leaq -0x53c(%rbp), %rdx
leaq -0x540(%rbp), %rcx
callq 0x1da70
jmp 0x1d03b
leaq -0x538(%rbp), %rdi
callq 0x61d0
jmp 0x1d069
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x538(%rbp), %rdi
callq 0x61d0
jmp 0x1d079
movq -0x550(%rbp), %rax
addq $0x660, %rsp            # imm = 0x660
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x3480
nopw %cs:(%rax,%rax)