// File: /workspace/github_cpp_makefile_star2_O2/kiudee[P]VAHD-Projekt/Node.cpp
// Function: Node::Probing(Probe*)
Action Node::Probing(Probe *ido)
{
    IdObj *tempido;
    Probe *tempprobe;
    if (isReal) {
        if (ido == NULL) {
            //If no left neighbor is set, set it to node0 and probing is done, else send probe to the left neighbor
            if (left == NULL) {
                tempido = new IdObj(num / 2, new Identity(node0->out), node0->debugID);
                left = new NodeRelay(tempido);
                leftstable = false;

            } else {
                //(1) send probe to left introducing the first phase (indicating by parameter 0)
                tempprobe = new Probe(num, new Identity(in), 0);
                left->out->call(Node::Probing, tempprobe);
            }
            //If no right neighbor is set, set it to node1 and probing is done, else send the probe to the right neighbor
            if (right == NULL) {
                tempido = new IdObj((1 + num) / 2, new Identity(node1->out), node1->debugID);
                right = new NodeRelay(tempido);
                rightstable = false;

            } else {
                tempprobe = new Probe(num, new Identity(in), 0);
                right->out->call(Node::Probing, tempprobe);
            }
        } else {

            //probe reaches v.0 or v.1. finish probing. this shall never happen, because we are on a real node, but we're searching for a virtual one.
            //if (num == ido->num / 2 || num == (1 + ido->num) / 2) {
            //v.0 / v.1 has to be virtual
            //delete ido;
            //return;
            //}

            /*probe came from the left, so we're searching for ido->num/2
             because we're on a real node, change the direction flag and
             send probe to node0*/
            if (ido->num > num) {
                //(3) we are on the real node w, so we switch the phase flag indicating, that we are on the left side of v.0.
                //tempido = new Probe(ido->num, extractIdentity(ido->out), 1);
                //delete ido;
                if (ido->phase == 0) {
                    ido->phase = 1;
                    node0->out->call(Node::Probing, ido);
                    return;
                } else {
                    if (num <= ido->num / 2) {
                        if (right != NULL) {
                            right->out->call(Node::Probing, ido);
                            return;
                        }

                    }

                }
                Relay *temprelay = new Relay(ido->id);
                NumObj *numo = new NumObj(0);
                temprelay->call(Node::BuildWeakConnectedComponent, numo);

            }

            /*probe came from the right, so we're searching for 1+ido->value/2
             because we're on a real node, change the direction flag and
             send probe to node1*/
            if (ido->num < num) {
                //tempido = new Probe(ido->num, extractIdentity(ido->out), 1);
                //delete ido;
                // Unpack probe
                if (ido->phase == 0) {
                    ido->phase = 1;
                    node1->out->call(Node::Probing, ido);
                    return;
                } else {
                    if (num >= ido->num / 2) {
                        if (left != NULL) {
                            left->out->call(Node::Probing, ido);
                            return;
                        }
                    }
                }
                Relay *temprelay = new Relay(ido->id);
                NumObj *numo = new NumObj(1);
                temprelay->call(Node::BuildWeakConnectedComponent, numo);
            }

        }

    } else {
        if (ido != NULL) {
            //probe came from the left
            if (ido->num > num) {
                //probe reaches v.0. finish probing
                if (num == ido->num / 2) {
                    delete ido;
                    return;
                }
                //probe hit no real node yet, so send it to left
                if (ido->phase == 0) {
                    if (left != NULL) {
                        //(2) send probe to the left
                        left->out->call(Node::Probing, ido);
                        return;
                    }
                }
                //probe hit real node, so send it to right
                else if (ido->phase == 1) {
                    if (num < ido->num / 2) {
                        if (right != NULL) {
                            //(4) send probe to the right
                            right->out->call(Node::Probing, ido);
                            return;
                        }
                    }
                }
                /*if the probe gets stuck (no left or right neighbor) or
                 the id was not found, establish link between v and v.0*/
                Relay *temprelay = new Relay(ido->id);
                NumObj *numo = new NumObj(0);
                temprelay->call(Node::BuildWeakConnectedComponent, numo);
                //delete temprelay;
            }
            if (ido->num < num) {

                //probe reaches v.1. finish probing
                if (num == (1 + ido->num) / 2) {
                    delete ido;
                    return;
                }
                if (ido->phase == 0) {
                    if (right != NULL) {
                        right->out->call(Node::Probing, ido);
                        return;
                    }
                } else if (ido->phase == 1) {
                    if (num > (1 + ido->num) / 2) {
                        if (left != NULL) {
                            left->out->call(Node::Probing, ido);
                            return;
                        }
                    }
                }
                Relay *temprelay = new Relay(ido->id);
                NumObj *numo = new NumObj(1);
                temprelay->call(Node::BuildWeakConnectedComponent, numo);
                //delete temprelay;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x1, 0xb8(%rdi)
jne 0x6c9d
testq %r14, %r14
je 0x6cf3
movsd 0x28(%r14), %xmm0
movsd 0xb0(%rbx), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6c4b
cmpl $0x0, 0x20(%r14)
je 0x6f13
mulsd 0x3815(%rip), %xmm0     # 0xa3c0
ucomisd %xmm1, %xmm0
jb 0x6bc1
movq 0xd0(%rbx), %rax
testq %rax, %rax
jne 0x7045
pushq $0x48
popq %rdi
callq 0x2170
movq %rax, %r15
leaq 0x30(%r14), %rsi
movq %rax, %rdi
callq 0x37c0
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r12
movq %rax, %rdi
callq 0x3a32
andl $0x0, 0x20(%r12)
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x95b8(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq 0x22f0(%rip), %rcx      # 0x8f0c
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %r12, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%r15), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
movsd 0x28(%r14), %xmm0
movsd 0xb0(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7010
cmpl $0x0, 0x20(%r14)
je 0x6f27
mulsd 0x3758(%rip), %xmm0     # 0xa3c0
ucomisd %xmm0, %xmm1
jb 0x6c7e
movq 0xc8(%rbx), %rax
testq %rax, %rax
jne 0x7045
pushq $0x48
popq %rdi
callq 0x2170
movq %rax, %r15
addq $0x30, %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x37c0
jmp 0x70be
testq %r14, %r14
je 0x7010
movsd 0x28(%r14), %xmm0
movsd 0xb0(%rbx), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6fdb
mulsd 0x36fa(%rip), %xmm0     # 0xa3c0
ucomisd %xmm0, %xmm1
jne 0x6cd2
jnp 0x6ff9
movl 0x20(%r14), %eax
cmpl $0x1, %eax
je 0x6f3b
testl %eax, %eax
jne 0x6f51
movq 0xc8(%rbx), %rax
jmp 0x6f48
movq 0xc8(%rbx), %r15
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %r14
movsd 0xb0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
testq %r15, %r15
je 0x6dac
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r15
movq 0xc0(%rbx), %rsi
movq %rax, %rdi
callq 0x92c2
movq %r14, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x28(%r14)
andl $0x0, 0x20(%r14)
movq %r15, 0x30(%r14)
movq 0xc8(%rbx), %rax
movq 0x28(%rax), %r15
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x944b(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq -0x231(%rip), %rcx      # 0x6b58
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %r14, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%r15), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
jmp 0x6e25
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r15
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rsi
movq %r15, %rdi
callq 0x92c2
movsd 0x8(%rsp), %xmm0
mulsd 0x35e8(%rip), %xmm0     # 0xa3c0
movsd %xmm0, 0x8(%rsp)
movq 0xd8(%rbx), %rax
movl 0x30(%rax), %ebp
movq %r14, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%r14)
movq %r15, 0x28(%r14)
movl %ebp, 0x30(%r14)
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x3766
movq %r15, 0xc8(%rbx)
movb $0x0, 0x60(%rbx)
movq 0xd0(%rbx), %r15
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %r14
movsd 0xb0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
testq %r15, %r15
je 0x6e8d
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r15
movq 0xc0(%rbx), %rsi
movq %rax, %rdi
callq 0x92c2
movq %r14, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x28(%r14)
andl $0x0, 0x20(%r14)
movq %r15, 0x30(%r14)
movq 0xd0(%rbx), %rax
jmp 0x7045
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r15
movq 0xe0(%rbx), %rax
movq 0x28(%rax), %rsi
movq %r15, %rdi
callq 0x92c2
movsd 0x8(%rsp), %xmm0
addsd 0x350f(%rip), %xmm0     # 0xa3c8
mulsd 0x34ff(%rip), %xmm0     # 0xa3c0
movsd %xmm0, 0x8(%rsp)
movq 0xe0(%rbx), %rax
movl 0x30(%rax), %ebp
movq %r14, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%r14)
movq %r15, 0x28(%r14)
movl %ebp, 0x30(%r14)
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x3766
movq %r15, 0xd0(%rbx)
movb $0x0, 0x61(%rbx)
jmp 0x7010
movl $0x1, 0x20(%r14)
movq 0xd8(%rbx), %rax
jmp 0x7045
movl $0x1, 0x20(%r14)
movq 0xe0(%rbx), %rax
jmp 0x7045
ucomisd %xmm1, %xmm0
jbe 0x6f51
movq 0xd0(%rbx), %rax
testq %rax, %rax
jne 0x7045
pushq $0x48
popq %rdi
callq 0x2170
movq %rax, %r15
leaq 0x30(%r14), %rsi
movq %rax, %rdi
callq 0x37c0
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r12
movq %rax, %rdi
callq 0x3a32
andl $0x0, 0x20(%r12)
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x9228(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq 0x1f60(%rip), %rcx      # 0x8f0c
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %r12, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%r15), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
movsd 0x28(%r14), %xmm0
movsd 0xb0(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7010
addsd 0x33df(%rip), %xmm0     # 0xa3c8
mulsd 0x33cf(%rip), %xmm0     # 0xa3c0
ucomisd %xmm0, %xmm1
jne 0x701d
jp 0x701d
pushq $0x38
popq %rsi
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2180
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x20(%r14), %eax
cmpl $0x1, %eax
je 0x7033
testl %eax, %eax
jne 0x70a4
movq 0xd0(%rbx), %rax
jmp 0x7040
ucomisd %xmm0, %xmm1
jbe 0x70a4
movq 0xc8(%rbx), %rax
testq %rax, %rax
je 0x70a4
movq 0x28(%rax), %r15
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x9160(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq -0x51c(%rip), %rcx      # 0x6b58
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %r14, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%r15), %rcx
movq 0x8(%rcx), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmpq *%rcx
pushq $0x48
popq %rdi
callq 0x2170
movq %rax, %r15
addq $0x30, %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x37c0
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
callq 0x3a32
movl $0x1, 0x20(%r14)
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x90d0(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq 0x1e08(%rip), %rcx      # 0x8f0c
jmp 0x7074
jmp 0x710f
jmp 0x710f
jmp 0x710f
movq %rax, %rbx
pushq $0x48
jmp 0x7121
jmp 0x711c
jmp 0x712f
jmp 0x713f
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r15, %rdi
jmp 0x7148
jmp 0x712f
jmp 0x713f
jmp 0x712f
jmp 0x713f
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r15, %rdi
callq 0x2180
jmp 0x7142
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x2290
nop