// File: /workspace/github_cpp_makefile_star2_O3/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
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x28(%rdi), %rax
movq 0x30(%rdi), %rdx
cmpq %rdx, %rax
je 0x14f9
movl 0xc(%rbx), %ecx
testl %ecx, %ecx
jle 0x143f
leaq 0x10(%rbx), %r14
xorl %r12d, %r12d
movq %rsp, %r15
xorl %r13d, %r13d
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rsi
movq 0x28(%rbx), %rdx
addq %r12, %rdx
callq 0x1f34
movq 0x18(%rbx), %rsi
cmpq %rsi, %rax
jne 0x1423
movq 0x28(%rbx), %rdx
leaq (%rdx,%r12), %rcx
cmpq 0x20(%rbx), %rax
je 0x13eb
movl (%rcx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rbx)
jmp 0x13fa
movq %r14, %rdi
movq %rcx, %rdx
callq 0x1fda
movq 0x28(%rbx), %rdx
addq %r12, %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x1418
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x1420
movq %r15, %rdi
callq 0x1fda
incl 0x8(%rbx)
incq %r13
movslq 0xc(%rbx), %rcx
addq $0x4, %r12
cmpq %rcx, %r13
jl 0x13b2
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rdx
movl %ecx, %r13d
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r13, %rdx
jbe 0x153f
leaq 0x10(%rbx), %r14
leal 0x1(%r13), %ebp
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq (%rax,%r13,4), %rdx
callq 0x1f34
cmpq 0x8(%rsp), %rax
jne 0x14da
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rdx
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x1496
subq %rsi, %rdx
callq 0x1150
movq 0x18(%rbx), %rdx
leaq -0x4(%rdx), %rsi
movq %rsi, 0x18(%rbx)
movq 0x28(%rbx), %rax
movl (%rax,%r13,4), %ecx
movslq %r12d, %rdi
movq (%rsp), %r8
movl %ecx, (%r8,%rdi,4)
cmpq 0x20(%rbx), %rsi
je 0x14c0
movl %ecx, -0x4(%rdx)
movq %rdx, 0x18(%rbx)
jmp 0x14cc
leaq (%rax,%r13,4), %rdx
movq %r14, %rdi
callq 0x1fda
incl %r12d
cmpl 0xc(%rbx), %r12d
cmovel %r15d, %r12d
incl 0x8(%rbx)
movl %ebp, %r13d
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
incl %ebp
cmpq %r13, %rcx
ja 0x1460
jmp 0x153f
movq 0x3ad8(%rip), %r14      # 0x4fd8
leaq 0x1b39(%rip), %rsi      # 0x3040
movl $0x29, %edx
movq %r14, %rdi
callq 0x1120
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x3aa6(%rip), %rdi      # 0x4fd8
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3a92(%rip), %rdi      # 0x4fd8
leaq 0x1b1d(%rip), %rsi      # 0x306a
movl $0x8, %edx
callq 0x1120
movl 0x8(%rbx), %esi
movq 0x3a77(%rip), %rdi      # 0x4fd8
callq 0x1160
movq %rax, %rbx
leaq 0x1b08(%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
callq 0x10a0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x15b2
callq 0x10f0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15c9
jmp 0x15c9
jmp 0x15c9
jmp 0x15c9
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x15da
callq 0x10f0
movq %rbx, %rdi
callq 0x1170