// File: 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:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x3560
movq 0x78(%rsp), %rdi
addq $0x28, %rdi
callq 0x35f0
testb $0x1, %al
jne 0x27bd
movl $0x0, 0xf4(%rsp)
movq 0x78(%rsp), %rcx
movl 0xf4(%rsp), %eax
cmpl 0xc(%rcx), %eax
jge 0x25b9
movq 0x78(%rsp), %rdi
addq $0x10, %rdi
movq %rdi, 0x68(%rsp)
callq 0x36e0
movq 0x68(%rsp), %rdi
movq %rax, 0xe0(%rsp)
callq 0x3710
movq 0x78(%rsp), %rdi
movq %rax, 0xd8(%rsp)
addq $0x28, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x3740
movq %rax, %rdx
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x3680
movq %rax, 0x70(%rsp)
jmp 0x24d1
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rax
movq %rax, 0xe8(%rsp)
addq $0x10, %rdi
callq 0x3710
movq %rax, 0xc0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3640
testb $0x1, %al
jne 0x250f
jmp 0x253a
jmp 0x25a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x3590
jmp 0x285d
movq 0x78(%rsp), %rdi
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x60(%rsp)
addq $0x28, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x3740
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x3760
jmp 0x256b
movq 0x78(%rsp), %rdi
addq $0x28, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x3740
movq %rax, %rsi
leaq 0xf8(%rsp), %rdi
callq 0x3760
jmp 0x2593
movq 0x78(%rsp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x25a3
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x245a
movq 0x78(%rsp), %rax
movl $0x0, 0xbc(%rsp)
movl 0xc(%rax), %eax
movl %eax, 0xb8(%rsp)
movq 0x78(%rsp), %rdi
movl 0xb8(%rsp), %eax
movq %rax, 0x58(%rsp)
addq $0x28, %rdi
callq 0x37d0
movq %rax, %rcx
movq 0x58(%rsp), %rax
cmpq %rcx, %rax
jae 0x27bb
leaq 0xf8(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x36e0
movq 0x48(%rsp), %rdi
movq %rax, 0xa8(%rsp)
callq 0x3710
movq 0x78(%rsp), %rdi
movq %rax, 0xa0(%rsp)
addq $0x28, %rdi
movl 0xb8(%rsp), %eax
movl %eax, %esi
callq 0x3740
movq %rax, %rdx
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x3680
movq %rax, 0x50(%rsp)
jmp 0x2660
movq 0x50(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x3710
movq %rax, 0x98(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x3640
testb $0x1, %al
jne 0x269d
jmp 0x26a2
jmp 0x27a3
movq 0x78(%rsp), %rdi
addq $0x10, %rdi
movq %rdi, 0x38(%rsp)
callq 0x36e0
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3860
movq 0x38(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x37f0
movq %rax, 0x40(%rsp)
jmp 0x26eb
movq 0x78(%rsp), %rdi
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
addq $0x28, %rdi
movq %rdi, 0x28(%rsp)
movl 0xb8(%rsp), %eax
movl %eax, %esi
callq 0x3740
movl (%rax), %eax
movl %eax, 0x24(%rsp)
movslq 0xbc(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x3740
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movq 0x78(%rsp), %rax
movl %edx, (%rcx)
addq $0x10, %rax
movq %rax, 0x30(%rsp)
movl 0xb8(%rsp), %eax
movl %eax, %esi
callq 0x3740
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x3760
jmp 0x2768
movq 0x78(%rsp), %rcx
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
cmpl 0xc(%rcx), %eax
jne 0x2795
movl $0x0, 0xbc(%rsp)
movq 0x78(%rsp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x27a5
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x25d3
jmp 0x27ec
movq 0x6814(%rip), %rdi      # 0x8fd8
leaq 0x3849(%rip), %rsi      # 0x6014
callq 0x20e0
movq %rax, 0x18(%rsp)
jmp 0x27d7
movq 0x18(%rsp), %rdi
movq 0x67e5(%rip), %rsi      # 0x8fc8
callq 0x2100
jmp 0x27ea
jmp 0x27ec
movq 0x67e5(%rip), %rdi      # 0x8fd8
leaq 0x3844(%rip), %rsi      # 0x603e
callq 0x20e0
movq %rax, 0x10(%rsp)
jmp 0x2806
movq 0x10(%rsp), %rdi
movq 0x78(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x2180
movq %rax, 0x8(%rsp)
jmp 0x281f
movq 0x8(%rsp), %rdi
leaq 0x3821(%rip), %rsi      # 0x604c
callq 0x20e0
movq %rax, (%rsp)
jmp 0x2836
movq (%rsp), %rdi
movq 0x6787(%rip), %rsi      # 0x8fc8
callq 0x2100
jmp 0x2848
leaq 0xf8(%rsp), %rdi
callq 0x3590
addq $0x118, %rsp            # imm = 0x118
retq
movq 0xd0(%rsp), %rdi
callq 0x2190
nopw (%rax,%rax)