// File: /workspace/github_cpp_makefile_star2_O1/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 $0x3, %eax
je 0x1e9b
cmpl $0x2, %eax
jne 0x1ed9
movl 0x18(%rdi), %ecx
testq %rcx, %rcx
je 0x1ed4
movl 0x68(%rdi), %eax
movq 0x40(%rdi), %r8
movq (%r8,%rax,8), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl %r10d, %eax
movl (%r8,%rax,4), %r11d
movl %r9d, %eax
cmpl (%r8,%r9,4), %r11d
jb 0x1e8e
movl %r10d, %eax
incq %r9
movl %eax, %r10d
cmpq %r9, %rcx
jne 0x1e7b
jmp 0x1ed6
movl 0x18(%rdi), %ecx
testq %rcx, %rcx
je 0x1ed4
movl 0x68(%rdi), %eax
movq 0x48(%rdi), %r8
movq (%r8,%rax,8), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movl %r10d, %eax
movl (%r8,%rax,4), %r11d
movl %r9d, %eax
cmpl (%r8,%r9,4), %r11d
ja 0x1ec7
movl %r10d, %eax
incq %r9
movl %eax, %r10d
cmpq %r9, %rcx
jne 0x1eb4
jmp 0x1ed6
xorl %eax, %eax
movl %eax, 0x6c(%rdi)
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rcx
movl 0x68(%rdi), %r11d
movq (%rcx,%r11,8), %r10
movq 0x38(%rdi), %r8
movq (%r8,%r11,8), %rbx
movl 0x58(%rdi), %ecx
shll %cl, %r11d
movl 0x6c(%rdi), %r14d
movl (%r10,%r14,4), %r9d
addl 0x5c(%rdi), %ecx
shll %cl, %r9d
orl %r11d, %r9d
movl 0x5c(%rax), %ecx
addl 0x58(%rax), %ecx
shrl %cl, %r9d
movl (%rbx,%r14,4), %r11d
movl %r9d, 0x64(%rax)
movl 0x64(%rdi), %ecx
movl %ecx, (%r10,%r14,4)
movl $0x1, %r10d
movl %esi, %ecx
testl %edx, %edx
jne 0x1f37
movq 0x38(%rax), %rdx
movq (%rdx), %rdx
movl (%rdx,%rcx,4), %r10d
movl 0x68(%rdi), %edx
movl 0x6c(%rdi), %esi
movq (%r8,%rdx,8), %rdx
movl %r10d, (%rdx,%rsi,4)
movq 0x28(%rax), %rdx
movq (%rdx), %rdx
movl %r9d, (%rdx,%rcx,4)
movq 0x38(%rax), %rdx
movq (%rdx), %rdx
movl %r11d, (%rdx,%rcx,4)
cmpl $0x2, 0x1c(%rax)
jne 0x1f97
movq 0x40(%rax), %rdx
movq (%rdx), %rdx
cmpl $0x0, 0x18(%rax)
je 0x1f90
movl (%rdx,%rcx,4), %esi
xorl %r8d, %r8d
movl (%rdx,%r8,4), %r9d
cmpl %esi, %r9d
jae 0x1f84
incl %r9d
movl %r9d, (%rdx,%r8,4)
incq %r8
movl 0x18(%rax), %r9d
cmpq %r9, %r8
jb 0x1f74
movl $0x0, (%rdx,%rcx,4)
movl 0x1c(%rdi), %eax
cmpl $0x3, %eax
je 0x1fe2
cmpl $0x2, %eax
jne 0x200d
movl 0x68(%rdi), %ecx
movl 0x6c(%rdi), %eax
movq 0x40(%rdi), %rdx
movq (%rdx,%rcx,8), %rcx
cmpl $0x0, 0x18(%rdi)
je 0x1fd9
movl (%rcx,%rax,4), %edx
xorl %esi, %esi
movl (%rcx,%rsi,4), %r8d
cmpl %edx, %r8d
jae 0x1fcd
incl %r8d
movl %r8d, (%rcx,%rsi,4)
incq %rsi
movl 0x18(%rdi), %r8d
cmpq %r8, %rsi
jb 0x1fbd
movl $0x0, (%rcx,%rax,4)
jmp 0x200d
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
nop