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

    cout << "\n---------- Unit Test - 1 ----------" << endl;

    cout << "\nThis Unit test uses 4 Threads. Numbers (1-30) are inserted into the skip list parallelly." << endl;
    cout << "Then a few numbers at random are removed from the skip list parallelly. And next a few numbers are searched in the skip list." << endl;
    cout << "Finally, few Range operations are done in the skip list parallelly. The output is dislayed after each step for verification." << endl;
    cout << "This Unit test displays the output. Output may be interleaved since multiple threads tend to print together." << endl;
    

	generate_input(30);

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

    vector<thread> threads;

    cout << "\n---------- Numbers inserted parallelly ----------" << endl;

    for (auto i = numbers_insert.begin(); i != numbers_insert.end(); ++i)
    std::cout << *i << ' ';
    cout << endl;

    // insert
    int chunk_size = ceil(float(numbers_insert.size()) / num_threads);
    for(size_t i = 0; i < numbers_insert.size(); i = i + chunk_size){
        threads.push_back(thread(skiplist_add, i, i+chunk_size));
    }
    for (auto &th : threads) {
        th.join();
    }
    threads.clear();

    cout << "\n---------- Skip list after insert ----------" << endl;
    skiplist.display();


    cout << "\n---------- Numbers deleted parallelly ----------" << endl;

    for (auto i = numbers_delete.begin(); i != numbers_delete.end(); ++i)
    std::cout << *i << ' ';
    cout << endl;

    // delete
    chunk_size = ceil(float(numbers_delete.size()) / num_threads);
    for(size_t i = 0; i < numbers_delete.size(); i = i + chunk_size){
        threads.push_back(thread(skiplist_remove, i, i+chunk_size));
    }
    for (auto &th : threads) {
        th.join();
    }
    threads.clear();

    cout << "\n---------- Skip list after delete ----------" << endl;
    skiplist.display();

    cout << "\n---------- Numbers searched parallelly ----------" << endl;

    for (auto i = numbers_get.begin(); i != numbers_get.end(); ++i)
    std::cout << *i << ' ';
    cout << endl;

    // search
    chunk_size = ceil(float(numbers_get.size()) / num_threads);
    for(size_t i = 0; i < numbers_get.size(); i = i + chunk_size){
        threads.push_back(thread(skiplist_search, i, i+chunk_size));
    }
    for (auto &th : threads) {
        th.join();
    }
    threads.clear();

    cout << "\n---------- Range between random numbers in Skip list parallely ---------- " << endl;
    // range
    for(size_t i = 0; i < num_threads; i++){
        threads.push_back(thread(skiplist_range, numbers_range[i].first, numbers_range[i].second));
    }
    for (auto &th : threads) {
        th.join();
    }
	
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x628f(%rip), %rbx      # 0x8fd0
leaq 0x3311(%rip), %rsi      # 0x6059
movl $0x24, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x32fb(%rip), %rsi      # 0x607e
movl $0x5a, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x331b(%rip), %rsi      # 0x60d9
movl $0x7d, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x335e(%rip), %rsi      # 0x6157
movl $0x7c, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x33a0(%rip), %rsi      # 0x61d4
movl $0x6c, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movl $0x1e, %edi
callq 0x255c
movq 0x634f(%rip), %rsi      # 0x91c8
subq 0x6340(%rip), %rsi      # 0x91c0
shrq $0x2, %rsi
leaq 0x10(%rsp), %r14
movss 0x3173(%rip), %xmm0     # 0x6004
movq %r14, %rdi
callq 0x43ac
movups (%r14), %xmm0
movups %xmm0, 0x630c(%rip)     # 0x91b0
movq %r14, %rdi
callq 0x539a
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
leaq 0x337f(%rip), %rsi      # 0x6241
movl $0x32, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x60e3(%rip), %rbx      # 0x8fd0
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x62bc(%rip), %r12      # 0x91c0
cmpq 0x62bd(%rip), %r12      # 0x91c8
je 0x2f44
movq 0x60bc(%rip), %r14      # 0x8fd0
movq %rsp, %r15
movl (%r12), %esi
movq %r14, %rdi
callq 0x22a0
movb $0x20, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2200
addq $0x4, %r12
cmpq 0x6286(%rip), %r12      # 0x91c8
jne 0x2f17
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x606e(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x6252(%rip), %rcx      # 0x91c8
movq 0x6243(%rip), %rdx      # 0x91c0
movq 0x6204(%rip), %rax      # 0x9188
movq $0x0, (%rsp)
subq %rdx, %rcx
je 0x305b
sarq $0x2, %rcx
js 0x2fa5
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
jmp 0x2fbd
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
js 0x2fc9
cvtsi2ss %rax, %xmm1
jmp 0x2fde
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
divss %xmm1, %xmm0
callq 0x2100
cvttss2si %xmm0, %eax
movslq %eax, %rbp
xorl %eax, %eax
leaq -0x8c5(%rip), %rbx      # 0x2732
leaq 0x8(%rsp), %r14
movq %rsp, %r15
leaq 0x30(%rsp), %r12
leaq 0x10(%rsp), %r13
addq %rbp, %rax
movq %rax, 0x30(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x366c
movq %r13, %rdi
movq %r14, %rsi
callq 0x3cb8
cmpq $0x0, 0x8(%rsp)
jne 0x361a
movq (%rsp), %rax
addq %rbp, %rax
movq %rax, (%rsp)
movq 0x617d(%rip), %rcx      # 0x91c8
subq 0x616e(%rip), %rcx      # 0x91c0
sarq $0x2, %rcx
cmpq %rcx, %rax
jb 0x3009
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x3078
movq %rbx, %rdi
callq 0x2290
addq $0x8, %rbx
jmp 0x3065
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rax, %rcx
je 0x30a2
movq %rax, %rdx
cmpq $0x0, (%rdx)
jne 0x361a
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0x308a
movq %rax, 0x18(%rsp)
movq 0x5f27(%rip), %rbx      # 0x8fd0
leaq 0x31c4(%rip), %rsi      # 0x6274
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x5ef5(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x60c1(%rip), %rdi      # 0x91b0
callq 0x52b0
movq 0x5ed5(%rip), %rbx      # 0x8fd0
leaq 0x31a0(%rip), %rsi      # 0x62a2
movl $0x31, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x5ea3(%rip), %rbx      # 0x8fd0
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x6094(%rip), %r12      # 0x91d8
cmpq 0x6095(%rip), %r12      # 0x91e0
je 0x3184
movq 0x5e7c(%rip), %r14      # 0x8fd0
movq %rsp, %r15
movl (%r12), %esi
movq %r14, %rdi
callq 0x22a0
movb $0x20, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2200
addq $0x4, %r12
cmpq 0x605e(%rip), %r12      # 0x91e0
jne 0x3157
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x5e2e(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x602a(%rip), %rcx      # 0x91e0
movq 0x601b(%rip), %rdx      # 0x91d8
movq 0x5fc4(%rip), %rax      # 0x9188
movq $0x0, (%rsp)
subq %rdx, %rcx
je 0x3295
sarq $0x2, %rcx
js 0x31e2
cvtsi2ss %rcx, %xmm0
jmp 0x31f7
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
js 0x3203
cvtsi2ss %rax, %xmm1
jmp 0x3218
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
divss %xmm1, %xmm0
callq 0x2100
cvttss2si %xmm0, %eax
movslq %eax, %rbp
xorl %eax, %eax
leaq -0x8b7(%rip), %rbx      # 0x297a
leaq 0x8(%rsp), %r14
movq %rsp, %r15
leaq 0x30(%rsp), %r12
leaq 0x10(%rsp), %r13
addq %rbp, %rax
movq %rax, 0x30(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x366c
movq %r13, %rdi
movq %r14, %rsi
callq 0x3cb8
cmpq $0x0, 0x8(%rsp)
jne 0x361a
movq (%rsp), %rax
addq %rbp, %rax
movq %rax, (%rsp)
movq 0x5f5b(%rip), %rcx      # 0x91e0
subq 0x5f4c(%rip), %rcx      # 0x91d8
sarq $0x2, %rcx
cmpq %rcx, %rax
jb 0x3243
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x32b2
movq %rbx, %rdi
callq 0x2290
addq $0x8, %rbx
jmp 0x329f
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rax, %rcx
je 0x32dc
movq %rax, %rdx
cmpq $0x0, (%rdx)
jne 0x361a
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0x32c4
movq %rax, 0x18(%rsp)
movq 0x5ced(%rip), %rbx      # 0x8fd0
leaq 0x2fea(%rip), %rsi      # 0x62d4
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x5cbb(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x5e87(%rip), %rdi      # 0x91b0
callq 0x52b0
movq 0x5c9b(%rip), %rbx      # 0x8fd0
leaq 0x2fc6(%rip), %rsi      # 0x6302
movl $0x32, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x5c69(%rip), %rbx      # 0x8fd0
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x5e72(%rip), %r12      # 0x91f0
cmpq 0x5e73(%rip), %r12      # 0x91f8
je 0x33be
movq 0x5c42(%rip), %r14      # 0x8fd0
movq %rsp, %r15
movl (%r12), %esi
movq %r14, %rdi
callq 0x22a0
movb $0x20, (%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2200
addq $0x4, %r12
cmpq 0x5e3c(%rip), %r12      # 0x91f8
jne 0x3391
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x5bf4(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq 0x5e08(%rip), %rcx      # 0x91f8
movq 0x5df9(%rip), %rdx      # 0x91f0
movq 0x5d8a(%rip), %rax      # 0x9188
movq $0x0, (%rsp)
subq %rdx, %rcx
je 0x34cf
sarq $0x2, %rcx
js 0x341c
cvtsi2ss %rcx, %xmm0
jmp 0x3431
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
js 0x343d
cvtsi2ss %rax, %xmm1
jmp 0x3452
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
divss %xmm1, %xmm0
callq 0x2100
cvttss2si %xmm0, %eax
movslq %eax, %rbp
xorl %eax, %eax
leaq -0xa8d(%rip), %rbx      # 0x29de
leaq 0x8(%rsp), %r14
movq %rsp, %r15
leaq 0x30(%rsp), %r12
leaq 0x10(%rsp), %r13
addq %rbp, %rax
movq %rax, 0x30(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x366c
movq %r13, %rdi
movq %r14, %rsi
callq 0x3cb8
cmpq $0x0, 0x8(%rsp)
jne 0x361a
movq (%rsp), %rax
addq %rbp, %rax
movq %rax, (%rsp)
movq 0x5d39(%rip), %rcx      # 0x91f8
subq 0x5d2a(%rip), %rcx      # 0x91f0
sarq $0x2, %rcx
cmpq %rcx, %rax
jb 0x347d
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x34ec
movq %rbx, %rdi
callq 0x2290
addq $0x8, %rbx
jmp 0x34d9
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rax, %rcx
je 0x3516
movq %rax, %rdx
cmpq $0x0, (%rdx)
jne 0x361a
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0x34fe
movq %rax, 0x18(%rsp)
movq 0x5ab3(%rip), %rbx      # 0x8fd0
leaq 0x2e11(%rip), %rsi      # 0x6335
movl $0x4b, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x5a81(%rip), %rdi      # 0x8fd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
cmpq $0x0, 0x5c24(%rip)      # 0x9188
je 0x35bd
movl $0x4, %r12d
xorl %r13d, %r13d
leaq -0xa39(%rip), %rbx      # 0x2b3d
movq %rsp, %r14
leaq 0x10(%rsp), %r15
movq 0x5c83(%rip), %rcx      # 0x9208
leaq (%rcx,%r12), %rdx
addq $-0x4, %rdx
addq %r12, %rcx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3702
movq %r15, %rdi
movq %r14, %rsi
callq 0x3cb8
cmpq $0x0, (%rsp)
jne 0x361a
incq %r13
addq $0x8, %r12
cmpq 0x5bcd(%rip), %r13      # 0x9188
jb 0x357e
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x35da
movq %rbx, %rdi
callq 0x2290
addq $0x8, %rbx
jmp 0x35c7
leaq 0x10(%rsp), %rdi
callq 0x3796
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3627
jmp 0x3627
cmpq $0x0, (%rsp)
jne 0x361a
jmp 0x3627
jmp 0x3627
jmp 0x3627
jmp 0x3612
jmp 0x3627
jmp 0x3627
jmp 0x3612
jmp 0x3627
jmp 0x3627
cmpq $0x0, 0x8(%rsp)
je 0x3627
callq 0x2070
jmp 0x3627
jmp 0x3627
jmp 0x3627
jmp 0x3627
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3796
movq %rbx, %rdi
callq 0x22b0