// File: estwings57[P]CasHMC/sources/VaultController.cpp
// Function: CasHMC::VaultController::MakeRespondPacket(CasHMC::DRAMCommand*)
void VaultController::MakeRespondPacket(DRAMCommand *retCMD)
{
	if(retCMD->trace != NULL) {
		retCMD->trace->vaultFullLat = currentClockCycle - retCMD->trace->vaultIssueTime;
	}
	Packet *newPacket;
	if(retCMD->atomic) {
		if(retCMD->packetCMD == _2ADD8 || retCMD->packetCMD == ADD16 || retCMD->packetCMD == INC8
		|| retCMD->packetCMD == EQ8 || retCMD->packetCMD == EQ16 || retCMD->packetCMD == BWR) {
			newPacket = new Packet(RESPONSE, WR_RS, retCMD->packetTAG, 1, retCMD->trace);
			pendingDataSize -= 1;
		}
		else {
			newPacket = new Packet(RESPONSE, RD_RS, retCMD->packetTAG, 2, retCMD->trace);
			pendingDataSize -= 2;
		}
	}
	else {
		if(retCMD->commandType == WRITE_DATA) {
			//packet, cmd, tag, lng, *lat
			newPacket = new Packet(RESPONSE, WR_RS, retCMD->packetTAG, 1, retCMD->trace);
			pendingDataSize -= 1;
			//DEBUG(ALI(18)<<header<<ALI(15)<<*retCMD<<"Up)   pendingDataSize 1 decreased   (current pendingDataSize : "<<pendingDataSize<<")");
		}
		else if(retCMD->commandType == READ_DATA) {
			//packet, cmd, tag, lng, *lat
			newPacket = new Packet(RESPONSE, RD_RS, retCMD->packetTAG, (retCMD->dataSize/16)+1, retCMD->trace);
			pendingDataSize -= (retCMD->dataSize/16)+1;
			//DEBUG(ALI(18)<<header<<ALI(15)<<*retCMD<<"Up)   pendingDataSize "<<(retCMD->dataSize/16)+1<<" decreased   (current pendingDataSize : "<<pendingDataSize<<")");
		}
		else {
			ERROR(header<<"  == Error - Unknown response packet command  cmd : "<<retCMD->commandType<<"  (CurrentClock : "<<currentClockCycle<<")");
			exit(0);
		}
	}
	ReverseAddressMapping(newPacket->ADRS, retCMD->bank, retCMD->column, retCMD->row);
	newPacket->segment = retCMD->segment;
	ReceiveUp(newPacket);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x4ca46
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
testb $0x1, 0x30(%rax)
je 0x4cb7a
movq -0x10(%rbp), %rax
cmpl $0x12, 0x2c(%rax)
je 0x4ca90
movq -0x10(%rbp), %rax
cmpl $0x13, 0x2c(%rax)
je 0x4ca90
movq -0x10(%rbp), %rax
cmpl $0x50, 0x2c(%rax)
je 0x4ca90
movq -0x10(%rbp), %rax
cmpl $0x69, 0x2c(%rax)
je 0x4ca90
movq -0x10(%rbp), %rax
cmpl $0x68, 0x2c(%rax)
je 0x4ca90
movq -0x10(%rbp), %rax
cmpl $0x11, 0x2c(%rax)
jne 0x4cb03
movl $0x468, %edi            # imm = 0x468
callq 0x4390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq 0x8(%rax), %r9
movl $0x39, %edx
movl $0x1, %r8d
movl %r8d, %esi
callq 0x43d70
jmp 0x4cac4
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movl 0x234(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x234(%rax)
jmp 0x4cb75
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x468, %esi            # imm = 0x468
callq 0x43a0
jmp 0x4cd9f
movl $0x468, %edi            # imm = 0x468
callq 0x4390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq 0x8(%rax), %r9
movl $0x1, %esi
movl $0x38, %edx
movl $0x2, %r8d
callq 0x43d70
jmp 0x4cb39
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movl 0x234(%rax), %ecx
subl $0x2, %ecx
movl %ecx, 0x234(%rax)
jmp 0x4cb75
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x468, %esi            # imm = 0x468
callq 0x43a0
jmp 0x4cd9f
jmp 0x4cd4e
movq -0x10(%rbp), %rax
cmpl $0x6, 0x10(%rax)
jne 0x4cbf7
movl $0x468, %edi            # imm = 0x468
callq 0x4390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq 0x8(%rax), %r9
movl $0x39, %edx
movl $0x1, %r8d
movl %r8d, %esi
callq 0x43d70
jmp 0x4cbb8
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movl 0x234(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x234(%rax)
jmp 0x4cd4c
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x468, %esi            # imm = 0x468
callq 0x43a0
jmp 0x4cd9f
movq -0x10(%rbp), %rax
cmpl $0x5, 0x10(%rax)
jne 0x4cc8b
movl $0x468, %edi            # imm = 0x468
callq 0x4390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movl 0x24(%rax), %r8d
shrl $0x4, %r8d
incl %r8d
movq 0x8(%rax), %r9
movl $0x1, %esi
movl $0x38, %edx
callq 0x43d70
jmp 0x4cc40
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x24(%rcx), %edx
shrl $0x4, %edx
addl $0x1, %edx
movl 0x234(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x234(%rax)
jmp 0x4cd4a
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x468, %esi            # imm = 0x468
callq 0x43a0
jmp 0x4cd9f
movq 0x1935e(%rip), %rdi     # 0x65ff0
leaq 0x43a1(%rip), %rsi      # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x7e08(%rip), %rsi      # 0x54ab0
callq 0x4380
movq %rax, %rdi
leaq 0x4b7e(%rip), %rsi      # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x9a, %esi
callq 0x4610
movq %rax, %rdi
leaq 0x4386(%rip), %rsi      # 0x51059
callq 0x4380
movq -0x30(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x7f1e(%rip), %rsi      # 0x54c10
callq 0x4380
movq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x4610
movq %rax, %rdi
leaq 0x7e9b(%rip), %rsi      # 0x54bab
callq 0x4380
movq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x764a(%rip), %rsi      # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x19272(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
jmp 0x4cd4c
jmp 0x4cd4e
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x450, %rsi            # imm = 0x450
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x20(%rax), %r8d
callq 0x4cdb0
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movb 0x31(%rax), %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x422(%rax)
movq -0x18(%rbp), %rsi
callq 0x4fc50
addq $0x50, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x4630
nopl (%rax,%rax)