// File: 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:
subq $0x298, %rsp            # imm = 0x298
movb %dl, %al
movq %rdi, 0x290(%rsp)
movq %rsi, 0x288(%rsp)
andb $0x1, %al
movb %al, 0x287(%rsp)
movq 0x290(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x3ec87(%rip), %rax     # 0x93ff0
testb $0x1, 0x88(%rax)
jne 0x55377
jmp 0x55ed0
leaq 0x25f(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
callq 0x56a0
movq 0xf8(%rsp), %rdx
leaq 0x1e3dd(%rip), %rsi     # 0x73778
leaq 0x260(%rsp), %rdi
callq 0x5530
jmp 0x553aa
leaq 0x3ec3f(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0x260(%rsp), %rsi
callq 0x33a00
movq %rax, 0xf0(%rsp)
jmp 0x553cc
leaq 0x260(%rsp), %rdi
callq 0x5768
leaq 0x25f(%rsp), %rdi
callq 0x53e0
movq 0xf0(%rsp), %rax
cmpq $0x0, %rax
je 0x55455
movq 0x288(%rsp), %rsi
leaq 0x1e382(%rip), %rdi     # 0x73785
movb $0x0, %al
callq 0x5060
jmp 0x55455
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x55443
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x5768
leaq 0x25f(%rsp), %rdi
callq 0x53e0
jmp 0x55ee5
movq 0x100(%rsp), %rdi
addq $0x188, %rdi            # imm = 0x188
leaq 0x288(%rsp), %rsi
callq 0x3dc90
cmpq $0x0, %rax
jne 0x555b1
movq 0x100(%rsp), %rax
addq $0x188, %rax            # imm = 0x188
movq %rax, 0xd8(%rsp)
leaq 0x3eb20(%rip), %rdx     # 0x93fb8
leaq 0x238(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
leaq 0x288(%rsp), %rsi
callq 0x58bf0
movq 0xd8(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x58ba0
movq %rax, 0x228(%rsp)
movb %dl, 0x230(%rsp)
leaq 0x207(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x56a0
movq 0xe8(%rsp), %rdx
leaq 0x1e27b(%rip), %rsi     # 0x73778
leaq 0x208(%rsp), %rdi
callq 0x5530
jmp 0x5550c
leaq 0x3eadd(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0x208(%rsp), %rsi
callq 0x33a00
movq %rax, 0xd0(%rsp)
jmp 0x5552e
leaq 0x208(%rsp), %rdi
callq 0x5768
leaq 0x207(%rsp), %rdi
callq 0x53e0
movq 0xd0(%rsp), %rax
cmpq $0x0, %rax
je 0x555af
leaq 0x1e255(%rip), %rdi     # 0x737b2
movb $0x0, %al
callq 0x5060
jmp 0x555af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x5559d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x208(%rsp), %rdi
callq 0x5768
leaq 0x207(%rsp), %rdi
callq 0x53e0
jmp 0x55ee5
jmp 0x555b1
movq 0x100(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x1a0(%rsp)
addq $0x170, %rsi            # imm = 0x170
callq 0x58c20
jmp 0x555d7
movq 0x100(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x1a0(%rsp)
addq $0x158, %rsi            # imm = 0x158
callq 0x58c20
jmp 0x555fd
leaq 0x1a8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
movq $0x2, 0x1e0(%rsp)
leaq 0x19f(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x58d20
movq 0xc8(%rsp), %rcx
movq 0x1d8(%rsp), %rsi
movq 0x1e0(%rsp), %rdx
leaq 0x1e8(%rsp), %rdi
callq 0x58d30
jmp 0x55655
leaq 0x19f(%rsp), %rdi
callq 0x58dc0
leaq 0x1a8(%rsp), %rax
movq %rax, 0xb8(%rsp)
addq $0x30, %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
addq $-0x18, %rdi
movq %rdi, 0xb0(%rsp)
callq 0x58aa0
movq 0xb8(%rsp), %rcx
movq 0xb0(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0xc0(%rsp)
jne 0x5567e
movb $0x0, 0x19e(%rsp)
movl $0x0, 0x198(%rsp)
movl 0x198(%rsp), %eax
movq %rax, 0xa0(%rsp)
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
callq 0x58940
movq 0xa0(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0xaf(%rsp)
jae 0x55722
movb 0x19e(%rsp), %al
xorb $-0x1, %al
movb %al, 0xaf(%rsp)
movb 0xaf(%rsp), %al
testb $0x1, %al
jne 0x55732
jmp 0x559a7
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movl 0x198(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
movq (%rax), %rax
cmpq 0x288(%rsp), %rax
jne 0x5598f
leaq 0x177(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x56a0
movq 0x98(%rsp), %rdx
leaq 0x1dfe2(%rip), %rsi     # 0x73778
leaq 0x178(%rsp), %rdi
callq 0x5530
jmp 0x557a5
leaq 0x3e844(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0x178(%rsp), %rsi
callq 0x33a00
movq %rax, 0x90(%rsp)
jmp 0x557c7
leaq 0x178(%rsp), %rdi
callq 0x5768
leaq 0x177(%rsp), %rdi
callq 0x53e0
movq 0x90(%rsp), %rax
cmpq $0x0, %rax
je 0x55940
movl 0x198(%rsp), %esi
leaq 0x1dfcb(%rip), %rdi     # 0x737cc
xorl %eax, %eax
callq 0x5060
jmp 0x5580a
jmp 0x55940
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
movq 0x1a0(%rsp), %rax
leaq 0x1a8(%rsp), %rcx
cmpq %rax, %rcx
movq %rax, 0x88(%rsp)
je 0x55876
movq 0x88(%rsp), %rdi
addq $-0x18, %rdi
movq %rdi, 0x80(%rsp)
callq 0x58aa0
movq 0x80(%rsp), %rax
leaq 0x1a8(%rsp), %rcx
cmpq %rcx, %rax
movq %rax, 0x88(%rsp)
jne 0x55840
jmp 0x55ee5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x19f(%rsp), %rdi
callq 0x58dc0
leaq 0x1a8(%rsp), %rax
movq %rax, 0x70(%rsp)
addq $0x30, %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
addq $-0x18, %rdi
movq %rdi, 0x68(%rsp)
callq 0x58aa0
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x78(%rsp)
jne 0x558b2
jmp 0x55ee5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x55915
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x5768
leaq 0x177(%rsp), %rdi
callq 0x53e0
jmp 0x55ed8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x55ed8
leaq 0x3e671(%rip), %rax     # 0x93fb8
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movl 0x198(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq 0x60(%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movb $0x1, 0x19e(%rsp)
jmp 0x55991
movl 0x198(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x198(%rsp)
jmp 0x556c7
testb $0x1, 0x19e(%rsp)
jne 0x55ec3
movl $0x0, 0x170(%rsp)
movl 0x170(%rsp), %eax
movq %rax, 0x50(%rsp)
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
callq 0x58940
movq 0x50(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x5f(%rsp)
jae 0x55a0f
movb 0x19e(%rsp), %al
xorb $-0x1, %al
movb %al, 0x5f(%rsp)
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x55a1c
jmp 0x55c02
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movl 0x170(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
testb $0x1, 0x14(%rax)
jne 0x55bea
movq 0x288(%rsp), %rax
movq %rax, 0x30(%rsp)
movzbl 0x287(%rsp), %eax
andl $0x1, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x58920
movq %rax, %rdi
movl 0x170(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movq %rcx, (%rax)
movzbl 0x287(%rsp), %eax
andl $0x1, %eax
movl %eax, %esi
callq 0x58920
movq %rax, %rdi
movl 0x170(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movb $0x1, 0x14(%rax)
leaq 0x3e4e0(%rip), %rax     # 0x93fb8
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movzbl 0x287(%rsp), %eax
andl $0x1, %eax
movl %eax, %esi
callq 0x58920
movq %rax, %rdi
movl 0x170(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq 0x40(%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x8(%rax)
leaq 0x14f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x56a0
movq 0x48(%rsp), %rdx
leaq 0x1dc4b(%rip), %rsi     # 0x73778
leaq 0x150(%rsp), %rdi
callq 0x5530
jmp 0x55b3c
leaq 0x3e4ad(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0x150(%rsp), %rsi
callq 0x33a00
movq %rax, 0x28(%rsp)
jmp 0x55b5b
leaq 0x150(%rsp), %rdi
callq 0x5768
leaq 0x14f(%rsp), %rdi
callq 0x53e0
movq 0x28(%rsp), %rax
cmpq $0x0, %rax
je 0x55be2
movl 0x170(%rsp), %esi
leaq 0x1dc62(%rip), %rdi     # 0x737f0
xorl %eax, %eax
callq 0x5060
jmp 0x55b97
jmp 0x55be2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x55bd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x5768
leaq 0x14f(%rsp), %rdi
callq 0x53e0
jmp 0x55ed8
movb $0x1, 0x19e(%rsp)
jmp 0x55bec
movl 0x170(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x170(%rsp)
jmp 0x559c0
testb $0x1, 0x19e(%rsp)
jne 0x55ec1
leaq 0x127(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x56a0
movq 0x20(%rsp), %rdx
leaq 0x1db4a(%rip), %rsi     # 0x73778
leaq 0x128(%rsp), %rdi
callq 0x5530
jmp 0x55c3d
leaq 0x3e3ac(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0x128(%rsp), %rsi
callq 0x33a00
movq %rax, 0x18(%rsp)
jmp 0x55c5c
leaq 0x128(%rsp), %rdi
callq 0x5768
leaq 0x127(%rsp), %rdi
callq 0x53e0
movq 0x18(%rsp), %rax
cmpq $0x0, %rax
je 0x55cdc
leaq 0x1db7c(%rip), %rdi     # 0x73804
xorl %eax, %eax
callq 0x5060
jmp 0x55c91
jmp 0x55cdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x55cca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x5768
leaq 0x127(%rsp), %rdi
callq 0x53e0
jmp 0x55ed8
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x118(%rsp)
movq $0x0, 0x110(%rsp)
movl $0x0, 0x10c(%rsp)
movl 0x10c(%rsp), %eax
movq %rax, 0x10(%rsp)
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
callq 0x58940
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x55e08
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movl 0x10c(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
movq 0x8(%rax), %rax
cmpq 0x118(%rsp), %rax
jae 0x55df0
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movl 0x10c(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x118(%rsp)
movl 0x10c(%rsp), %eax
movq %rax, 0x110(%rsp)
jmp 0x55df2
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x55d29
movq 0x288(%rsp), %rax
movq %rax, (%rsp)
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movq 0x110(%rsp), %rsi
callq 0x58860
movq (%rsp), %rcx
movq (%rax), %rax
movq %rcx, (%rax)
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movq 0x110(%rsp), %rsi
callq 0x58860
movq (%rax), %rax
movb $0x1, 0x14(%rax)
leaq 0x3e136(%rip), %rax     # 0x93fb8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movb 0x287(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
leaq 0x1e8(%rsp), %rdi
callq 0x58920
movq %rax, %rdi
movq 0x110(%rsp), %rsi
callq 0x58860
movq 0x8(%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x8(%rax)
jmp 0x55ec3
leaq 0x1e8(%rsp), %rdi
callq 0x58b00
addq $0x298, %rsp            # imm = 0x298
retq
leaq 0x1e8(%rsp), %rdi
callq 0x58b00
movq 0x250(%rsp), %rdi
callq 0x5690
nopw %cs:(%rax,%rax)