// File: yiboyang[P]VirtualMemory/PageTable.cpp
// Function: PageTable::PageTable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
PageTable::PageTable(const string& pageReplacementPolicy, const string& backingStorePath) : bs(backingStorePath) {
	if (!(pageReplacementPolicy == "FIFO" || pageReplacementPolicy == "LRU"))
		throw invalid_argument("Page replacement policy must be FIFO or LRU");
	else
		this->pageReplacementPolicy = pageReplacementPolicy;

	// initialize all page entries such that they all point to frame # -1 with dirty bit set to false
	for (int i = 0; i < NUM_LOGICAL_MEM_FRAMES; i++)
		pt[i] = make_pair(-1, false);

	// initialize free frames set; at first all frames are free
	for (int j = 0; j < NUM_PHYSICAL_MEM_FRAMES; j++)
		fs.insert(fs.end(), j);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x80(%rbp)
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
callq 0x62c0
movq -0x80(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x98(%rbp)
callq 0x62e0
movq -0x80(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x90(%rbp)
callq 0x3340
movq -0x80(%rbp), %rdi
subq $-0x80, %rdi
movq %rdi, -0x88(%rbp)
callq 0x6300
movq -0x80(%rbp), %rax
addq $0x98, %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x3120
jmp 0x5ba7
movq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x6320
jmp 0x5bb6
leaq -0x38(%rbp), %rdi
callq 0x31c0
movq -0xa0(%rbp), %rdi
addq $0x3a8, %rdi            # imm = 0x3A8
movq %rdi, -0xb0(%rbp)
callq 0x6420
movq -0xa0(%rbp), %rax
movb $0x0, 0x3f0(%rax)
movl $0x0, 0x3f4(%rax)
movb $0x0, 0x3f8(%rax)
movq -0x10(%rbp), %rdi
leaq 0x5402(%rip), %rsi      # 0xb005
callq 0x6450
movb %al, -0xa1(%rbp)
jmp 0x5c10
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x5ce5
jmp 0x5c20
movq -0x10(%rbp), %rdi
leaq 0x5407(%rip), %rsi      # 0xb032
callq 0x6450
movb %al, -0xb1(%rbp)
jmp 0x5c38
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x5ce5
jmp 0x5c48
movl $0x10, %edi
callq 0x3150
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
leaq 0x53a4(%rip), %rsi      # 0xb00a
callq 0x3430
jmp 0x5c6d
movq -0xc0(%rbp), %rdi
movq 0xb355(%rip), %rsi      # 0x10fd0
movq 0xb33e(%rip), %rdx      # 0x10fc0
callq 0x33d0
jmp 0x5e24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5dee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31c0
jmp 0x5dee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5dd9
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x31f0
jmp 0x5dd9
movq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x60, %rdi
callq 0x3030
jmp 0x5cfb
jmp 0x5cfd
movl $0x0, -0x48(%rbp)
cmpl $0x100, -0x48(%rbp)     # imm = 0x100
jge 0x5d75
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movb $0x0, -0x55(%rbp)
leaq -0x54(%rbp), %rdi
leaq -0x55(%rbp), %rsi
callq 0x6480
movq %rax, -0xc8(%rbp)
jmp 0x5d2e
movq -0xa0(%rbp), %rdi
movq -0xc8(%rbp), %rax
movl %eax, %ecx
movl %ecx, -0x50(%rbp)
shrq $0x20, %rax
movb %al, -0x4c(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x64b0
movq %rax, -0xd0(%rbp)
jmp 0x5d5a
movq -0xd0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x6590
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x5d04
movl $0x0, -0x5c(%rbp)
cmpl $0x40, -0x5c(%rbp)
jge 0x5dd0
movq -0xa0(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0xe0(%rbp)
callq 0x6610
movq -0xe0(%rbp), %rdi
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq 0x65c0
movq %rax, -0xd8(%rbp)
jmp 0x5dba
movq -0xd8(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x5d7c
addq $0xe0, %rsp
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x6640
movq -0x78(%rbp), %rdi
callq 0x6670
movq -0x88(%rbp), %rdi
callq 0x3f50
movq -0x90(%rbp), %rdi
callq 0x31c0
movq -0x98(%rbp), %rdi
callq 0x66c0
movq -0x80(%rbp), %rdi
callq 0x66e0
movq -0x40(%rbp), %rdi
callq 0x33f0
nopw %cs:(%rax,%rax)