// File: kiudee[P]VAHD-Projekt/Node.cpp
// Function: Node::Search(SearchJob*)
Action Node::Search(SearchJob *sj)
{
    double hashedkey = sj->sid;
    //std::cout << "(" << sj->_debugID << ") " << num << "<-Search(" << sj->sid << ")\n";
    //responsible node for date was found
    if ((right == NULL && num <= hashedkey && num < MAX) // There is no right node and this node is responsible
            || (num <= hashedkey && right->num > hashedkey && num < MAX)// There is a right node but not responsible
            || (sj->sid == MAX && right == NULL && num < MAX) //The searchjob was delegated to the last node and now we reached the last node
            || (sj->type == JOIN && left == NULL && hashedkey < num)) {
        //it is prohibited to do operations on virtual nodes (TO DO except for Join? => yes!)
        FinishSearch(sj);
        return;
    }

    if (sj->round >= sj->bound) {
        doListHop(sj);
    } else {
        //TODO check this if case
        if ((rightstable || leftstable) && sj->round > 0) {
            double bound = Node::calcRoutingBound();
            sj->bound = bound;
        }
        if (!doDebruijnHop(sj)) {
            doListHop(sj);
        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movsd 0x20(%rcx), %xmm0
movsd %xmm0, -0x18(%rbp)
cmpq $0x0, 0xd0(%rax)
jne 0x118e1
movq -0x28(%rbp), %rax
movsd 0xb0(%rax), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x118e1
movq -0x28(%rbp), %rax
movsd 0x5b35(%rip), %xmm0     # 0x17408
ucomisd 0xb0(%rax), %xmm0
ja 0x11991
movq -0x28(%rbp), %rax
movsd 0xb0(%rax), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x11925
movq -0x28(%rbp), %rax
movq 0xd0(%rax), %rax
movsd 0x20(%rax), %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x11925
movq -0x28(%rbp), %rax
movsd 0x5aed(%rip), %xmm0     # 0x17408
ucomisd 0xb0(%rax), %xmm0
ja 0x11991
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
movsd 0x5ad2(%rip), %xmm1     # 0x17408
ucomisd %xmm1, %xmm0
jne 0x11962
jp 0x11962
movq -0x28(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
jne 0x11962
movq -0x28(%rbp), %rax
movsd 0x5ab0(%rip), %xmm0     # 0x17408
ucomisd 0xb0(%rax), %xmm0
ja 0x11991
movq -0x10(%rbp), %rax
cmpl $0x3, 0x38(%rax)
jne 0x119a0
movq -0x28(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
jne 0x119a0
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm1
movsd 0xb0(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x119a0
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x11b40
jmp 0x11a1d
movq -0x10(%rbp), %rax
cvtsi2sdl 0x48(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomisd 0x40(%rax), %xmm0
jb 0x119c3
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x132c0
jmp 0x11a1d
movq -0x28(%rbp), %rax
testb $0x1, 0x61(%rax)
jne 0x119d7
movq -0x28(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0x119fd
movq -0x10(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jle 0x119fd
movq -0x28(%rbp), %rdi
callq 0x102b0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x40(%rax)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x12eb0
testb $0x1, %al
jne 0x11a1b
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x132c0
jmp 0x11a1d
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)