// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rsi), %r12
testq %r12, %r12
je 0x2e000
movl 0x8(%rbx), %eax
subl 0x18(%r12), %eax
movl %eax, 0x1c(%r12)
cmpb $0x1, 0x30(%r14)
jne 0x2e059
movl 0x2c(%r14), %eax
leal -0x50(%rax), %ecx
cmpl $0x19, %ecx
jbe 0x2e09e
addl $-0x11, %eax
cmpl $0x3, %eax
jb 0x2e0ac
movl $0x468, %edi            # imm = 0x468
callq 0x42f0
movq %rax, %r15
movl 0x14(%r14), %ecx
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movq %rax, %rdi
movl $0x1, %esi
movl $0x38, %edx
movl $0x2, %r8d
movq %r12, %r9
callq 0x2863e
jmp 0x2e119
movl 0x10(%r14), %eax
cmpl $0x5, %eax
je 0x2e0df
cmpl $0x6, %eax
jne 0x2e158
movl $0x468, %edi            # imm = 0x468
callq 0x42f0
movq %rax, %r15
movl 0x14(%r14), %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rax, %rdi
movl $0x1, %esi
movl $0x39, %edx
movl $0x1, %r8d
movq %r12, %r9
callq 0x2863e
jmp 0x2e119
movl $0x3000001, %edx        # imm = 0x3000001
btl %ecx, %edx
jae 0x2e017
movl $0x468, %edi            # imm = 0x468
callq 0x42f0
movq %rax, %r15
movl 0x14(%r14), %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rax, %rdi
movl $0x1, %esi
movl $0x39, %edx
movl $0x1, %r8d
movq %r12, %r9
callq 0x2863e
jmp 0x2e119
movl $0x468, %edi            # imm = 0x468
callq 0x42f0
movq %rax, %r15
movl 0x14(%r14), %ecx
movl 0x24(%r14), %r8d
shrl $0x4, %r8d
incl %r8d
movq %rax, %rdi
movl $0x1, %esi
movl $0x38, %edx
movq %r12, %r9
callq 0x2863e
movl 0x24(%r14), %ebp
shrl $0x4, %ebp
notl %ebp
addl %ebp, 0x234(%rbx)
leaq 0x450(%r15), %rsi
movl 0x18(%r14), %edx
movl 0x1c(%r14), %ecx
movl 0x20(%r14), %r8d
movq %rbx, %rdi
callq 0x2e224
movb 0x31(%r14), %al
movb %al, 0x422(%r15)
movq %rbx, %rdi
movq %r15, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3024a
movq 0xde91(%rip), %rdi      # 0x3bff0
leaq 0x2ebc(%rip), %rsi      # 0x31022
callq 0x42e0
leaq 0x6a1e(%rip), %rsi      # 0x34b90
movq %rax, %rdi
callq 0x42e0
leaq 0x36b6(%rip), %rsi      # 0x31837
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x9a, %esi
callq 0x4500
leaq 0x2ea4(%rip), %rsi      # 0x31041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x6b38(%rip), %rsi      # 0x34cf0
movq %rax, %rdi
callq 0x42e0
movl 0x10(%r14), %esi
movq %rax, %rdi
callq 0x4500
leaq 0x6ab8(%rip), %rsi      # 0x34c8b
movq %rax, %rdi
callq 0x42e0
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x6273(%rip), %rsi      # 0x34461
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360
jmp 0x2e20b
jmp 0x2e20b
jmp 0x2e20b
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4540
nop