// File: iPapatsoris[P]Paging-Simulator/Simulator.cpp
// Function: Simulator::run()
void Simulator::run() {
	ifstream trace1;
	ifstream trace2;
	trace1.open("bzip.trace", ios::in);
	trace2.open("gcc.trace", ios::in);

	bool processSwitch = false;

	/* Receive page requests */
	Address *address;
	while ((address = this->getTrace(trace1, trace2, processSwitch)) != NULL) {
		statistics.pageRequests++;
		//invertedPageTable.print();
		//cout << "Trace: " << address->toString() << endl;
		address->print();
		if (! replacementAlgorithm.compare("lru")) {
			this->runLRU(address);
		}
		else if (! replacementAlgorithm.compare("ws")) {
			this->runWorkingSet(address, processSwitch);
		}
	}
	cout << "\nFrames: " << frames << statistics.toString() << endl;
	trace1.close();
	trace2.close();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x480, %rsp            # imm = 0x480
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x458(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x2220
leaq -0x418(%rbp), %rdi
callq 0x2220
jmp 0x2cb4
leaq 0x5447(%rip), %rsi      # 0x8102
leaq -0x210(%rbp), %rdi
movl $0x8, %edx
callq 0x2150
jmp 0x2cce
leaq 0x5438(%rip), %rsi      # 0x810d
leaq -0x418(%rbp), %rdi
movl $0x8, %edx
callq 0x2150
jmp 0x2ce8
movb $0x0, -0x425(%rbp)
movq -0x458(%rbp), %rdi
leaq -0x210(%rbp), %rsi
leaq -0x418(%rbp), %rdx
leaq -0x425(%rbp), %rcx
callq 0x2f00
movq %rax, -0x460(%rbp)
jmp 0x2d19
movq -0x460(%rbp), %rax
movq %rax, -0x430(%rbp)
cmpq $0x0, %rax
je 0x2de8
movq -0x458(%rbp), %rax
movl 0x58(%rax), %ecx
incl %ecx
movl %ecx, 0x58(%rax)
movq -0x430(%rbp), %rdi
callq 0x45d0
jmp 0x2d4e
movq -0x458(%rbp), %rdi
leaq 0x52e3(%rip), %rsi      # 0x803f
callq 0x20c0
cmpl $0x0, %eax
jne 0x2dab
movq -0x458(%rbp), %rdi
movq -0x430(%rbp), %rsi
callq 0x31f0
jmp 0x2d7b
jmp 0x2de3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x420(%rbp)
movl %eax, -0x424(%rbp)
jmp 0x2ee0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x420(%rbp)
movl %eax, -0x424(%rbp)
jmp 0x2ed4
movq -0x458(%rbp), %rdi
leaq 0x52b5(%rip), %rsi      # 0x806e
callq 0x20c0
cmpl $0x0, %eax
jne 0x2de1
movq -0x458(%rbp), %rdi
movq -0x430(%rbp), %rsi
leaq -0x425(%rbp), %rdx
callq 0x33a0
jmp 0x2ddf
jmp 0x2de1
jmp 0x2de3
jmp 0x2cef
movq 0x91e9(%rip), %rdi      # 0xbfd8
leaq 0x5321(%rip), %rsi      # 0x8117
callq 0x21e0
movq %rax, -0x468(%rbp)
jmp 0x2e04
movq -0x468(%rbp), %rdi
movq -0x458(%rbp), %rax
movl 0x20(%rax), %esi
callq 0x22f0
movq %rax, -0x470(%rbp)
jmp 0x2e23
movq -0x458(%rbp), %rsi
addq $0x58, %rsi
leaq -0x450(%rbp), %rdi
callq 0x6fa0
jmp 0x2e3c
movq -0x470(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0x21b0
movq %rax, -0x478(%rbp)
jmp 0x2e58
movq -0x478(%rbp), %rdi
movq 0x9162(%rip), %rsi      # 0xbfc8
callq 0x2200
jmp 0x2e6d
leaq -0x450(%rbp), %rdi
callq 0x2140
leaq -0x210(%rbp), %rdi
callq 0x2080
jmp 0x2e87
leaq -0x418(%rbp), %rdi
callq 0x2080
jmp 0x2e95
leaq -0x418(%rbp), %rdi
callq 0x20a0
leaq -0x210(%rbp), %rdi
callq 0x20a0
addq $0x480, %rsp            # imm = 0x480
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x420(%rbp)
movl %eax, -0x424(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x2140
leaq -0x418(%rbp), %rdi
callq 0x20a0
leaq -0x210(%rbp), %rdi
callq 0x20a0
movq -0x420(%rbp), %rdi
callq 0x2300
nopl (%rax,%rax)