// File: /workspace/github_cpp_makefile_star2_O1/AbraaoHonorio[P]Page-Replacement-Algorithms/PageReplacement.cpp
// Function: PageReplacement::lru()
void PageReplacement::lru(void)
{
	/* initializing */
	pageFaults_m = 0;
	myQueue.clear();


	/*inserting the value to queue*/
	for (int i = (sizeRam_m-1); i>=0; i--)
	{
	    if (std::find(myQueue.begin(), myQueue.end(), myPages[i]) != myQueue.end())
				;
        else
        {
            pageFaults_m++;
            myQueue.push_back(myPages[i]);
        }
	}

	// deleting Erase the first sizeRam_m elements
	myPages.erase(myPages.begin(), myPages.begin() + sizeRam_m);

	if (!myPages.empty() && !myQueue.empty()) //verify exist elemen t
	{
		for (unsigned int i = 0; i <myPages.size(); i++)
		{
				auto it = std::find(myQueue.begin(), myQueue.end(), myPages[i]);
				if (it != myQueue.end())
				{
					auto index = std::distance(myQueue.begin(), it); // calculating the index of the element
					myQueue.erase(myQueue.begin() + index); // deleting the element
					myQueue.insert(myQueue.begin(), myPages[i]); //Inserting the element at the top( highest priority )

				}
				else
				{
					myQueue.insert(myQueue.begin(), myPages[i]); //Inserting the element at the top( highest  priority )
					myQueue.erase(myQueue.end()-1); //delete to lower priority
					pageFaults_m++;
				}
		}
	}
	else
	{
		std::cout << " The Queue have empty or sizeRam is null " << std::endl;
	}

	std::cout << " LRU  " << pageFaults_m << " " << std::endl; //output
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl $0x0, 0x8(%rdi)
movq 0x10(%rdi), %rax
cmpq %rax, 0x18(%rdi)
je 0x1962
movq %rax, 0x18(%rbx)
leaq 0x10(%rbx), %r14
movslq 0xc(%rbx), %r15
testq %r15, %r15
jle 0x19ca
leaq -0x4(,%r15,4), %r12
incq %r15
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rsi
movq 0x28(%rbx), %rdx
addq %r12, %rdx
callq 0x1f14
movq 0x18(%rbx), %rsi
cmpq %rsi, %rax
jne 0x19bd
incl 0x8(%rbx)
movq 0x28(%rbx), %rdx
addq %r12, %rdx
cmpq 0x20(%rbx), %rsi
je 0x19b5
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rbx)
jmp 0x19bd
movq %r14, %rdi
callq 0x1fae
decq %r15
addq $-0x4, %r12
cmpq $0x1, %r15
jg 0x197a
movslq 0xc(%rbx), %rax
testq %rax, %rax
je 0x1a05
movq 0x28(%rbx), %r15
leaq (%r15,%rax,4), %r12
movq 0x30(%rbx), %rdx
subq %r12, %rdx
je 0x19ef
movq %r15, %rdi
movq %r12, %rsi
callq 0x1150
movq 0x30(%rbx), %rax
movq %rax, %rcx
subq %r12, %rcx
addq %rcx, %r15
cmpq %r15, %rax
je 0x1a05
movq %r15, 0x30(%rbx)
movq 0x28(%rbx), %rax
cmpq 0x30(%rbx), %rax
je 0x1adc
movq 0x10(%rbx), %rax
cmpq 0x18(%rbx), %rax
je 0x1adc
movq 0x28(%rbx), %rax
cmpq %rax, 0x30(%rbx)
je 0x1b1e
movl $0x1, %ebp
xorl %r15d, %r15d
movb $0x1, %r12b
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rsi
leaq (%rax,%r15,4), %rdx
callq 0x1f14
movq 0x18(%rbx), %rdx
cmpq %rdx, %rax
je 0x1a86
leaq 0x4(%rax), %rsi
cmpq %rdx, %rsi
je 0x1a68
subq %rsi, %rdx
movq %rax, %rdi
callq 0x1150
addq $-0x4, 0x18(%rbx)
movq 0x10(%rbx), %rsi
shlq $0x2, %r15
addq 0x28(%rbx), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x1e9a
jmp 0x1abd
movq 0x10(%rbx), %rsi
shlq $0x2, %r15
addq 0x28(%rbx), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x1e9a
testb %r12b, %r12b
jne 0x1ab5
movq 0x18(%rbx), %rsi
leaq -0x4(%rsi), %rdi
movq %rsi, %rdx
subq %rsi, %rdx
callq 0x1150
addq $-0x4, 0x18(%rbx)
incl 0x8(%rbx)
movl %ebp, %r15d
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
incl %ebp
cmpq %r15, %rcx
ja 0x1a3a
jmp 0x1b1e
movq 0x34f5(%rip), %r14      # 0x4fd8
leaq 0x1556(%rip), %rsi      # 0x3040
movl $0x29, %edx
movq %r14, %rdi
callq 0x1120
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x34b3(%rip), %r14      # 0x4fd8
leaq 0x154e(%rip), %rsi      # 0x307a
movl $0x6, %edx
movq %r14, %rdi
callq 0x1120
movl 0x8(%rbx), %esi
movq %r14, %rdi
callq 0x1160
movq %rax, %rbx
leaq 0x152a(%rip), %rsi      # 0x3078
movl $0x1, %edx
movq %rax, %rdi
callq 0x1120
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x10a0