// File: /workspace/github_cpp_makefile_star2_O2/shreyas-gopalakrishna[P]Concurrent-Skip-list/main.cpp
// Function: main
int main(int argc, char *argv[]){

    static struct option long_options[] = {
        {"name", no_argument, NULL, 'n'},
        {"operation", required_argument, NULL, 'o'},
        {"help", no_argument, NULL, 'h'},
        {0, 0, 0, 0}
    };

    //Variables for options
    bool name = false;
    int max_number = -1;
    string operation = "";
    bool help = false;

    while (true) {
        int option_index = 0;
        int flag_char = getopt_long(argc, argv, "i:t:", long_options, &option_index);
        if (flag_char == -1) {
          break;
        }

        switch (flag_char) {
            case 'n':
                name = true;
                break;
            case 'o':
                operation = std::string(optarg);
                break;
            case 'h':
                help = true;
                break;
            case 't':
                num_threads = stoi(optarg);
                break;
            case 'i':
                max_number = stoi(optarg);
                break;
            case '?':
                break;
            default:
                exit(EXIT_FAILURE);
        }
    }

    if(name){
        cout << "\nShreyas Gopalakrishna\n";
    }

    if(help){
        show_usage();
    }

	if(argc > 2){
	    if(operation == "" || max_number <= 0 || num_threads < 1 ){
	        show_usage();
	    }else{

            generate_input(max_number);
            skiplist = SkipList(numbers_insert.size(), 0.5);

	        if(operation == "separate"){
                concurrent_skiplist_seperate();
	        }
	        else if (operation == "combined"){
                concurrent_skiplist_combined();
	        }else{
	            cout << "Invalid operation type \n";
	            show_usage();
	        }
	    }
    }else{
        show_usage();
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movl %edi, %ebx
leaq 0x2c84(%rip), %rsi      # 0x6049
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %r12
movq %r12, %rdx
callq 0x36a0
pushq $-0x1
popq %r15
movq $0x0, 0x8(%rsp)
leaq 0x4(%rsp), %rbp
leaq 0x2c18(%rip), %r13      # 0x6008
movq $0x0, 0x10(%rsp)
andl $0x0, 0x4(%rsp)
movl %ebx, %edi
movq %r14, %rsi
leaq 0x31d3(%rip), %rdx      # 0x65dd
leaq 0x6dcf(%rip), %rcx      # 0xa1e0
movq %rbp, %r8
callq 0x22f0
leal -0x68(%rax), %ecx
cmpl $0x7, %ecx
ja 0x3434
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x33f9
cmpl $0x3f, %eax
je 0x33f9
cmpl $0x74, %eax
jne 0x34d7
movq 0x6b6f(%rip), %rax      # 0x9fb8
movq (%rax), %rsi
movq %r12, %rdi
leaq 0x3(%rsp), %rdx
callq 0x36a0
movq %r12, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x38b1
cltq
movq %rax, 0x6d61(%rip)      # 0xa1d0
jmp 0x34ca
movq 0x6b40(%rip), %rax      # 0x9fb8
movq (%rax), %rsi
movq %r12, %rdi
leaq 0x3(%rsp), %rdx
callq 0x36a0
movq %r12, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x38b1
movl %eax, %r15d
jmp 0x34ca
movb $0x1, %al
movq %rax, 0x8(%rsp)
jmp 0x33f9
movq 0x6b0b(%rip), %rax      # 0x9fb8
movq (%rax), %rsi
movq %r12, %rdi
leaq 0x3(%rsp), %rdx
callq 0x36a0
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x2250
movq %r12, %rdi
callq 0x20d0
jmp 0x33f9
cmpl $-0x1, %eax
jne 0x35cd
testb $0x1, 0x8(%rsp)
je 0x34fa
movq 0x6ada(%rip), %rdi      # 0x9fc8
leaq 0x30ed(%rip), %rsi      # 0x65e2
callq 0x21e0
cmpl $0x3, %ebx
setl %al
orb 0x10(%rsp), %al
testb $0x1, %al
jne 0x35e8
leaq 0x2b36(%rip), %rsi      # 0x6049
leaq 0x18(%rsp), %rdi
callq 0x38cd
testb %al, %al
jne 0x35e8
testl %r15d, %r15d
jle 0x35e8
cmpq $0x0, 0x6c9a(%rip)      # 0xa1d0
je 0x35e8
movl %r15d, %edi
callq 0x2661
movq 0x6d4d(%rip), %rsi      # 0xa298
subq 0x6d3e(%rip), %rsi      # 0xa290
shrq $0x2, %rsi
leaq 0x38(%rsp), %rdi
movss 0x2aa1(%rip), %xmm0     # 0x6004
callq 0x4630
leaq 0x38(%rsp), %rdi
movups (%rdi), %xmm0
movups %xmm0, 0x6d09(%rip)     # 0xa280
callq 0x533c
leaq 0x3077(%rip), %rsi      # 0x65fa
leaq 0x18(%rsp), %rdi
callq 0x38cd
testb %al, %al
je 0x3598
callq 0x2adf
jmp 0x35b2
leaq 0x3064(%rip), %rsi      # 0x6603
leaq 0x18(%rsp), %rdi
callq 0x38cd
testb %al, %al
je 0x35d5
callq 0x31ec
leaq 0x18(%rsp), %rdi
callq 0x20d0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
callq 0x2240
movq 0x69ec(%rip), %rdi      # 0x9fc8
leaq 0x3029(%rip), %rsi      # 0x660c
callq 0x21e0
callq 0x259c
jmp 0x35f7
jmp 0x35f7
jmp 0x35fc
jmp 0x35f7
jmp 0x35f7
movq %rax, %rbx
jmp 0x3609
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x20d0
leaq 0x18(%rsp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2320
nop