// File: 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
subq $0x100, %rsp            # imm = 0x100
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x7, -0x8(%rbp)
jge 0x263b
movq 0x99c2(%rip), %rdi      # 0xbfd8
leaq 0x59e7(%rip), %rsi      # 0x8004
callq 0x21e0
movq %rax, %rdi
movq 0x999c(%rip), %rsi      # 0xbfc8
callq 0x2200
movl $0x1, %edi
callq 0x2230
leaq -0x31(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x2310
movq -0xd0(%rbp), %rdx
leaq 0x5b4b(%rip), %rsi      # 0x81a4
leaq -0x30(%rbp), %rdi
callq 0x2260
jmp 0x2664
leaq -0x31(%rbp), %rdi
callq 0x2210
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl $0x1000, -0x58(%rbp)    # imm = 0x1000
movb $0x1, -0x59(%rbp)
movl $0x1, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x2881
movq -0x10(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x5982(%rip), %rsi      # 0x803c
callq 0x2280
cmpl $0x0, %eax
jne 0x277c
movq -0x10(%rbp), %rax
movslq -0x60(%rbp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, -0x60(%rbp)
movq 0x8(%rax,%rcx,8), %rsi
leaq -0x30(%rbp), %rdi
callq 0x2250
jmp 0x26e7
leaq -0x30(%rbp), %rdi
leaq 0x594d(%rip), %rsi      # 0x803f
callq 0x20c0
cmpl $0x0, %eax
je 0x2777
leaq -0x30(%rbp), %rdi
leaq 0x5967(%rip), %rsi      # 0x806e
callq 0x20c0
cmpl $0x0, %eax
je 0x2777
movq 0x98c0(%rip), %rdi      # 0xbfd8
leaq 0x5924(%rip), %rsi      # 0x8043
callq 0x21e0
movq %rax, -0xd8(%rbp)
jmp 0x272d
movq -0xd8(%rbp), %rdi
movq 0x988d(%rip), %rsi      # 0xbfc8
callq 0x2200
jmp 0x2742
movl $0x1, %edi
callq 0x2230
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x2210
jmp 0x2a07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x29fe
jmp 0x2871
movq -0x10(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x58e2(%rip), %rsi      # 0x8071
callq 0x2280
cmpl $0x0, %eax
jne 0x27ba
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x60(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22b0
movl %eax, -0x48(%rbp)
jmp 0x286f
movq -0x10(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x58a7(%rip), %rsi      # 0x8074
callq 0x2280
cmpl $0x0, %eax
jne 0x27f5
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x60(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22b0
movl %eax, -0x4c(%rbp)
jmp 0x286d
movq -0x10(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x586f(%rip), %rsi      # 0x8077
callq 0x2280
cmpl $0x0, %eax
jne 0x2830
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x60(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22b0
movl %eax, -0x50(%rbp)
jmp 0x286b
movq -0x10(%rbp), %rax
movslq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x5837(%rip), %rsi      # 0x807a
callq 0x2280
cmpl $0x0, %eax
jne 0x2869
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x60(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22b0
movl %eax, -0x54(%rbp)
jmp 0x286b
jmp 0x286d
jmp 0x286f
jmp 0x2871
jmp 0x2873
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x269b
leaq -0x30(%rbp), %rdi
leaq 0x5918(%rip), %rsi      # 0x81a4
callq 0x20c0
cmpl $0x0, %eax
je 0x28a2
cmpl $0x0, -0x48(%rbp)
je 0x28a2
cmpl $0x0, -0x4c(%rbp)
jne 0x28dd
movq 0x972f(%rip), %rdi      # 0xbfd8
leaq 0x5754(%rip), %rsi      # 0x8004
callq 0x21e0
movq %rax, -0xe0(%rbp)
jmp 0x28be
movq -0xe0(%rbp), %rdi
movq 0x96fc(%rip), %rsi      # 0xbfc8
callq 0x2200
jmp 0x28d3
movl $0x1, %edi
callq 0x2230
leaq -0x30(%rbp), %rdi
leaq 0x5786(%rip), %rsi      # 0x806e
callq 0x20c0
cmpl $0x0, %eax
jne 0x2933
cmpl $0x0, -0x50(%rbp)
jne 0x2933
movq 0x96d9(%rip), %rdi      # 0xbfd8
leaq 0x5777(%rip), %rsi      # 0x807d
callq 0x21e0
movq %rax, -0xe8(%rbp)
jmp 0x2914
movq -0xe8(%rbp), %rdi
movq 0x96a6(%rip), %rsi      # 0xbfc8
callq 0x2200
jmp 0x2929
movl $0x1, %edi
callq 0x2230
leaq -0x30(%rbp), %rdi
leaq 0x5730(%rip), %rsi      # 0x806e
callq 0x20c0
cmpl $0x0, %eax
jne 0x298b
movl -0x50(%rbp), %eax
cmpl -0x48(%rbp), %eax
jle 0x298b
movq 0x9681(%rip), %rdi      # 0xbfd8
leaq 0x575a(%rip), %rsi      # 0x80b8
callq 0x21e0
movq %rax, -0xf0(%rbp)
jmp 0x296c
movq -0xf0(%rbp), %rdi
movq 0x964e(%rip), %rsi      # 0xbfc8
callq 0x2200
jmp 0x2981
movl $0x1, %edi
callq 0x2230
movq %rsp, %rax
leaq -0x54(%rbp), %rcx
movq %rcx, (%rax)
leaq -0xc8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x48(%rbp), %rdx
leaq -0x58(%rbp), %rcx
leaq -0x4c(%rbp), %r8
leaq -0x50(%rbp), %r9
callq 0x2a10
jmp 0x29b7
leaq -0xc8(%rbp), %rdi
callq 0x2c80
jmp 0x29c5
leaq -0xc8(%rbp), %rdi
callq 0x2bc0
leaq -0x30(%rbp), %rdi
callq 0x2140
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x2bc0
leaq -0x30(%rbp), %rdi
callq 0x2140
movq -0x40(%rbp), %rdi
callq 0x2300