// File: /workspace/github_cpp_makefile_star2_O1/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 0x5e89(%rip), %rsi      # 0xb304
incq %rsi
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5dcc
movslq 0x5e70(%rip), %rsi      # 0xb304
incq %rsi
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x5dcc
movq 0x20(%rsp), %rcx
cmpq %rcx, 0x28(%rsp)
je 0x54dc
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 0x54b6
leaq 0x20(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
movl %ebp, %esi
callq 0x4ec8
movl %eax, %r14d
cmpl $-0x1, %eax
je 0x55a2
movq (%r15), %r15
movslq 0x5dfe(%rip), %r12      # 0xb304
testq %r12, %r12
js 0x554b
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x553e
leaq 0x28(%r15), %r13
callq 0x4bea
cmpl %ebp, %eax
jge 0x553e
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 0x551c
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x550b
movq 0x28(%r15), %rax
movq (%rax), %r15
testq %r15, %r15
je 0x5587
movq %r15, %rdi
callq 0x4bea
cmpl %ebp, %eax
jne 0x5587
movslq %r14d, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movb 0x69(%rcx), %cl
testb $0x1, %cl
je 0x5587
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movb 0x68(%rax), %al
testb $0x1, %al
je 0x55fb
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x1ac0(%rip), %rdx      # 0x7055
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x46ae
jmp 0x55bb
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x1aa5(%rip), %rdx      # 0x7055
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x46ae
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x55d2
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x55e9
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 0x4bf0
jmp 0x55bb
jmp 0x5615
jmp 0x5615
jmp 0x5615
jmp 0x5615
movq %rax, %rbx
jmp 0x562f
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x562f
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5646
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2220
movq %rbx, %rdi
callq 0x2320