// File: /workspace/github_cpp_makefile_star2_O1/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
cmpq 0x30(%rdi), %rax
je 0x14ec
movl 0xc(%rbx), %eax
testl %eax, %eax
jle 0x142a
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 0x1f14
movq 0x18(%rbx), %rsi
cmpq %rsi, %rax
jne 0x141a
movq 0x28(%rbx), %rdx
addq %r12, %rdx
cmpq 0x20(%rbx), %rsi
je 0x13e5
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rbx)
jmp 0x13ed
movq %r14, %rdi
callq 0x1fae
movq 0x28(%rbx), %rdx
addq %r12, %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x140f
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x1417
movq %r15, %rdi
callq 0x1fae
incl 0x8(%rbx)
incq %r13
movslq 0xc(%rbx), %rax
addq $0x4, %r12
cmpq %rax, %r13
jl 0x13ad
movl %eax, %r13d
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r13, %rcx
jbe 0x1532
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 0x1f14
cmpq 0x8(%rsp), %rax
jne 0x14cd
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rdx
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x1485
subq %rsi, %rdx
callq 0x1150
movq 0x18(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq -0x4(%rax), %rsi
movq %rsi, 0x18(%rbx)
leaq (%rcx,%r13,4), %rdx
movl (%rdx), %ecx
movslq %r12d, %rdi
movq (%rsp), %r8
movl %ecx, (%r8,%rdi,4)
cmpq 0x20(%rbx), %rsi
je 0x14b7
movl (%rdx), %ecx
movl %ecx, -0x4(%rax)
movq %rax, 0x18(%rbx)
jmp 0x14bf
movq %r14, %rdi
callq 0x1fae
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 0x1453
jmp 0x1532
movq 0x3ae5(%rip), %r14      # 0x4fd8
leaq 0x1b46(%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 0x3ab3(%rip), %rdi      # 0x4fd8
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3a9f(%rip), %rdi      # 0x4fd8
leaq 0x1b2a(%rip), %rsi      # 0x306a
movl $0x8, %edx
callq 0x1120
movl 0x8(%rbx), %esi
movq 0x3a84(%rip), %rdi      # 0x4fd8
callq 0x1160
movq %rax, %rbx
leaq 0x1b15(%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 0x15a5
callq 0x10f0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15bc
jmp 0x15bc
jmp 0x15bc
jmp 0x15bc
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x15cd
callq 0x10f0
movq %rbx, %rdi
callq 0x1170