// File: 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:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movl $0x0, 0x8(%rdi)
addq $0x10, %rdi
callq 0x3570
movl $0x0, 0xbc(%rsp)
movq 0x20(%rsp), %rcx
movl 0xbc(%rsp), %eax
cmpl 0xc(%rcx), %eax
jge 0x2c71
movq 0x20(%rsp), %rdi
addq $0x10, %rdi
callq 0x36e0
movq 0x20(%rsp), %rdi
movq %rax, 0xa8(%rsp)
addq $0x10, %rdi
callq 0x3710
movq 0x20(%rsp), %rdi
movq %rax, 0xa0(%rsp)
addq $0x28, %rdi
movslq 0xbc(%rsp), %rsi
callq 0x3740
movq %rax, %rdx
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x3680
movq 0x20(%rsp), %rdi
movq %rax, 0xb0(%rsp)
addq $0x10, %rdi
callq 0x3710
movq %rax, 0x98(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x3640
testb $0x1, %al
jne 0x2c1f
jmp 0x2c21
jmp 0x2c59
movq 0x20(%rsp), %rdi
movl 0x8(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x8(%rdi)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, 0x18(%rsp)
addq $0x28, %rdi
movslq 0xbc(%rsp), %rsi
callq 0x3740
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x3760
jmp 0x2c5b
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x2b77
movq 0x20(%rsp), %rdi
addq $0x28, %rdi
callq 0x35f0
testb $0x1, %al
jne 0x2e5e
movq 0x20(%rsp), %rdi
addq $0x10, %rdi
callq 0x35f0
testb $0x1, %al
jne 0x2e5e
movq 0x20(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x94(%rsp)
movq 0x20(%rsp), %rdi
movl 0x94(%rsp), %eax
movq %rax, 0x10(%rsp)
addq $0x28, %rdi
callq 0x37d0
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x2e5c
movq 0x20(%rsp), %rdi
addq $0x10, %rdi
callq 0x36e0
movq 0x20(%rsp), %rdi
movq %rax, 0x80(%rsp)
addq $0x10, %rdi
callq 0x3710
movq 0x20(%rsp), %rdi
movq %rax, 0x78(%rsp)
addq $0x28, %rdi
movl 0x94(%rsp), %eax
movl %eax, %esi
callq 0x3740
movq %rax, %rdx
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x3680
movq 0x20(%rsp), %rdi
movq %rax, 0x88(%rsp)
addq $0x10, %rdi
callq 0x3710
movq %rax, 0x70(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3640
testb $0x1, %al
jne 0x2d5f
jmp 0x2d64
jmp 0x2e44
movq 0x20(%rsp), %rsi
addq $0x10, %rsi
leaq 0x50(%rsp), %rdi
callq 0x3a20
movq 0x20(%rsp), %rsi
addq $0x28, %rsi
leaq 0x38(%rsp), %rdi
callq 0x3a20
jmp 0x2d8c
movl 0x94(%rsp), %edx
leaq 0x50(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2870
movl %eax, 0xc(%rsp)
jmp 0x2da8
leaq 0x38(%rsp), %rdi
callq 0x3590
leaq 0x50(%rsp), %rdi
callq 0x3590
movl 0xc(%rsp), %eax
movq 0x20(%rsp), %rdi
movl %eax, 0x6c(%rsp)
addq $0x28, %rdi
movl 0x94(%rsp), %eax
movl %eax, %esi
callq 0x3740
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x8(%rsp)
addq $0x10, %rdi
movslq 0x6c(%rsp), %rsi
callq 0x3740
movl 0x8(%rsp), %edx
movq %rax, %rcx
movq 0x20(%rsp), %rax
movl %edx, (%rcx)
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x2e44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0x2e35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x3590
leaq 0x50(%rsp), %rdi
callq 0x3590
jmp 0x2ec9
jmp 0x2e46
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x2cac
jmp 0x2e80
movq 0x6173(%rip), %rdi      # 0x8fd8
leaq 0x31a8(%rip), %rsi      # 0x6014
callq 0x20e0
movq %rax, %rdi
movq 0x614d(%rip), %rsi      # 0x8fc8
callq 0x2100
movq 0x6151(%rip), %rdi      # 0x8fd8
leaq 0x31b9(%rip), %rsi      # 0x6047
callq 0x20e0
movq %rax, %rdi
movq 0x20(%rsp), %rax
movl 0x8(%rax), %esi
callq 0x2180
movq %rax, %rdi
leaq 0x319f(%rip), %rsi      # 0x604c
callq 0x20e0
movq %rax, %rdi
movq 0x610c(%rip), %rsi      # 0x8fc8
callq 0x2100
addq $0xc8, %rsp
retq
movq 0x30(%rsp), %rdi
callq 0x2190
nopw %cs:(%rax,%rax)