// File: /workspace/github_cpp_makefile_star2_O3/shreyas-gopalakrishna[P]Concurrent-Skip-list/skip_list.cpp
// Function: SkipList::search[abi:cxx11](int)
string SkipList::search(int key){

    // Finds the predecessor and successors 
    vector<Node*> preds(max_level + 1); 
    vector<Node*> succs(max_level + 1);

    for (size_t i = 0; i < preds.size(); i++){
        preds[i] = NULL;
        succs[i] = NULL;
    }

    int found = find(key, preds, succs);

    // If not found return empty.
    if(found == -1){
        return "";
    }

    Node *curr = head; 

    for (int level = max_level; level >= 0; level--){
        while (curr->next[level] != NULL && key > curr->next[level]->get_key()){
            curr = curr->next[level];
        }
    }

    curr = curr->next[0];
    
    // If found, unmarked and fully linked, then return value. Else return empty.
    if ((curr != NULL) && (curr->get_key() == key) && succs[found]->fully_linked && !succs[found]->marked){
        return curr->get_value();
    }else {
        return "";
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movslq 0x5e63(%rip), %rsi      # 0xb304
incq %rsi
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5de0
movslq 0x5e4a(%rip), %rsi      # 0xb304
incq %rsi
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x5de0
movq 0x20(%rsp), %rcx
cmpq %rcx, 0x28(%rsp)
je 0x5502
xorl %eax, %eax
xorl %edx, %edx
movq %rax, (%rcx,%rdx,8)
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%rdx,8)
incq %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
cmpq %rsi, %rdx
jb 0x54dc
leaq 0x20(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
movl %ebp, %esi
callq 0x4f0c
movl %eax, %r14d
cmpl $-0x1, %eax
je 0x55c8
movq (%r15), %r15
movslq 0x5dd8(%rip), %r12      # 0xb304
testq %r12, %r12
js 0x5571
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x5564
leaq 0x28(%r15), %r13
callq 0x4c2a
cmpl %ebp, %eax
jge 0x5564
movq (%r13), %rax
movq (%rax,%r12,8), %r15
leaq 0x28(%r15), %r13
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
jne 0x5542
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x5531
movq 0x28(%r15), %rax
movq (%rax), %r15
testq %r15, %r15
je 0x55ad
movq %r15, %rdi
callq 0x4c2a
cmpl %ebp, %eax
jne 0x55ad
movslq %r14d, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movb 0x69(%rcx), %cl
testb $0x1, %cl
je 0x55ad
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movb 0x68(%rax), %al
testb $0x1, %al
je 0x5621
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x1a9a(%rip), %rdx      # 0x7055
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x46e2
jmp 0x55e1
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x1a7f(%rip), %rdx      # 0x7055
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x46e2
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x55f8
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x560f
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4c30
jmp 0x55e1
jmp 0x563b
jmp 0x563b
jmp 0x563b
jmp 0x563b
movq %rax, %rbx
jmp 0x5655
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5655
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x566c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rdi
callq 0x2320