// File: /workspace/github_cpp_makefile_star2_O1/iPapatsoris[P]Paging-Simulator/Launcher.cpp
// Function: main
int main(int argc, char **argv) {
	if (argc < 7) {
		cout << "Failure: usage: -a <algorithm> -f <frames> -q <quantum>" << endl;
		exit(EXIT_FAILURE);
	}

	string replacementAlgorithm = "";
	int frames = 0;
	int quantum = 0;
	int workingSetSize = 0;
	int maxReferences = -1;
	int frameSize = FRAME_SIZE;
	bool print = true;

	/* Argument parse */
	for (int i=1 ; i < argc ; i++) {
		if (!strcmp(argv[i],"-a")) {
			replacementAlgorithm = argv[++i];
			if (replacementAlgorithm.compare("lru") && replacementAlgorithm.compare("ws")) {
				cout << "Failure: algorithm should be either lru or ws" << endl;
				exit(EXIT_FAILURE);
			}
		}
		else if (!strcmp(argv[i], "-f")) {
			frames = atoi(argv[++i]);
		}
		else if (!strcmp(argv[i], "-q")) {
			quantum = atoi(argv[++i]);
		}
		else if (!strcmp(argv[i], "-w")) {
			workingSetSize = atoi(argv[++i]);
		}
		else if (!strcmp(argv[i], "-m")) {
			maxReferences = atoi(argv[++i]);
		}
	}

	if (! replacementAlgorithm.compare("") || !frames || !quantum) {
		cout << "Failure: usage: -a <algorithm> -f <frames> -q <quantum>" << endl;
		exit(EXIT_FAILURE);
	}
	if (!replacementAlgorithm.compare("ws") && !workingSetSize) {
		cout << "Failure: did not provide working set size with -w <window>" << endl;
		exit(EXIT_FAILURE);
	}
	if (!replacementAlgorithm.compare("ws") && workingSetSize > frames) {
			cout << "Failure: working set size should be less or equal to the number of frames" << endl;
			exit(EXIT_FAILURE);
		}

	Simulator sim(replacementAlgorithm, frames, frameSize, quantum, workingSetSize, maxReferences);
	sim.run();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
cmpl $0x6, %edi
jle 0x27e9
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x2c40(%rip), %rdx      # 0x51ce
leaq -0x68(%rbp), %rdi
movq %rdx, %rsi
callq 0x28b4
xorl %eax, %eax
movl %eax, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl %eax, -0x2c(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl $0x1000, -0x3c(%rbp)    # imm = 0x1000
movl $0x1, %r12d
movq %rbx, -0x48(%rbp)
movslq %r12d, %r15
movq (%rbx,%r15,8), %r13
movq %r13, %rdi
leaq 0x2a6e(%rip), %rsi      # 0x503c
callq 0x2200
testl %eax, %eax
je 0x2649
movq %r13, %rdi
leaq 0x2a90(%rip), %rsi      # 0x5071
callq 0x2200
testl %eax, %eax
je 0x26ac
movq %r13, %rdi
leaq 0x2a7c(%rip), %rsi      # 0x5074
callq 0x2200
testl %eax, %eax
je 0x26bf
movq %r13, %rdi
leaq 0x2a68(%rip), %rsi      # 0x5077
callq 0x2200
testl %eax, %eax
je 0x26db
movq %r13, %rdi
leaq 0x2a54(%rip), %rsi      # 0x507a
callq 0x2200
testl %eax, %eax
jne 0x26ec
leal 0x1(%r15), %r12d
movq 0x8(%rbx,%r15,8), %rdi
callq 0x2230
movl %eax, -0x38(%rbp)
jmp 0x26ec
movq %rbx, %rax
movl %r14d, %ebx
movq 0x8(%rax,%r15,8), %r13
movq -0x60(%rbp), %r15
movq %r13, %rdi
callq 0x20b0
leaq -0x68(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x2220
incl %r12d
movq %r14, %rdi
leaq 0x29bb(%rip), %rsi      # 0x503f
callq 0x2080
testl %eax, %eax
je 0x26d2
movq %r14, %rdi
leaq 0x29d7(%rip), %rsi      # 0x506e
callq 0x2080
testl %eax, %eax
movl %ebx, %r14d
movq -0x48(%rbp), %rbx
je 0x26ec
jmp 0x27c3
leal 0x1(%r15), %r12d
movq 0x8(%rbx,%r15,8), %rdi
callq 0x2230
movl %eax, -0x30(%rbp)
jmp 0x26ec
leal 0x1(%r15), %r12d
movq 0x8(%rbx,%r15,8), %rdi
callq 0x2230
movl %eax, -0x34(%rbp)
jmp 0x26ec
movl %ebx, %r14d
movq -0x48(%rbp), %rbx
jmp 0x26ec
leal 0x1(%r15), %r12d
movq 0x8(%rbx,%r15,8), %rdi
callq 0x2230
movl %eax, -0x2c(%rbp)
incl %r12d
cmpl %r14d, %r12d
jl 0x25bd
leaq 0x2acf(%rip), %rsi      # 0x51ce
leaq -0x68(%rbp), %rdi
callq 0x2080
testl %eax, %eax
je 0x280e
cmpl $0x0, -0x30(%rbp)
je 0x280e
cmpl $0x0, -0x34(%rbp)
je 0x280e
leaq 0x2943(%rip), %rsi      # 0x506e
leaq -0x68(%rbp), %rdi
callq 0x2080
orl -0x2c(%rbp), %eax
je 0x2834
leaq 0x292a(%rip), %rsi      # 0x506e
leaq -0x68(%rbp), %rdi
callq 0x2080
testl %eax, %eax
jne 0x275d
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x285a
leaq -0x38(%rbp), %rax
movq %rax, (%rsp)
leaq -0xd0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x30(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
leaq -0x34(%rbp), %r8
leaq -0x2c(%rbp), %r9
callq 0x2950
leaq -0xd0(%rbp), %rdi
callq 0x2b22
leaq -0xd0(%rbp), %rdi
callq 0x2a8a
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x27af
callq 0x2160
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x580e(%rip), %rdi      # 0x7fd8
leaq 0x2872(%rip), %rsi      # 0x5043
movl $0x2d, %edx
callq 0x21c0
movq 0x57f6(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x2804
movq 0x57e8(%rip), %rdi      # 0x7fd8
leaq 0x280d(%rip), %rsi      # 0x5004
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movl $0x1, %edi
callq 0x21e0
movq 0x57c3(%rip), %rdi      # 0x7fd8
leaq 0x27e8(%rip), %rsi      # 0x5004
movl $0x37, %edx
callq 0x21c0
movq 0x57ab(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x2804
movq 0x579d(%rip), %rdi      # 0x7fd8
leaq 0x283b(%rip), %rsi      # 0x507d
movl $0x3a, %edx
callq 0x21c0
movq 0x5785(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x2804
movq 0x5777(%rip), %rdi      # 0x7fd8
leaq 0x2850(%rip), %rsi      # 0x50b8
movl $0x49, %edx
callq 0x21c0
movq 0x575f(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x2804
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x2a8a
jmp 0x289a
jmp 0x2897
jmp 0x2897
jmp 0x2897
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x28ac
callq 0x2160
movq %rbx, %rdi
callq 0x2270