// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rsi), %r12
testq %r12, %r12
je 0x21cf2
movl 0x8(%rbx), %eax
subl 0x18(%r12), %eax
movl %eax, 0x1c(%r12)
cmpb $0x1, 0x30(%r14)
jne 0x21d37
movl 0x2c(%r14), %eax
leal -0x50(%rax), %ecx
cmpl $0x19, %ecx
jbe 0x21d70
addl $-0x11, %eax
cmpl $0x3, %eax
jb 0x21d7a
movl $0x468, %edi            # imm = 0x468
callq 0x4310
movq %rax, %r15
movl 0x14(%r14), %ecx
pushq $0x1
popq %rsi
pushq $0x38
popq %rdx
pushq $0x2
popq %r8
movq %rax, %rdi
movq %r12, %r9
callq 0x1de6a
pushq $-0x2
jmp 0x21da1
movl 0x10(%r14), %eax
cmpl $0x5, %eax
je 0x21da4
cmpl $0x6, %eax
jne 0x21e1c
movl $0x468, %edi            # imm = 0x468
callq 0x4310
movq %rax, %r15
movl 0x14(%r14), %ecx
pushq $0x39
popq %rdx
pushq $0x1
popq %rsi
movq %rax, %rdi
movl %esi, %r8d
movq %r12, %r9
callq 0x1de6a
jmp 0x21d9f
movl $0x3000001, %edx        # imm = 0x3000001
btl %ecx, %edx
jae 0x21d05
movl $0x468, %edi            # imm = 0x468
callq 0x4310
movq %rax, %r15
movl 0x14(%r14), %ecx
pushq $0x39
popq %rdx
pushq $0x1
popq %rsi
movq %rax, %rdi
movl %esi, %r8d
movq %r12, %r9
callq 0x1de6a
pushq $-0x1
popq %rax
jmp 0x21dda
movl $0x468, %edi            # imm = 0x468
callq 0x4310
movq %rax, %r15
movl 0x14(%r14), %ecx
movl 0x24(%r14), %r8d
shrl $0x4, %r8d
incl %r8d
pushq $0x1
popq %rsi
pushq $0x38
popq %rdx
movq %rax, %rdi
movq %r12, %r9
callq 0x1de6a
movl 0x24(%r14), %eax
shrl $0x4, %eax
notl %eax
addl %eax, 0x234(%rbx)
leaq 0x450(%r15), %rsi
movl 0x18(%r14), %edx
movl 0x1c(%r14), %ecx
movl 0x20(%r14), %r8d
movq %rbx, %rdi
callq 0x21ee8
movb 0x31(%r14), %al
movb %al, 0x422(%r15)
movq %rbx, %rdi
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x23512
movq 0xf1cd(%rip), %rdi      # 0x30ff0
leaq 0x21f8(%rip), %rsi      # 0x24022
callq 0x4300
leaq 0x5dca(%rip), %rsi      # 0x27c00
movq %rax, %rdi
callq 0x4300
leaq 0x2a32(%rip), %rsi      # 0x24877
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
movl $0x9a, %esi
callq 0x44f0
leaq 0x21e0(%rip), %rsi      # 0x24041
movq %rax, %rdi
callq 0x4300
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
leaq 0x5ee4(%rip), %rsi      # 0x27d60
movq %rax, %rdi
callq 0x4300
movl 0x10(%r14), %esi
movq %rax, %rdi
callq 0x44f0
leaq 0x5e64(%rip), %rsi      # 0x27cfb
movq %rax, %rdi
callq 0x4300
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40d0
leaq 0x561f(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
xorl %edi, %edi
callq 0x4370
jmp 0x21ecf
jmp 0x21ecf
jmp 0x21ecf
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x4320
movq %rbx, %rdi
callq 0x4520
nop