// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/Predictor.cc
// Function: Predictor::updateFUcaches(unsigned long, bool)
void 
Predictor::updateFUcaches(uint64_t block_addr, bool inNVM)
{
	if(!simu_parameters.simulate_conflicts)
		return;
	DPRINTF(DebugFUcache, "Predictor::updateFUcaches update block %#lx\n", block_addr);
	
	if(m_accessedBlocks.count(block_addr) == 0)
	{
		m_accessedBlocks.insert(pair<uint64_t,uint64_t>(block_addr, cpt_time));
		DPRINTF(DebugFUcache, "First Touch of the block\n");
	}

	vector< vector<MissingTagEntry*> > FUcaches = { m_SRAM_FU , m_NVM_FU };
	
	bool find = false;
		
	for(unsigned i = 0 ; i < FUcaches[inNVM].size() && !find ; i++)
	{
		if(FUcaches[inNVM][i]->addr == block_addr)
		{
			DPRINTF(DebugFUcache, "Find at index %d , updatation !!! \n" , i);				
			FUcaches[inNVM][i]->last_time_touched = cpt_time;
			find = true;
		}
	}
	if(!find) // Data not found, insert the access in the FU cache 
	{
		for(unsigned i = 0; i < FUcaches[inNVM].size() && !find; i++)
		{
			if(!FUcaches[inNVM][i]->isValid)
			{
				FUcaches[inNVM][i]->addr = block_addr;
				FUcaches[inNVM][i]->isValid = true;
				FUcaches[inNVM][i]->last_time_touched = cpt_time;	
				DPRINTF(DebugFUcache, "Added in index %d \n" , i);				
				find = true;		
			}
		}
		if(!find){	
			DPRINTF(DebugFUcache, "HERE ? \n");				
			uint64_t min_time = FUcaches[inNVM][0]->last_time_touched, min_index = 0;
			for(unsigned i = 0; i < FUcaches[inNVM].size() ; i++)
			{
				if(FUcaches[inNVM][i]->last_time_touched < min_time)
				{
					min_time = FUcaches[inNVM][i]->last_time_touched;
					min_index = i;
				}
			}
			FUcaches[inNVM][min_index]->addr = block_addr;
			FUcaches[inNVM][min_index]->isValid = true;
			FUcaches[inNVM][min_index]->last_time_touched = cpt_time;					
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x8(%rsp)
leaq 0x1ead4(%rip), %rbx     # 0x3df50
cmpb $0x1, 0x88(%rbx)
jne 0x1f7ac
movl %edx, %ebp
movq %rdi, %r14
leaq 0xc2eb(%rip), %rsi      # 0x2b780
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x5140
addq $0x8, %rbx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x138f8
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x5618
testq %r15, %r15
je 0x1f4da
movq 0x8(%rsp), %rsi
leaq 0xc2ba(%rip), %rdi      # 0x2b78d
xorl %eax, %eax
callq 0x5040
leaq 0x188(%r14), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x177ca
testq %rax, %rax
jne 0x1f557
movq 0x8(%rsp), %rax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x1ea11(%rip), %rax     # 0x3df18
movq (%rax), %rax
movq %rax, 0x8(%rsi)
movq %r15, %rdi
callq 0x21274
leaq 0xc263(%rip), %rsi      # 0x2b780
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x5140
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x138f8
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x5618
testq %r15, %r15
je 0x1f557
leaq 0xc530(%rip), %rdi      # 0x2ba82
callq 0x5480
leaq 0x170(%r14), %rsi
leaq 0x10(%rsp), %rdi
callq 0x20bc8
leaq 0x28(%rsp), %rdi
addq $0x158, %r14            # imm = 0x158
movq %r14, %rsi
callq 0x20bc8
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x7(%rsp), %rcx
callq 0x20c16
pushq $0x18
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x10, %rdi
callq 0x20e5a
addq $-0x18, %r14
cmpq $-0x18, %r14
jne 0x1f597
movzbl %bpl, %eax
xorl %r12d, %r12d
movq 0x40(%rsp), %rcx
imulq $0x18, %rax, %r14
leaq 0x10(%rsp), %r15
xorl %ebp, %ebp
movl %ebp, %ebp
movq (%rcx,%r14), %rax
movq 0x8(%rcx,%r14), %rdx
movq %rdx, %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %rbp, %rsi
jbe 0x1f657
testb $0x1, %r12b
jne 0x1f657
movq (%rax,%rbp,8), %rax
movq (%rax), %rax
cmpq 0x8(%rsp), %rax
jne 0x1f650
movq %r15, %rdi
leaq 0xc183(%rip), %rsi      # 0x2b780
leaq 0x7(%rsp), %rdx
callq 0x5140
movq %rbx, %rdi
movq %r15, %rsi
callq 0x138f8
movq %rax, %r13
movq %r15, %rdi
callq 0x5618
testq %r13, %r13
je 0x1f632
leaq 0xc191(%rip), %rdi      # 0x2b7ba
movl %ebp, %esi
xorl %eax, %eax
callq 0x5040
leaq 0x1e8df(%rip), %rax     # 0x3df18
movq (%rax), %rax
movq 0x40(%rsp), %rcx
movq (%rcx,%r14), %rdx
movq (%rdx,%rbp,8), %rdx
movq %rax, 0x8(%rdx)
movb $0x1, %r12b
incl %ebp
jmp 0x1f5c5
testb $0x1, %r12b
jne 0x1f7a2
leaq 0x10(%rsp), %r15
xorl %ebp, %ebp
movl %ebp, %ebp
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x1f6fb
testb $0x1, %r12b
jne 0x1f6fb
movq (%rax,%rbp,8), %rax
cmpb $0x0, 0x14(%rax)
jne 0x1f6e6
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movb $0x1, 0x14(%rax)
leaq 0x1e87b(%rip), %rcx     # 0x3df18
movq (%rcx), %rcx
movq %rcx, 0x8(%rax)
movq %r15, %rdi
leaq 0xc0d2(%rip), %rsi      # 0x2b780
leaq 0x7(%rsp), %rdx
callq 0x5140
movq %rbx, %rdi
movq %r15, %rsi
callq 0x138f8
movq %rax, %r13
movq %r15, %rdi
callq 0x5618
movb $0x1, %r12b
testq %r13, %r13
je 0x1f6e6
leaq 0xc101(%rip), %rdi      # 0x2b7de
movl %ebp, %esi
xorl %eax, %eax
callq 0x5040
incl %ebp
movq 0x40(%rsp), %rcx
movq (%rcx,%r14), %rax
movq 0x8(%rcx,%r14), %rdx
jmp 0x1f668
testb $0x1, %r12b
jne 0x1f7a2
leaq 0xc074(%rip), %rsi      # 0x2b780
leaq 0x10(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x5140
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x138f8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5618
testq %rbx, %rbx
je 0x1f746
leaq 0xc35a(%rip), %rdi      # 0x2ba9b
callq 0x5480
movq 0x40(%rsp), %rcx
movq (%rcx,%r14), %rax
movq 0x8(%rcx,%r14), %rcx
movq (%rax), %rdx
movq 0x8(%rdx), %rdx
subq %rax, %rcx
sarq $0x3, %rcx
xorl %esi, %esi
xorl %edi, %edi
movl %edi, %edi
cmpq %rdi, %rcx
jbe 0x1f784
movq (%rax,%rdi,8), %r8
movq 0x8(%r8), %r8
cmpq %rdx, %r8
cmovbq %r8, %rdx
cmovbq %rdi, %rsi
incl %edi
jmp 0x1f766
movq 0x8(%rsp), %rcx
movq (%rax,%rsi,8), %rax
movq %rcx, (%rax)
movb $0x1, 0x14(%rax)
leaq 0x1e77d(%rip), %rcx     # 0x3df18
movq (%rcx), %rcx
movq %rcx, 0x8(%rax)
leaq 0x40(%rsp), %rdi
callq 0x20ba6
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f811
jmp 0x1f80c
jmp 0x1f7f4
jmp 0x1f803
movq %rax, %rbx
pushq $0x18
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x10, %rdi
callq 0x20e5a
addq $-0x18, %r14
cmpq $-0x18, %r14
jne 0x1f7ca
jmp 0x1f828
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x20e5a
jmp 0x1f828
jmp 0x1f803
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5618
jmp 0x1f828
movq %rax, %rbx
jmp 0x1f828
jmp 0x1f80c
jmp 0x1f811
movq %rax, %rbx
jmp 0x1f81e
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5618
leaq 0x40(%rsp), %rdi
callq 0x20ba6
movq %rbx, %rdi
callq 0x5570