// File: /workspace/github_cpp_makefile_star2_O2/AbraaoHonorio[P]Page-Replacement-Algorithms/PageReplacement.cpp
// Function: PageReplacement::fifo()
void PageReplacement::fifo(void)
{
	std::vector<int> arrayMemory;


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

            }

		}

		int j = 0;  //variable to follow the memory
		/* Looking for element in memory */
		for (unsigned int i = sizeRam_m; i < myPages.size(); i++)
		{
			if (std::find(arrayMemory.begin(), arrayMemory.end(), myPages[i]) != arrayMemory.end())
				;
			else
			{
				myQueue.erase(myQueue.begin()); //Erase first element
				arrayMemory[j] = myPages[i]; // replacing in accordance with index(variable j)
				myQueue.push_back(myPages[i]);
				j++;
				if (j == (sizeRam_m)) // Checking if you have already reached the limit
					j = 0;

				pageFaults_m++;
			}

			/*					DEBUG                             */

			/*std::cout << "\n *** myQueue *** " << std::endl; //DEBUG
			for each (int element in myQueue)
			{
			std::cout << element << " " << std::endl; //DEBUG
			}

			std::cout << "\n *** arrayMemory *** " << std::endl; //DEBUG
			for each (int element in arrayMemory)
			{
			std::cout << element << " " << std::endl; //DEBUG
			}*/
		}

	}
	else
	{
		std::cout << " The Queue have empty or sizeRam is null " << std::endl;
	}


	std::cout << " \n FIFO " << pageFaults_m << " " << std::endl; //output
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq 0x28(%rdi), %rax
cmpq 0x30(%rdi), %rax
je 0x1412
leaq 0x10(%rbx), %r14
xorl %r13d, %r13d
movq %rsp, %r15
xorl %ebp, %ebp
movslq 0xc(%rbx), %r12
cmpq %r12, %rbp
jge 0x13a3
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rsi
movq 0x28(%rbx), %rdx
addq %r13, %rdx
callq 0x1ae3
cmpq 0x18(%rbx), %rax
jne 0x139a
movq 0x28(%rbx), %rsi
addq %r13, %rsi
movq %r14, %rdi
callq 0x196a
movq 0x28(%rbx), %rsi
addq %r13, %rsi
movq %r15, %rdi
callq 0x196a
incl 0x8(%rbx)
incq %rbp
addq $0x4, %r13
jmp 0x1356
xorl %ebp, %ebp
xorl %r15d, %r15d
movl %r12d, %r12d
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
jbe 0x142d
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq (%rax,%r12,4), %rdx
callq 0x1ae3
cmpq 0x8(%rsp), %rax
jne 0x140d
movq (%r14), %rsi
movq %r14, %rdi
callq 0x1988
movq 0x28(%rbx), %rax
leaq (%rax,%r12,4), %rsi
movl (%rsi), %eax
movslq %r15d, %rcx
movq (%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
movq %r14, %rdi
callq 0x196a
incl %r15d
cmpl 0xc(%rbx), %r15d
cmovel %ebp, %r15d
incl 0x8(%rbx)
incl %r12d
jmp 0x13a8
movq 0x2bbf(%rip), %rdi      # 0x3fd8
leaq 0xbe4(%rip), %rsi       # 0x2004
callq 0x10f0
movq %rax, %rdi
callq 0x1090
movq 0x2ba4(%rip), %rdi      # 0x3fd8
leaq 0xbf3(%rip), %rsi       # 0x202e
callq 0x10f0
movl 0x8(%rbx), %esi
movq %rax, %rdi
callq 0x1140
leaq 0xbea(%rip), %rsi       # 0x203c
movq %rax, %rdi
callq 0x10f0
movq %rax, %rdi
callq 0x1090
movq %rsp, %rdi
callq 0x1ad6
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1483
jmp 0x1483
jmp 0x1483
jmp 0x1483
jmp 0x1483
movq %rax, %rbx
movq %rsp, %rdi
callq 0x1ad6
movq %rbx, %rdi
callq 0x1150