// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x268(%rdi)
jne 0x21c32
leaq 0x238(%rbx), %r15
movq 0x238(%rbx), %rax
movq 0x240(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
pushq $0x4
popq %r12
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x21b43
movl 0x14(%r14), %esi
leaq 0x1(%rdx), %rdi
addq $-0x4, %r12
cmpl (%rax,%rdx,4), %esi
movq %rdi, %rdx
jne 0x21a56
cmpb $0x1, 0x29(%r14)
jne 0x21b24
cmpb $0x1, 0x30(%r14)
jne 0x21b19
movq %r14, 0x228(%rbx)
movl $0x1, 0x230(%rbx)
leaq 0xf9e7(%rip), %rax      # 0x31488
cmpb $0x1, (%rax)
jne 0x21b2d
movq 0xf51f(%rip), %rdi      # 0x30fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x12, 0x10(%rdi,%rax)
pushq $0x20
popq %rbp
movl %ebp, %esi
callq 0x4440
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0xf, 0x10(%rax,%rcx)
movq %rax, %rdi
movl %ebp, %esi
callq 0x4440
movq 0x228(%rbx), %rsi
movq %rax, %rdi
callq 0x15274
leaq 0x6207(%rip), %rsi      # 0x27d0e
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
jmp 0x21b2d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21cce
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movq (%r15), %rsi
subq %r12, %rsi
movq %r15, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x111a8
movq 0xf4a6(%rip), %rdi      # 0x30ff0
leaq 0x24d1(%rip), %rsi      # 0x24022
callq 0x4300
leaq 0x60a3(%rip), %rsi      # 0x27c00
movq %rax, %rdi
callq 0x4300
leaq 0x2d0b(%rip), %rsi      # 0x24877
movq %rax, %rdi
callq 0x4300
pushq $0x73
popq %rsi
movq %rax, %rdi
callq 0x44f0
leaq 0x24bb(%rip), %rsi      # 0x24041
movq %rax, %rdi
callq 0x4300
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
leaq 0x618e(%rip), %rsi      # 0x27d2f
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
movq %r14, %rsi
callq 0x15274
leaq 0x5399(%rip), %rsi      # 0x26f54
movq %rax, %rdi
callq 0x4300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movl 0x14(%r14), %esi
movq %rax, %rdi
callq 0x43c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x60fb(%rip), %rsi      # 0x27cfb
movq %rax, %rdi
callq 0x4300
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40d0
leaq 0x58b6(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
xorl %edi, %edi
callq 0x4370
movq 0xf3b7(%rip), %rdi      # 0x30ff0
leaq 0x23e2(%rip), %rsi      # 0x24022
callq 0x4300
leaq 0x5fb4(%rip), %rsi      # 0x27c00
movq %rax, %rdi
callq 0x4300
leaq 0x2c1c(%rip), %rsi      # 0x24877
movq %rax, %rdi
callq 0x4300
pushq $0x58
popq %rsi
movq %rax, %rdi
callq 0x44f0
leaq 0x23cc(%rip), %rsi      # 0x24041
movq %rax, %rdi
callq 0x4300
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
leaq 0x6035(%rip), %rsi      # 0x27cc5
movq %rax, %rdi
callq 0x4300
movq 0x268(%rbx), %rsi
movq %rax, %rdi
callq 0x15274
leaq 0x6042(%rip), %rsi      # 0x27cf0
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
movq %r14, %rsi
callq 0x15274
leaq 0x6032(%rip), %rsi      # 0x27cfa
jmp 0x21c00
nop