// File: estwings57[P]CasHMC/sources/VaultController.cpp
// Function: CasHMC::VaultController::ReturnCommand(CasHMC::DRAMCommand*)
void VaultController::ReturnCommand(DRAMCommand *retCMD)
{
	//Read and write data commands share one data bus
	if(dataBus != NULL) {
		ERROR(header<<"  == Error - Data Bus Collision  (dataBus:"<<*dataBus<<", retCMD:"<<*retCMD<<")  (CurrentClock : "<<currentClockCycle<<")");
		exit(0);
	}
	
	bool foundMatch = false;
	for(int i=0; i<pendingReadData.size(); i++) {
		if(retCMD->packetTAG == pendingReadData[i]) {
			if(retCMD->lastCMD == true) {
				if(retCMD->atomic) {
					atomicCMD = retCMD;
					atomicOperLeft = 1;
					DE_CR(ALI(18)<<header<<ALI(15)<<*atomicCMD<<"Up)   RETURNING ATOMIC read data");
				}
				else {
					MakeRespondPacket(retCMD);
					delete retCMD;
				}
			}
			else {
				delete retCMD;
			}
			pendingReadData.erase(pendingReadData.begin()+i);
			foundMatch = true;
			break;
		}
	}
	if(!foundMatch) {
		ERROR(header<<"  == Error - Can't find a matching transaction  "<<*retCMD<<" 0x"<<hex<<retCMD->packetTAG<<dec<<"  (CurrentClock : "<<currentClockCycle<<")");
		exit(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, 0x268(%rax)
je 0x4c6d7
movq 0x199f0(%rip), %rdi     # 0x65ff0
leaq 0x4a33(%rip), %rsi      # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x849a(%rip), %rsi      # 0x54ab0
callq 0x4380
movq %rax, %rdi
leaq 0x5210(%rip), %rsi      # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x58, %esi
callq 0x4610
movq %rax, %rdi
leaq 0x4a18(%rip), %rsi      # 0x51059
callq 0x4380
movq -0x50(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x8515(%rip), %rsi      # 0x54b75
callq 0x4380
movq %rax, %rdi
movq -0x50(%rbp), %rax
movq 0x268(%rax), %rsi
callq 0x30f50
movq %rax, %rdi
leaq 0x851e(%rip), %rsi      # 0x54ba0
callq 0x4380
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x30f50
movq %rax, %rdi
leaq 0x850d(%rip), %rsi      # 0x54baa
callq 0x4380
movq %rax, %rdi
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x7cbd(%rip), %rsi      # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x198e5(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
movb $0x0, -0x11(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x50(%rbp), %rdi
movslq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x238, %rdi            # imm = 0x238
callq 0x17eb0
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0x4c8ef
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x5c(%rbp)
addq $0x238, %rdi            # imm = 0x238
movslq -0x18(%rbp), %rsi
callq 0x17e90
movq %rax, %rcx
movl -0x5c(%rbp), %eax
cmpl (%rcx), %eax
jne 0x4c8df
movq -0x10(%rbp), %rax
movb 0x29(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x4c863
movq -0x10(%rbp), %rax
testb $0x1, 0x30(%rax)
je 0x4c83a
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, 0x228(%rax)
movl $0x1, 0x230(%rax)
leaq 0x19daf(%rip), %rax     # 0x66528
testb $0x1, (%rax)
je 0x4c838
movl $0x12, %edi
callq 0x177b0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
movq 0x19837(%rip), %rdi     # 0x65fd0
callq 0x4440
movq %rax, -0x78(%rbp)
movl $0x20, %edi
callq 0x177d0
movq -0x78(%rbp), %rdi
movb %al, -0x1d(%rbp)
movzbl -0x1d(%rbp), %esi
callq 0x4550
movq -0x50(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, -0x70(%rbp)
movl $0xf, %edi
callq 0x177b0
movq -0x70(%rbp), %rdi
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %esi
callq 0x4440
movq %rax, -0x68(%rbp)
movl $0x20, %edi
callq 0x177d0
movq -0x68(%rbp), %rdi
movb %al, -0x25(%rbp)
movzbl -0x25(%rbp), %esi
callq 0x4550
movq %rax, %rdi
movq -0x50(%rbp), %rax
movq 0x228(%rax), %rsi
callq 0x30f50
movq %rax, %rdi
leaq 0x839a(%rip), %rsi      # 0x54bbe
callq 0x4380
movq %rax, %rdi
movq 0x1977d(%rip), %rsi     # 0x65fb0
callq 0x43c0
jmp 0x4c861
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4ca00
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x4c85f
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x4c861
jmp 0x4c883
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, %rax
je 0x4c881
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x4c883
movq -0x50(%rbp), %rdi
movq %rdi, %rax
addq $0x238, %rax            # imm = 0x238
movq %rax, -0x90(%rbp)
addq $0x238, %rdi            # imm = 0x238
callq 0x19bc0
movq %rax, -0x40(%rbp)
movslq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x25950
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x22aa0
movq -0x90(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x22a30
movq %rax, -0x48(%rbp)
movb $0x1, -0x11(%rbp)
jmp 0x4c8ef
jmp 0x4c8e1
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4c6e2
testb $0x1, -0x11(%rbp)
jne 0x4c9f1
movq 0x196f0(%rip), %rdi     # 0x65ff0
leaq 0x4733(%rip), %rsi      # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x819a(%rip), %rsi      # 0x54ab0
callq 0x4380
movq %rax, %rdi
leaq 0x4f10(%rip), %rsi      # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x73, %esi
callq 0x4610
movq %rax, %rdi
leaq 0x4718(%rip), %rsi      # 0x51059
callq 0x4380
movq -0x50(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x827f(%rip), %rsi      # 0x54bdf
callq 0x4380
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x30f50
movq %rax, %rdi
leaq 0x74a4(%rip), %rsi      # 0x53e1f
callq 0x4380
movq %rax, %rdi
leaq -0x901a(%rip), %rsi     # 0x43970
callq 0x4150
movq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x44c0
movq %rax, %rdi
leaq -0x9008(%rip), %rsi     # 0x439a0
callq 0x4150
movq %rax, %rdi
leaq 0x81f4(%rip), %rsi      # 0x54bab
callq 0x4380
movq %rax, %rdi
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x79a3(%rip), %rsi      # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x195cb(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)