// File: /workspace/github_cpp_makefile_star2_O3/sopanpatra160[P]OOO_Superscalar_Processor_Simulator/cache.cc
// Function: cache::swap(unsigned int, unsigned int)
unsigned int cache::swap(unsigned int found_loc,unsigned int writeorread){
	//LRU policy
	if(rp==2){
		ev_blk= lru_block2evict(ind);
	}
	//LFU policy
	else if(rp==3){
		ev_blk= lfu_block2evict(ind);
	}
	
	unsigned int temp_tag = tag_store[ind][ev_blk];
	unsigned int temp_dirty = dirty_store[ind][ev_blk];
	unsigned int reconstr_addr_to_vc = ev_blk_addr(ind,temp_tag);	
	unsigned int reconstr_tag_to_vc = vptr->calc_tag(reconstr_addr_to_vc);

	tag_store[ind][ev_blk] = tag;
	if(writeorread)
		dirty_store[ind][ev_blk] = 1; 
	else
		dirty_store[ind][ev_blk] = vptr->dirty_store[0][found_loc];
	vptr->tag_store[0][found_loc] = reconstr_tag_to_vc;
	vptr->dirty_store[0][found_loc] = temp_dirty;
	//Update Victim Cache counters
	if(vptr->rp==2)
		vptr->lru_update(0,found_loc);
	//Update L1 Cache counters
	if(rp==2)
		lru_update(ind,ev_blk);
	else if(rp==3){
		lfu_update_set(ind,ev_blk);
		lfu_update_block(ind,ev_blk,0);
	}
	return 0;
}

// Assembly:
pushq %r14
pushq %rbx
movl 0x1c(%rdi), %eax
cmpl $0x2, %eax
je 0x2045
cmpl $0x3, %eax
jne 0x207e
movl 0x18(%rdi), %eax
testq %rax, %rax
je 0x2083
movl 0x68(%rdi), %ecx
movq 0x48(%rdi), %r8
movq (%r8,%rcx,8), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl %r10d, %ecx
movl (%r8,%rcx,4), %r11d
movl %r9d, %ecx
cmpl (%r8,%r9,4), %r11d
ja 0x2038
movl %r10d, %ecx
incq %r9
movl %ecx, %r10d
cmpq %r9, %rax
jne 0x2025
jmp 0x2085
movl 0x18(%rdi), %eax
testq %rax, %rax
je 0x2083
movl 0x68(%rdi), %ecx
movq 0x40(%rdi), %r8
movq (%r8,%rcx,8), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl %r10d, %ecx
movl (%r8,%rcx,4), %r11d
movl %r9d, %ecx
cmpl (%r8,%r9,4), %r11d
jb 0x2071
movl %r10d, %ecx
incq %r9
movl %ecx, %r10d
cmpq %r9, %rax
jne 0x205e
jmp 0x2085
movl 0x6c(%rdi), %ecx
jmp 0x2088
xorl %ecx, %ecx
movl %ecx, 0x6c(%rdi)
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %r8
movl 0x68(%rdi), %ebx
movq (%r8,%rbx,8), %r11
movl %ecx, %r14d
movq 0x38(%rdi), %r10
movq (%r10,%rbx,8), %r8
movl 0x58(%rdi), %ecx
shll %cl, %ebx
movl (%r11,%r14,4), %r9d
movl (%r8,%r14,4), %r8d
addl 0x5c(%rdi), %ecx
shll %cl, %r9d
orl %ebx, %r9d
movl 0x5c(%rax), %ecx
addl 0x58(%rax), %ecx
shrl %cl, %r9d
movl %r9d, 0x64(%rax)
movl 0x64(%rdi), %ecx
movl %ecx, (%r11,%r14,4)
testl %edx, %edx
je 0x20ec
movl 0x68(%rdi), %ecx
movl 0x6c(%rdi), %edx
movq (%r10,%rcx,8), %rcx
movl $0x1, (%rcx,%rdx,4)
movq 0x38(%rax), %rcx
movq (%rcx), %rdx
movl %esi, %ecx
jmp 0x2107
movq 0x38(%rax), %rcx
movq (%rcx), %rdx
movl %esi, %ecx
movl (%rdx,%rcx,4), %esi
movl 0x68(%rdi), %r11d
movl 0x6c(%rdi), %ebx
movq (%r10,%r11,8), %r10
movl %esi, (%r10,%rbx,4)
movq 0x28(%rax), %rsi
movq (%rsi), %rsi
movl %r9d, (%rsi,%rcx,4)
movl %r8d, (%rdx,%rcx,4)
cmpl $0x2, 0x1c(%rax)
jne 0x2156
movq 0x40(%rax), %rdx
movq (%rdx), %rdx
movl 0x18(%rax), %esi
testl %esi, %esi
je 0x214f
movl (%rdx,%rcx,4), %r8d
xorl %r9d, %r9d
movl (%rdx,%r9,4), %r10d
cmpl %r8d, %r10d
jae 0x2144
incl %r10d
movl %r10d, (%rdx,%r9,4)
movl 0x18(%rax), %esi
incq %r9
movl %esi, %r10d
cmpq %r10, %r9
jb 0x2131
movl $0x0, (%rdx,%rcx,4)
movl 0x1c(%rdi), %eax
cmpl $0x3, %eax
je 0x21a5
cmpl $0x2, %eax
jne 0x21d0
movl 0x68(%rdi), %ecx
movl 0x6c(%rdi), %eax
movq 0x40(%rdi), %rdx
movq (%rdx,%rcx,8), %rcx
movl 0x18(%rdi), %edx
testl %edx, %edx
je 0x219c
movl (%rcx,%rax,4), %esi
xorl %r8d, %r8d
movl (%rcx,%r8,4), %r9d
cmpl %esi, %r9d
jae 0x2191
incl %r9d
movl %r9d, (%rcx,%r8,4)
movl 0x18(%rdi), %edx
incq %r8
movl %edx, %r9d
cmpq %r9, %r8
jb 0x217e
movl $0x0, (%rcx,%rax,4)
jmp 0x21d0
movl 0x68(%rdi), %eax
movl 0x6c(%rdi), %ecx
movq 0x48(%rdi), %rdx
movq 0x50(%rdi), %rsi
movq (%rdx,%rax,8), %r8
movl (%r8,%rcx,4), %ecx
movl %ecx, (%rsi,%rax,4)
movl 0x68(%rdi), %eax
movl 0x6c(%rdi), %ecx
movl (%rsi,%rax,4), %esi
incl %esi
movq (%rdx,%rax,8), %rax
movl %esi, (%rax,%rcx,4)
xorl %eax, %eax
popq %rbx
popq %r14
retq