// File: /workspace/github_cpp_makefile_star2_O3/AbraaoHonorio[P]Page-Replacement-Algorithms/PageReplacement.cpp
// Function: PageReplacement::otm()
void PageReplacement::otm(void)
{
	/* initializing */
	pageFaults_m = 0;
	myQueue.clear();


	/*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
        {
            pageFaults_m++;
		    myQueue.push_back(myPages[i]);
        }
	}


	if (!myPages.empty() && !myQueue.empty())
	{
		for (unsigned int i = sizeRam_m; i < myPages.size(); i++)
		{

			if (std::find(myQueue.begin(), myQueue.end(), myPages[i]) != myQueue.end())
				;
			else
			{
				int index = findIndex(myQueue, myPages, i);
				myQueue[index] = myPages[i]; //	replacing in accordance with index
				pageFaults_m++;
			}
		}
	}
	else
	{
		std::cout << " The Queue have empty or sizeRam is null " << std::endl;
	}

	std::cout << " OTM  " << pageFaults_m << " " << std::endl; //output
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movl $0x0, 0x8(%rdi)
movq 0x10(%rdi), %rax
cmpq %rax, 0x18(%rdi)
je 0x171c
movq %rax, 0x18(%rbx)
leaq 0x10(%rbx), %r14
movl 0xc(%rbx), %r15d
testl %r15d, %r15d
jle 0x1782
xorl %r12d, %r12d
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 0x1772
incl 0x8(%rbx)
movq 0x28(%rbx), %rdx
addq %r12, %rdx
cmpq 0x20(%rbx), %rax
je 0x176a
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rbx)
jmp 0x1772
movq %r14, %rdi
callq 0x1fda
incq %r13
movslq 0xc(%rbx), %r15
addq $0x4, %r12
cmpq %r15, %r13
jl 0x172f
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
cmpq %rcx, %rax
je 0x1866
movq 0x10(%rbx), %rdx
cmpq 0x18(%rbx), %rdx
je 0x1866
movq %r14, 0x10(%rsp)
movl %r15d, %ebp
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbp, %rcx
jbe 0x18a8
leaq 0x28(%rbx), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x30(%rsp), %r13
leaq 0x18(%rsp), %r12
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rsi
leaq (%rax,%rbp,4), %rdx
callq 0x1f34
cmpq 0x18(%rbx), %rax
jne 0x1846
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x1e3a
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0x1e3a
movq %r12, %rsi
movq %r13, %r14
movq %r13, %rdi
movl %r15d, %edx
callq 0x15e2
movl %eax, %r13d
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1820
callq 0x10f0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x182f
callq 0x10f0
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %rcx
movl (%rcx,%rbp,4), %ecx
movslq %r13d, %rdx
movl %ecx, (%rax,%rdx,4)
incl 0x8(%rbx)
movq %r14, %r13
incl %r15d
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movq %r15, %rbp
cmpq %r15, %rcx
ja 0x17cc
jmp 0x18a8
movq 0x376b(%rip), %r14      # 0x4fd8
leaq 0x17cc(%rip), %rsi      # 0x3040
movl $0x29, %edx
movq %r14, %rdi
callq 0x1120
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq 0x3729(%rip), %r14      # 0x4fd8
leaq 0x17bd(%rip), %rsi      # 0x3073
movl $0x6, %edx
movq %r14, %rdi
callq 0x1120
movl 0x8(%rbx), %esi
movq %r14, %rdi
callq 0x1160
movq %rax, %rbx
leaq 0x17a0(%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
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1932
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1932
callq 0x10f0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1941
callq 0x10f0
movq %rbx, %rdi
callq 0x1170
nop