// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rdi), %rax
xorl %ecx, %ecx
movl %ecx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rcx, 0x28(%rdi)
leaq 0x30(%rdi), %r14
leaq 0x38(%rdi), %r13
movl %ecx, 0x38(%rdi)
movq %rcx, 0x40(%rdi)
movq %r13, 0x48(%rdi)
movq %r13, 0x50(%rdi)
movq %rcx, 0x58(%rdi)
leaq 0x60(%rdi), %rax
movq %rax, -0x40(%rbp)
leaq 0x70(%rdi), %rax
movq %rax, -0x58(%rbp)
movq %rax, 0x60(%rdi)
movq %rcx, 0x68(%rdi)
movb $0x0, 0x70(%rdi)
leaq 0x80(%rdi), %rax
movq %rax, 0x88(%rdi)
movq %rax, -0x50(%rbp)
movq %rax, 0x80(%rdi)
movq %rcx, 0x90(%rdi)
leaq -0x68(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x32ec
leaq 0x98(%rbx), %rdi
leaq -0x78(%rbp), %rsi
movq %rdi, -0x48(%rbp)
callq 0x3046
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x2a79
callq 0x2200
leaq 0x3b0(%rbx), %rax
xorl %ecx, %ecx
movl %ecx, 0x3b0(%rbx)
movq %rcx, 0x3b8(%rbx)
movq %rax, 0x3c0(%rbx)
movq %rax, 0x3c8(%rbx)
movq %rcx, 0x3d0(%rbx)
leaq 0x3d8(%rbx), %rax
movq %rax, 0x3e0(%rbx)
movq %rax, 0x3d8(%rbx)
movq %rcx, 0x3e8(%rbx)
movb %cl, 0x3f0(%rbx)
movl %ecx, 0x3f4(%rbx)
movb %cl, 0x3f8(%rbx)
leaq 0x252c(%rip), %rsi      # 0x5005
movq %r15, %rdi
callq 0x20c0
testl %eax, %eax
je 0x2af8
leaq 0x2546(%rip), %rsi      # 0x5032
movq %r15, %rdi
callq 0x20c0
testl %eax, %eax
jne 0x2b75
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x2150
leaq -0x38(%rbp), %r15
movl $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x30d6
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movb $0x0, 0x4(%rax)
movl -0x38(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x38(%rbp)
cmpl $0xff, %eax
jl 0x2b0f
leaq -0x2c(%rbp), %r15
movl $0x0, (%r15)
leaq -0x38(%rbp), %r12
movq %r14, -0x38(%rbp)
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x358e
movl -0x2c(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x2c(%rbp)
cmpl $0x3f, %eax
jl 0x2b43
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x2120
movq %rax, %r12
leaq 0x2481(%rip), %rsi      # 0x500a
movq %rax, %rdi
callq 0x23c0
movq 0x5438(%rip), %rsi      # 0x7fd0
movq 0x5421(%rip), %rdx      # 0x7fc0
movq %r12, %rdi
callq 0x2360
movq %rax, %r15
movq %r12, %rdi
callq 0x21c0
jmp 0x2bd3
movq %rax, %r15
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x2be8
callq 0x2200
jmp 0x2be8
movq %rax, %r15
jmp 0x2be8
jmp 0x2bd0
jmp 0x2bd0
movq %rax, %r15
leaq 0x3a8(%rbx), %rdi
callq 0x313e
movq -0x48(%rbp), %rdi
callq 0x317a
movq -0x50(%rbp), %r13
movq (%r13), %rdi
cmpq %r13, %rdi
je 0x2c05
movq (%rdi), %r12
callq 0x2200
movq %r12, %rdi
cmpq %r13, %r12
jne 0x2bf5
movq -0x40(%rbp), %rax
movq (%rax), %rdi
cmpq -0x58(%rbp), %rdi
je 0x2c17
callq 0x2200
movq %r14, %rdi
callq 0x323c
movq %rbx, %rdi
callq 0x3294
movq %r15, %rdi
callq 0x2380
nop