// File: shreyas-gopalakrishna[P]Concurrent-Skip-list/skip_list.cpp
// Function: SkipList::range[abi:cxx11](int, int)
map<int, string> SkipList::range(int start_key, int end_key){

    map<int, string> range_output;

    if(start_key > end_key){
        return range_output;
    }

    Node *curr = head;

    for (int level = max_level; level >= 0; level--){
        while (curr->next[level] != NULL && start_key > curr->next[level]->get_key()){
            if(curr->get_key() >= start_key && curr->get_key() <= end_key){
                range_output.insert(make_pair(curr->get_key(), curr->get_value()));
            }
            curr = curr->next[level];
        }
    }

    while(curr != NULL && end_key >= curr->get_key()){
        if(curr->get_key() >= start_key && curr->get_key() <= end_key){
            range_output.insert(make_pair(curr->get_key(), curr->get_value()));
        }
        curr = curr->next[0];
    }

    return range_output;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x118(%rbp)
movq %rdi, %rax
movq %rax, -0x110(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movb $0x0, -0x19(%rbp)
callq 0xce50
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0xc556
movb $0x1, -0x19(%rbp)
movl $0x1, -0x20(%rbp)
jmp 0xc8bd
movq -0x108(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl 0xadfa(%rip), %eax      # 0x17364
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0xc72f
jmp 0xc579
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xa1b0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x119(%rbp)
je 0xc5dc
movl -0x14(%rbp), %eax
movl %eax, -0x124(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xa1b0
movq (%rax), %rdi
callq 0x9f00
movl %eax, -0x120(%rbp)
jmp 0xc5c5
movl -0x124(%rbp), %eax
movl -0x120(%rbp), %ecx
cmpl %ecx, %eax
setg %al
movb %al, -0x119(%rbp)
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0xc5eb
jmp 0xc71f
movq -0x28(%rbp), %rdi
callq 0x9f00
movl %eax, -0x128(%rbp)
jmp 0xc5fc
movl -0x128(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0xc702
movq -0x28(%rbp), %rdi
callq 0x9f00
movl %eax, -0x12c(%rbp)
jmp 0xc61c
movl -0x12c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0xc702
movq -0x28(%rbp), %rdi
callq 0x9f00
movl %eax, -0x130(%rbp)
jmp 0xc63c
movl -0x130(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x9f20
jmp 0xc657
leaq -0x68(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0xceb0
jmp 0xc66d
movq -0x118(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xce70
movb %dl, -0x139(%rbp)
movq %rax, -0x138(%rbp)
jmp 0xc68c
movb -0x139(%rbp), %al
movq -0x138(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movb %al, -0x98(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xcef0
leaq -0x90(%rbp), %rdi
callq 0x3170
jmp 0xc702
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xc8df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xc6f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xcef0
leaq -0x90(%rbp), %rdi
callq 0x3170
jmp 0xc8df
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xa1b0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0xc579
jmp 0xc721
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xc56d
jmp 0xc731
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x13a(%rbp)
je 0xc771
movl -0x18(%rbp), %eax
movl %eax, -0x144(%rbp)
movq -0x28(%rbp), %rdi
callq 0x9f00
movl %eax, -0x140(%rbp)
jmp 0xc75a
movl -0x144(%rbp), %eax
movl -0x140(%rbp), %ecx
cmpl %ecx, %eax
setge %al
movb %al, -0x13a(%rbp)
movb -0x13a(%rbp), %al
testb $0x1, %al
jne 0xc780
jmp 0xc8b2
movq -0x28(%rbp), %rdi
callq 0x9f00
movl %eax, -0x148(%rbp)
jmp 0xc791
movl -0x148(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0xc895
movq -0x28(%rbp), %rdi
callq 0x9f00
movl %eax, -0x14c(%rbp)
jmp 0xc7b1
movl -0x14c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0xc895
movq -0x28(%rbp), %rdi
callq 0x9f00
movl %eax, -0x150(%rbp)
jmp 0xc7d1
movl -0x150(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0x28(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x9f20
jmp 0xc7ef
leaq -0xc8(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0xceb0
jmp 0xc80b
movq -0x118(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xce70
movb %dl, -0x159(%rbp)
movq %rax, -0x158(%rbp)
jmp 0xc82d
movb -0x159(%rbp), %al
movq -0x158(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movb %al, -0xf8(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xcef0
leaq -0xf0(%rbp), %rdi
callq 0x3170
jmp 0xc895
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xc887
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xcef0
leaq -0xf0(%rbp), %rdi
callq 0x3170
jmp 0xc8df
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa1b0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0xc731
movb $0x1, -0x19(%rbp)
movl $0x1, -0x20(%rbp)
testb $0x1, -0x19(%rbp)
jne 0xc8cf
movq -0x118(%rbp), %rdi
callq 0x57a0
movq -0x110(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x118(%rbp), %rdi
callq 0x57a0
movq -0x38(%rbp), %rdi
callq 0x33b0
nopw %cs:(%rax,%rax)