// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
cmpl $0x6, %edi
jle 0x27c9
movq %rsi, %r15
movl %edi, %r12d
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x2c41(%rip), %rdx      # 0x51bf
leaq -0x70(%rbp), %r14
movq %r14, %rdi
movq %rdx, %rsi
callq 0x2894
xorl %eax, %eax
movl %eax, -0x40(%rbp)
movl %eax, -0x3c(%rbp)
movq $0x0, -0x50(%rbp)
movl %eax, -0x38(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0x1000, -0x44(%rbp)    # imm = 0x1000
movl $0x1, %ebx
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movslq %ebx, %rax
movq (%r15,%rax,8), %rcx
cmpb $0x2d, (%rcx)
jne 0x26ca
cmpb $0x61, 0x1(%rcx)
jne 0x25dd
cmpb $0x0, 0x2(%rcx)
je 0x2636
cmpb $0x66, 0x1(%rcx)
jne 0x25ed
cmpb $0x0, 0x2(%rcx)
je 0x268c
cmpb $0x71, 0x1(%rcx)
jne 0x25fd
cmpb $0x0, 0x2(%rcx)
je 0x26a1
cmpb $0x77, 0x1(%rcx)
jne 0x260d
cmpb $0x0, 0x2(%rcx)
je 0x26b6
cmpb $0x6d, 0x1(%rcx)
jne 0x26ca
cmpb $0x0, 0x2(%rcx)
jne 0x26ca
leal 0x1(%rax), %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2220
movl %eax, -0x34(%rbp)
jmp 0x26ca
movq 0x8(%r15,%rax,8), %r13
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %r13, %rdi
callq 0x20b0
movq %r14, %rdi
xorl %esi, %esi
movq -0x78(%rbp), %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x2210
incl %ebx
movq %r14, %rdi
leaq 0x29d1(%rip), %rsi      # 0x503c
callq 0x2080
testl %eax, %eax
je 0x26ca
movq %r14, %rdi
leaq 0x29ed(%rip), %rsi      # 0x506b
callq 0x2080
testl %eax, %eax
je 0x26ca
jmp 0x27a3
leal 0x1(%rax), %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2220
movl %eax, -0x30(%rbp)
movl %eax, -0x40(%rbp)
jmp 0x26ca
leal 0x1(%rax), %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2220
movl %eax, -0x2c(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x26ca
leal 0x1(%rax), %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2220
movq %rax, -0x50(%rbp)
movl %eax, -0x38(%rbp)
incl %ebx
cmpl %r12d, %ebx
jl 0x25c1
leaq 0x2ae3(%rip), %rsi      # 0x51bf
leaq -0x70(%rbp), %rdi
callq 0x2080
testl %eax, %eax
movl -0x30(%rbp), %r14d
je 0x27ee
testl %r14d, %r14d
je 0x27ee
cmpl $0x0, -0x2c(%rbp)
je 0x27ee
leaq 0x2960(%rip), %rsi      # 0x506b
leaq -0x70(%rbp), %rdi
callq 0x2080
movq -0x50(%rbp), %rbx
orl %ebx, %eax
je 0x2814
leaq 0x2944(%rip), %rsi      # 0x506b
leaq -0x70(%rbp), %rdi
callq 0x2080
testl %eax, %eax
jne 0x273d
cmpl %r14d, %ebx
jg 0x283a
leaq -0x34(%rbp), %rax
movq %rax, (%rsp)
leaq -0xe0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x40(%rbp), %rdx
leaq -0x44(%rbp), %rcx
leaq -0x3c(%rbp), %r8
leaq -0x38(%rbp), %r9
callq 0x2934
leaq -0xe0(%rbp), %rdi
callq 0x2b06
leaq -0xe0(%rbp), %rdi
callq 0x2a6e
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x278f
callq 0x2160
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x582e(%rip), %rdi      # 0x7fd8
leaq 0x288f(%rip), %rsi      # 0x5040
movl $0x2d, %edx
callq 0x21c0
movq 0x5816(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x27e4
movq 0x5808(%rip), %rdi      # 0x7fd8
leaq 0x282d(%rip), %rsi      # 0x5004
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movl $0x1, %edi
callq 0x21e0
movq 0x57e3(%rip), %rdi      # 0x7fd8
leaq 0x2808(%rip), %rsi      # 0x5004
movl $0x37, %edx
callq 0x21c0
movq 0x57cb(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x27e4
movq 0x57bd(%rip), %rdi      # 0x7fd8
leaq 0x284c(%rip), %rsi      # 0x506e
movl $0x3a, %edx
callq 0x21c0
movq 0x57a5(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x27e4
movq 0x5797(%rip), %rdi      # 0x7fd8
leaq 0x2861(%rip), %rsi      # 0x50a9
movl $0x49, %edx
callq 0x21c0
movq 0x577f(%rip), %rdi      # 0x7fd8
callq 0x20c0
jmp 0x27e4
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x2a6e
jmp 0x287a
jmp 0x2877
jmp 0x2877
jmp 0x2877
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x288c
callq 0x2160
movq %rbx, %rdi
callq 0x2260