// File: /workspace/github_cpp_makefile_star2_O2/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 0x2711
movq %rsi, %r15
movl %edi, %r12d
leaq 0x2c9f(%rip), %rsi      # 0x5195
leaq -0x68(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
movq %rdi, %r14
callq 0x20c0
andl $0x0, -0x44(%rbp)
andl $0x0, -0x40(%rbp)
andl $0x0, -0x3c(%rbp)
orl $-0x1, -0x38(%rbp)
movl $0x1000, -0x48(%rbp)    # imm = 0x1000
pushq $0x1
popq %rbx
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl %r12d, %ebx
jge 0x2630
movslq %ebx, %rax
movq (%r15,%rax,8), %rcx
cmpb $0x2d, (%rcx)
jne 0x2629
cmpb $0x61, 0x1(%rcx)
jne 0x255d
cmpb $0x0, 0x2(%rcx)
je 0x25b2
cmpb $0x66, 0x1(%rcx)
jne 0x256d
cmpb $0x0, 0x2(%rcx)
je 0x25ef
cmpb $0x71, 0x1(%rcx)
jne 0x257d
cmpb $0x0, 0x2(%rcx)
je 0x2603
cmpb $0x77, 0x1(%rcx)
jne 0x258d
cmpb $0x0, 0x2(%rcx)
je 0x2617
cmpb $0x6d, 0x1(%rcx)
jne 0x2629
cmpb $0x0, 0x2(%rcx)
jne 0x2629
incl %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2200
movl %eax, -0x38(%rbp)
jmp 0x2629
movq %r14, %r13
movq 0x8(%r15,%rax,8), %rsi
movq %r14, %rdi
callq 0x2280
incl %ebx
movq %r13, %rdi
leaq 0x2a6e(%rip), %rsi      # 0x503c
callq 0x2090
testl %eax, %eax
je 0x2629
movq %r13, %rdi
leaq 0x2a8a(%rip), %rsi      # 0x506b
callq 0x2090
testl %eax, %eax
je 0x2629
jmp 0x26f4
incl %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2200
movl %eax, -0x34(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2629
incl %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2200
movl %eax, -0x30(%rbp)
movl %eax, -0x40(%rbp)
jmp 0x2629
incl %ebx
movq 0x8(%r15,%rax,8), %rdi
callq 0x2200
movl %eax, -0x2c(%rbp)
movl %eax, -0x3c(%rbp)
incl %ebx
jmp 0x2538
leaq 0x2b5e(%rip), %rsi      # 0x5195
leaq -0x68(%rbp), %rdi
callq 0x2090
testl %eax, %eax
movl -0x34(%rbp), %r14d
je 0x2734
testl %r14d, %r14d
je 0x2734
cmpl $0x0, -0x30(%rbp)
je 0x2734
leaq 0x2a05(%rip), %rsi      # 0x506b
leaq -0x68(%rbp), %rdi
callq 0x2090
movl -0x2c(%rbp), %ebx
orl %ebx, %eax
je 0x2751
leaq 0x29ea(%rip), %rsi      # 0x506b
leaq -0x68(%rbp), %rdi
callq 0x2090
testl %eax, %eax
jne 0x2697
cmpl %r14d, %ebx
jg 0x276e
leaq -0x38(%rbp), %rax
movq %rax, (%rsp)
leaq -0xd0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x44(%rbp), %rdx
leaq -0x48(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x3c(%rbp), %r9
callq 0x27b8
leaq -0xd0(%rbp), %rdi
callq 0x2940
leaq -0xd0(%rbp), %rdi
callq 0x28d2
leaq -0x68(%rbp), %rdi
callq 0x20d0
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x58dd(%rip), %rdi      # 0x7fd8
leaq 0x293e(%rip), %rsi      # 0x5040
callq 0x2180
movq %rax, %rdi
callq 0x20e0
jmp 0x272c
movq 0x58c0(%rip), %rdi      # 0x7fd8
leaq 0x28e5(%rip), %rsi      # 0x5004
callq 0x2180
movq %rax, %rdi
callq 0x20e0
pushq $0x1
popq %rdi
callq 0x21c0
movq 0x589d(%rip), %rdi      # 0x7fd8
leaq 0x28c2(%rip), %rsi      # 0x5004
callq 0x2180
movq %rax, %rdi
callq 0x20e0
jmp 0x272c
movq 0x5880(%rip), %rdi      # 0x7fd8
leaq 0x290f(%rip), %rsi      # 0x506e
callq 0x2180
movq %rax, %rdi
callq 0x20e0
jmp 0x272c
movq 0x5863(%rip), %rdi      # 0x7fd8
leaq 0x292d(%rip), %rsi      # 0x50a9
callq 0x2180
movq %rax, %rdi
callq 0x20e0
jmp 0x272c
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x28d2
jmp 0x27a5
jmp 0x27a2
jmp 0x27a2
jmp 0x27a2
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2250
nop