// File: /workspace/github_cpp_makefile_star2_O3/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 0x2d6a8
movl 0x8(%rbx), %eax
subl 0x18(%r12), %eax
movl %eax, 0x1c(%r12)
cmpb $0x1, 0x30(%r14)
jne 0x2d701
movl 0x2c(%r14), %eax
leal -0x50(%rax), %ecx
cmpl $0x19, %ecx
jbe 0x2d746
addl $-0x11, %eax
cmpl $0x3, %eax
jb 0x2d754
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 0x27dbe
jmp 0x2d7c1
movl 0x10(%r14), %eax
cmpl $0x5, %eax
je 0x2d787
cmpl $0x6, %eax
jne 0x2d800
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 0x27dbe
jmp 0x2d7c1
movl $0x3000001, %edx        # imm = 0x3000001
btl %ecx, %edx
jae 0x2d6bf
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 0x27dbe
jmp 0x2d7c1
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 0x27dbe
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 0x2d8cc
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 0x2f8e8
movq 0xd7e9(%rip), %rdi      # 0x3aff0
leaq 0x2814(%rip), %rsi      # 0x30022
callq 0x42e0
leaq 0x63f6(%rip), %rsi      # 0x33c10
movq %rax, %rdi
callq 0x42e0
leaq 0x306e(%rip), %rsi      # 0x30897
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x9a, %esi
callq 0x4500
leaq 0x27fc(%rip), %rsi      # 0x30041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x6510(%rip), %rsi      # 0x33d70
movq %rax, %rdi
callq 0x42e0
movl 0x10(%r14), %esi
movq %rax, %rdi
callq 0x4500
leaq 0x6490(%rip), %rsi      # 0x33d0b
movq %rax, %rdi
callq 0x42e0
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x5c4b(%rip), %rsi      # 0x334e1
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360
jmp 0x2d8b3
jmp 0x2d8b3
jmp 0x2d8b3
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4540
nop