// File: /workspace/github_cpp_makefile_star2_O3/gvaumour[P]cache-simulator/src/Hierarchy.cc
// Function: Hierarchy::signalWB(Access, bool, int)
void
Hierarchy::signalWB(Access wb_request, bool isKept, int idcore)
{

	if(idcore == -1)
	{
		// It is a WB from the LLC to the Main Mem
		if(wb_request.m_type == MemCmd::DIRTY_WRITEBACK)
			stats_dirtyWB_MainMem++;		
		else if(wb_request.m_type == MemCmd::CLEAN_WRITEBACK)
			stats_cleanWB_MainMem++;
		else
			assert(false && "Error on the type of the write back request");

		string state = directory_state_str[m_directory->getState(wb_request.m_address)];
		//cout << "WB Request address = " << std::hex << wb_request.m_address << ", DirectoryState = " << state  << endl;

		uint64_t addr =  wb_request.m_address;
		DirectoryState dir_state = m_directory->getEntry(addr)->coherence_state;
		
		if( dir_state == CLEAN_LLC || dir_state == DIRTY_LLC )
			m_directory->setCoherenceState(addr , NOT_PRESENT);
		else if( dir_state == SHARED_L1)
			m_directory->setCoherenceState(addr , SHARED_L1_NOT_LLC);
		else if( dir_state == EXCLUSIVE_L1)
			m_directory->setCoherenceState(addr , EXCLUSIVE_L1_NOT_LLC);
		else if( dir_state == MODIFIED_L1)
			m_directory->setCoherenceState(addr , MODIFIED_L1_NOT_LLC);
		else{
			cout << "Error dir_state = " << directory_state_str[dir_state] << endl;
			assert(false);
		}
	
		state = directory_state_str[m_directory->getState(wb_request.m_address)];
		//cout << "WB Request address = " << std::hex << wb_request.m_address << ", DirectoryState = " << state  << endl;
			
//		m_directory->removeEntry(wb_request.m_address);
	}			
	else{
	
		string dir_state = string( directory_state_str[m_directory->getState(wb_request.m_address)]);
		DPRINTF( DebugHierarchy , "Write Back Block %#lx , Id Core = %d , Dir State = %s \n" , wb_request.m_address , idcore , dir_state.c_str()); 
		//Remove the idcore from the tracker list and update the state
		if(!isKept)
			m_directory->removeTracker(wb_request.m_address , idcore);
		
		if( m_LLC->handleAccess(wb_request) == BYPASS_CACHE)
		{
			if(m_directory->getTrackers(wb_request.m_address).size() == 0)
				m_directory->setCoherenceState(wb_request.m_address , NOT_PRESENT);
		
			if(wb_request.m_type == MemCmd::DIRTY_WRITEBACK)
				stats_dirtyWB_MainMem++;		
			else if(wb_request.m_type == MemCmd::CLEAN_WRITEBACK)
				stats_cleanWB_MainMem++;
			else
				assert(false && "Error on the type of the write back request");
		}
		else
		{
			
			if(m_directory->getTrackers(wb_request.m_address).size() == 0)
				m_directory->setCoherenceState(wb_request.m_address , CLEAN_LLC);
			else
				m_directory->setCoherenceState(wb_request.m_address , SHARED_L1);
		}
		dir_state = directory_state_str[m_directory->getState(wb_request.m_address)];
		DPRINTF( DebugHierarchy , "End Write Back Block %#lx Dir State is now %s \n" , wb_request.m_address , dir_state.c_str()); 
		//m_directory->updateEntry(wb_request.m_address);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, %ebp
movq %rdi, %rbx
leaq 0xd0(%rsp), %rdx
cmpl $-0x1, %ebp
je 0x170e2
movl %esi, %r12d
movq 0x20(%rbx), %rdi
movq (%rdx), %r14
movq %r14, %rsi
callq 0x132f8
movl %eax, %eax
leaq 0x2e404(%rip), %rcx     # 0x453b0
movq (%rcx,%rax,8), %rsi
leaq 0x78(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x5140
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1e389(%rip), %rsi     # 0x35358
leaq 0x1e390(%rip), %rdx     # 0x35366
leaq 0x40(%rsp), %rdi
callq 0xcc6c
leaq 0x2ef69(%rip), %r15     # 0x45f50
leaq 0x8(%r15), %rdi
leaq 0x40(%rsp), %rsi
movq %rdi, 0x70(%rsp)
callq 0x1800c
movq %rax, %r13
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x17011
callq 0x52b0
addq $0x10, %r15
cmpq %r15, %r13
je 0x17032
movq 0x78(%rsp), %rcx
leaq 0x1e4c2(%rip), %rdi     # 0x354e8
movq %r14, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x5050
testb %r12b, %r12b
jne 0x17045
movq 0x20(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x13328
movq 0x18(%rbx), %rdi
leaq 0xd0(%rsp), %rcx
movq 0x30(%rcx), %rax
movq %rax, 0x30(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1eb00
cmpl $0x2, %eax
jne 0x171a9
movq 0x20(%rbx), %rsi
leaq 0x40(%rsp), %rdi
movq %r14, %rdx
callq 0x132b4
leaq 0x40(%rsp), %rdi
movq 0x28(%rdi), %r12
callq 0x1380a
testq %r12, %r12
jne 0x170b6
movq 0x20(%rbx), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x133aa
leaq 0xd0(%rsp), %rax
movl 0x1c(%rax), %ecx
movl $0x78, %eax
cmpl $0x6, %ecx
je 0x170d9
cmpl $0x5, %ecx
jne 0x17316
movl $0x70, %eax
incq (%rbx,%rax)
jmp 0x171e1
movl 0x1c(%rdx), %ecx
movl $0x78, %eax
cmpl $0x6, %ecx
je 0x170fd
cmpl $0x5, %ecx
jne 0x172a8
movl $0x70, %eax
incq (%rbx,%rax)
movq 0x20(%rbx), %rdi
movq (%rdx), %r14
movq %r14, %rsi
callq 0x132f8
movl %eax, %eax
leaq 0x2e297(%rip), %r15     # 0x453b0
movq (%r15,%rax,8), %rsi
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x5140
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x13184
movl 0x38(%rax), %r12d
movl %r12d, %eax
andl $-0x2, %eax
movl $0x8, %edx
cmpl $0x6, %eax
je 0x1715d
cmpl $0x2, %r12d
ja 0x172c7
addl $0x3, %r12d
movl %r12d, %edx
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x133aa
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x132f8
movl %eax, %eax
movq (%r15,%rax,8), %rbx
leaq 0x40(%rsp), %r14
movq 0x8(%r14), %r15
movq %rbx, %rdi
callq 0x5160
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x54b0
leaq 0x50(%rsp), %rax
jmp 0x17288
movq 0x20(%rbx), %rsi
leaq 0x40(%rsp), %rdi
movq %r14, %rdx
callq 0x132b4
xorl %eax, %eax
leaq 0x40(%rsp), %rdi
cmpq $0x0, 0x28(%rdi)
movl $0x6, %ebp
cmovnel %eax, %ebp
callq 0x1380a
movq 0x20(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x133aa
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x132f8
movl %eax, %eax
leaq 0x2e1ba(%rip), %rcx     # 0x453b0
movq (%rcx,%rax,8), %rbx
leaq 0x78(%rsp), %r12
movq 0x8(%r12), %r13
movq %rbx, %rdi
callq 0x5160
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x54b0
leaq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1e125(%rip), %rsi     # 0x35358
leaq 0x1e12c(%rip), %rdx     # 0x35366
callq 0xcc6c
leaq 0x40(%rsp), %rsi
movq 0x70(%rsp), %rdi
callq 0x1800c
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x17265
callq 0x52b0
cmpq %r15, %rbx
je 0x17280
movq 0x78(%rsp), %rdx
leaq 0x1e2aa(%rip), %rdi     # 0x35520
movq %r14, %rsi
xorl %eax, %eax
callq 0x5050
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17296
callq 0x52b0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e1ac(%rip), %rdi     # 0x3545b
leaq 0x1e1dc(%rip), %rsi     # 0x35492
leaq 0x1e1e6(%rip), %rcx     # 0x354a3
movl $0xa4, %edx
callq 0x51d0
movq 0x2dd02(%rip), %rdi     # 0x44fd0
leaq 0x1e1fa(%rip), %rsi     # 0x354cf
movl $0x12, %edx
callq 0x5360
movq (%r15,%r12,8), %rsi
movq 0x2dce6(%rip), %rdi     # 0x44fd0
callq 0x52d0
movq %rax, %rdi
callq 0x5180
leaq 0x1e1e4(%rip), %rdi     # 0x354e2
leaq 0x1e18d(%rip), %rsi     # 0x35492
leaq 0x1e197(%rip), %rcx     # 0x354a3
movl $0xb6, %edx
callq 0x51d0
leaq 0x1e13e(%rip), %rdi     # 0x3545b
leaq 0x1e16e(%rip), %rsi     # 0x35492
leaq 0x1e178(%rip), %rcx     # 0x354a3
movl $0xd0, %edx
callq 0x51d0
jmp 0x17369
jmp 0x17369
jmp 0x1735a
jmp 0x1733f
jmp 0x17369
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x1736c
callq 0x52b0
jmp 0x1736c
jmp 0x17369
movq %rax, %rbx
jmp 0x17382
movq %rax, %rbx
leaq 0x50(%rsp), %rax
jmp 0x17374
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17382
callq 0x52b0
movq %rbx, %rdi
callq 0x55a0