// File: 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:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x150(%rsp)
movq 0x150(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movl $0x0, 0x8(%rdi)
addq $0x10, %rdi
callq 0x3570
movq 0x40(%rsp), %rax
movl 0xc(%rax), %eax
subl $0x1, %eax
movl %eax, 0x14c(%rsp)
cmpl $0x0, 0x14c(%rsp)
jl 0x3011
movq 0x40(%rsp), %rdi
addq $0x10, %rdi
callq 0x36e0
movq 0x40(%rsp), %rdi
movq %rax, 0x138(%rsp)
addq $0x10, %rdi
callq 0x3710
movq 0x40(%rsp), %rdi
movq %rax, 0x130(%rsp)
addq $0x28, %rdi
movslq 0x14c(%rsp), %rsi
callq 0x3740
movq %rax, %rdx
movq 0x138(%rsp), %rdi
movq 0x130(%rsp), %rsi
callq 0x3680
movq 0x40(%rsp), %rdi
movq %rax, 0x140(%rsp)
addq $0x10, %rdi
callq 0x3710
movq %rax, 0x128(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3640
testb $0x1, %al
jne 0x2fbf
jmp 0x2fc1
jmp 0x2ff9
movq 0x40(%rsp), %rdi
movl 0x8(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x8(%rdi)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x38(%rsp)
addq $0x28, %rdi
movslq 0x14c(%rsp), %rsi
callq 0x3740
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x3760
jmp 0x2ffb
movl 0x14c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x14c(%rsp)
jmp 0x2f1e
movq 0x40(%rsp), %rdi
movq %rdi, %rax
addq $0x28, %rax
movq %rax, 0x30(%rsp)
addq $0x28, %rdi
callq 0x36e0
movq %rax, 0x118(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x3860
movq 0x40(%rsp), %rdi
addq $0x28, %rdi
callq 0x36e0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x100(%rsp)
movslq 0xc(%rax), %rsi
leaq 0x100(%rsp), %rdi
callq 0x3940
movq %rax, 0x108(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x3860
movq 0x30(%rsp), %rdi
movq 0x120(%rsp), %rsi
movq 0x110(%rsp), %rdx
callq 0x38a0
movq 0x40(%rsp), %rdi
movq %rax, 0xf8(%rsp)
addq $0x28, %rdi
callq 0x35f0
testb $0x1, %al
jne 0x33ad
movq 0x40(%rsp), %rdi
addq $0x10, %rdi
callq 0x35f0
testb $0x1, %al
jne 0x33ad
movl $0x0, 0xf4(%rsp)
movq 0x40(%rsp), %rdi
movl 0xf4(%rsp), %eax
movq %rax, 0x28(%rsp)
addq $0x28, %rdi
callq 0x37d0
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0x33ab
movq 0x40(%rsp), %rdi
addq $0x10, %rdi
callq 0x36e0
movq 0x40(%rsp), %rdi
movq %rax, 0xe0(%rsp)
addq $0x10, %rdi
callq 0x3710
movq 0x40(%rsp), %rdi
movq %rax, 0xd8(%rsp)
addq $0x28, %rdi
movl 0xf4(%rsp), %eax
movl %eax, %esi
callq 0x3740
movq %rax, %rdx
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x3680
movq 0x40(%rsp), %rdi
movq %rax, 0xe8(%rsp)
addq $0x10, %rdi
callq 0x3710
movq %rax, 0xd0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x3640
testb $0x1, %al
jne 0x31af
jmp 0x32d0
movq 0x40(%rsp), %rdi
addq $0x10, %rdi
callq 0x36e0
movq %rax, 0xc0(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xc0(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x3b20
movq 0x40(%rsp), %rdi
movq %rax, 0xc8(%rsp)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x18(%rsp)
addq $0x10, %rdi
callq 0x36e0
movq %rax, 0xa0(%rsp)
movq 0xc8(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x3940
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3860
movq 0x18(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x37f0
movq 0x40(%rsp), %rdi
movq %rax, 0x98(%rsp)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x20(%rsp)
addq $0x10, %rdi
callq 0x36e0
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3860
movq 0x40(%rsp), %rdi
addq $0x28, %rdi
movl 0xf4(%rsp), %eax
movl %eax, %esi
callq 0x3740
movq 0x20(%rsp), %rdi
movq %rax, %rdx
movq 0x90(%rsp), %rsi
callq 0x3b60
movq %rax, 0x80(%rsp)
jmp 0x3393
movq 0x40(%rsp), %rdi
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x8(%rsp)
addq $0x10, %rdi
callq 0x36e0
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3860
movq 0x40(%rsp), %rdi
addq $0x28, %rdi
movl 0xf4(%rsp), %eax
movl %eax, %esi
callq 0x3740
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movq 0x78(%rsp), %rsi
callq 0x3b60
movq 0x40(%rsp), %rdi
movq %rax, 0x68(%rsp)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x10(%rsp)
addq $0x10, %rdi
callq 0x3710
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x1, %esi
callq 0x3d80
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x3860
movq 0x10(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x37f0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x48(%rsp)
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x3395
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x30ed
jmp 0x33cf
movq 0x5c24(%rip), %rdi      # 0x8fd8
leaq 0x2c59(%rip), %rsi      # 0x6014
callq 0x20e0
movq %rax, %rdi
movq 0x5bfe(%rip), %rsi      # 0x8fc8
callq 0x2100
movq 0x5c02(%rip), %rdi      # 0x8fd8
leaq 0x2c71(%rip), %rsi      # 0x604e
callq 0x20e0
movq %rax, %rdi
movq 0x40(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x2180
movq %rax, %rdi
leaq 0x2c50(%rip), %rsi      # 0x604c
callq 0x20e0
movq %rax, %rdi
movq 0x5bbd(%rip), %rsi      # 0x8fc8
callq 0x2100
addq $0x158, %rsp            # imm = 0x158
retq
nopl (%rax,%rax)