// File: eva23511[P]OS-Virtual-Memory-Management/main.cpp
// Function: ParseCommand(int, char**, int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void ParseCommand(int argc, char * argv[], int &num_frames, string &algo, string &input_filename, string &rand_filename) {
    
    if (argc < 3) {
        printf("Use this to run: ./mmu –f<num_frames> -a<algo> [-o<options>] inputfile randomfile\n");
        exit (EXIT_FAILURE);
    }
    
    int c;
    while ((c = getopt (argc, argv, "a:f:o:")) != -1) {
        switch(c) {
            case 'f':
                num_frames = atoi(optarg);
                break;
            case 'a':
                algo = string(optarg);
                break;
            case 'o':
                ParseOptions(string(optarg));
                break;
            case '?':
                printf("Unknown Option -%c\n", optopt);
                printf("Use this to run: ./mmu –f<num_frames> -a<algo> [-o<options>] inputfile randomfile\n");
                exit (EXIT_FAILURE);
                break;
        }
    }
    
    for (int index = optind; index < argc; index++) {
        if (index == argc - 2) {
            input_filename = argv[index];
        } else if (index == argc - 1) {
            rand_filename = argv[index];
        } else {
            printf("Non-option argument %s\n", argv[index]);
            printf("Use this to run: ./mmu –f<num_frames> -a<algo> [-o<options>] inputfile randomfile\n");
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpl $0x3, -0x4(%rbp)
jge 0x3990
leaq 0xa80c(%rip), %rdi      # 0xe18b
movb $0x0, %al
callq 0x3030
movl $0x1, %edi
callq 0x3220
jmp 0x3992
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xa840(%rip), %rdx      # 0xe1e0
callq 0x3080
movl %eax, -0x34(%rbp)
cmpl $-0x1, %eax
je 0x3b5a
movl -0x34(%rbp), %eax
movl %eax, -0x9c(%rbp)
subl $0x3f, %eax
je 0x3b26
jmp 0x39c5
movl -0x9c(%rbp), %eax
subl $0x61, %eax
je 0x3a0f
jmp 0x39d2
movl -0x9c(%rbp), %eax
subl $0x66, %eax
je 0x39f3
jmp 0x39df
movl -0x9c(%rbp), %eax
subl $0x6f, %eax
je 0x3a87
jmp 0x3b55
movq 0x115c6(%rip), %rax     # 0x14fc0
movq (%rax), %rdi
callq 0x32b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x3b55
movq 0x115aa(%rip), %rax     # 0x14fc0
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x3330
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x5880
jmp 0x3a49
movq -0x20(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x3230
leaq -0x58(%rbp), %rdi
callq 0x3150
leaq -0x59(%rbp), %rdi
callq 0x31f0
jmp 0x3b55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x31f0
jmp 0x3c18
movq 0x11532(%rip), %rax     # 0x14fc0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x3330
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0x90(%rbp), %rdi
callq 0x5880
jmp 0x3ac7
leaq -0x90(%rbp), %rdi
callq 0x4fd0
jmp 0x3ad5
leaq -0x90(%rbp), %rdi
callq 0x3150
leaq -0x91(%rbp), %rdi
callq 0x31f0
jmp 0x3b55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x3b15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3150
leaq -0x91(%rbp), %rdi
callq 0x31f0
jmp 0x3c18
movq 0x114a3(%rip), %rax     # 0x14fd0
movl (%rax), %esi
leaq 0xa6b1(%rip), %rdi      # 0xe1e7
movb $0x0, %al
callq 0x3030
leaq 0xa647(%rip), %rdi      # 0xe18b
movb $0x0, %al
callq 0x3030
movl $0x1, %edi
callq 0x3220
jmp 0x3992
movq 0x11477(%rip), %rax     # 0x14fd8
movl (%rax), %eax
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x3c0f
movl -0x98(%rbp), %eax
movl -0x4(%rbp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jne 0x3ba2
movq -0x10(%rbp), %rax
movslq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x28(%rbp), %rdi
callq 0x3270
jmp 0x3bf9
movl -0x98(%rbp), %eax
movl -0x4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3bcc
movq -0x10(%rbp), %rax
movslq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x30(%rbp), %rdi
callq 0x3270
jmp 0x3bf7
movq -0x10(%rbp), %rax
movslq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xa619(%rip), %rdi      # 0xe1fb
movb $0x0, %al
callq 0x3030
leaq 0xa59b(%rip), %rdi      # 0xe18b
movb $0x0, %al
callq 0x3030
jmp 0x3bf9
jmp 0x3bfb
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x3b69
addq $0xc0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x3320
nopw %cs:(%rax,%rax)