// File: /workspace/github_cpp_makefile_star2_O2/kiudee[P]VAHD-Projekt/Node.cpp
// Function: Node::BuildList(IdObj*)
Action Node::BuildList(IdObj *ido)
{

    IdObj *tempido;
    // Check if there are dead links from both sides:
    //   -> Delete if dead.
    checkDead(&left, false);
    checkDead(&right, true);

    // Check if both links are still valid:
    //   -> Call BuildDeBruijn if not.
    checkValid();

    if (ido != NULL && isSelf(ido)) {
        //delete ido;
        return;
    }

    if (ido == NULL) {
        // timeout: ask neighbors to create return links
        if (left != NULL) {
            tempido = new IdObj(num, new Identity(in), _debugID);
            left->out->call(Node::BuildList, tempido);
        }
        if (right != NULL) {
            tempido = new IdObj(num, new Identity(in), _debugID);
            right->out->call(Node::BuildList, tempido);
        }
        if (right == NULL && num > MAX && idle(in)) {
            if (isReal) {
                if (node0left && node1left) {
                    DoubleObj *dob = new DoubleObj(num - MAX);
                    parent->call(Supervisor::RemoveRealChild, dob);
                } else {
                    call(Node::BuildList, ido);
                }
            } else {
                std::cout << "Node " << (num - MAX) << " leaves. Ciao.\n";
                DoubleObj *obj = new DoubleObj(num - MAX);
                parent->call(Node::RemoveVirtualChild, obj);
            }
        } else {
            // prepare next timeout
            NumObj *counter = new NumObj(5);
            call(Node::Wakeup, counter);
        }
    } else {
        checkStable(ido->num);
        if (ido->num > num) {
            BuildSide(ido, &right, true);
        } else if (ido->num < num) { // ido->num <= num
            BuildSide(ido, &left, false);
        } else if (isReal) { // prioritize real nodes
            BuildSide(ido, &left, false);
        } else {
            BuildSide(ido, &right, true);
        }
    }

    /*
    if(isReal)
        std::cout << "REAL";
    else
        std::cout << "VIRTUAL";


    std::cout << "\tNode: " << num << " " << _debugID;

    if (left == NULL) {
        //std::cout << "\tLeft: NULL";
    } else {
        //std::cout << "\tLeft: " << left->num << " " << left->_debugID;
    }

    if (right == NULL) {
        //std::cout << "\tRight: NULL";
    } else {
        //std::cout << "\tRight: " << right->num << " " << right->_debugID;
    }

    //std::cout << "\n";
     */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xc8(%rdi), %r12
movq %r12, %rsi
xorl %edx, %edx
callq 0x6396
leaq 0xd0(%rbx), %r15
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6396
movq %rbx, %rdi
callq 0x6404
testq %r14, %r14
je 0x6657
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8c86
testb %al, %al
je 0x6886
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, (%r12)
je 0x670c
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %r14
movsd 0xb0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r12
movq 0xc0(%rbx), %rsi
movq %rax, %rdi
callq 0x92c2
movl 0x8(%rbx), %ebp
movq %r14, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%r14)
movq %r12, 0x28(%r14)
movl %ebp, 0x30(%r14)
movq 0xc8(%rbx), %rax
movq 0x28(%rax), %r12
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x9aea(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq -0xf8(%rip), %rcx       # 0x65f2
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %r14, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%r12), %rcx
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
cmpq $0x0, (%r15)
je 0x67ce
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %r14
movsd 0xb0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r15
movq 0xc0(%rbx), %rsi
movq %rax, %rdi
callq 0x92c2
movl 0x8(%rbx), %ebp
movq %r14, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%r14)
movq %r15, 0x28(%r14)
movl %ebp, 0x30(%r14)
movq 0xd0(%rbx), %rax
movq 0x28(%rax), %r15
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x9a36(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq -0x1ac(%rip), %rcx      # 0x65f2
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)
xorl %eax, %eax
cmpq %rax, 0xd0(%rbx)
jne 0x68bd
movsd 0xb0(%rbx), %xmm0
ucomisd 0x3bea(%rip), %xmm0     # 0xa3c8
jbe 0x68bd
movq (%rbx), %rax
movq 0xc0(%rbx), %rsi
movq %rbx, %rdi
callq *0x58(%rax)
testl %eax, %eax
je 0x68bd
cmpb $0x1, 0xb8(%rbx)
jne 0x6962
cmpb $0x1, 0x62(%rbx)
jne 0x6a29
cmpb $0x1, 0x63(%rbx)
jne 0x6a29
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r14
movsd 0xb0(%rbx), %xmm0
addsd 0x3b98(%rip), %xmm0     # 0xa3d0
movsd %xmm0, 0x8(%rsp)
movq %rax, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%r14)
movq 0x28(%rbx), %r15
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x9953(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq -0x32ff(%rip), %rcx     # 0x3582
jmp 0x6a08
movsd 0x20(%r14), %xmm0
movq %rbx, %rdi
callq 0x8838
movsd 0x20(%r14), %xmm0
movsd 0xb0(%rbx), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6933
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
jmp 0x6951
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
callq 0x3a32
movl $0x5, 0x20(%r14)
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x98d1(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq -0x5fd(%rip), %rcx      # 0x6306
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %r14, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%rbx), %rcx
movq 0x48(%rcx), %rcx
movq %rbx, %rdi
movq %rbx, %rsi
movq %rax, %rdx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmpq *%rcx
ucomisd %xmm0, %xmm1
ja 0x6946
cmpb $0x1, 0xb8(%rbx)
jne 0x68ac
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x89b4
movq 0x9667(%rip), %rdi      # 0xffd0
leaq 0x38b2(%rip), %rsi      # 0xa222
callq 0x2160
movsd 0x3a53(%rip), %xmm1     # 0xa3d0
movsd %xmm1, 0x8(%rsp)
movsd 0xb0(%rbx), %xmm0
addsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x2240
leaq 0x388a(%rip), %rsi      # 0xa228
movq %rax, %rdi
callq 0x2160
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r14
movsd 0x8(%rsp), %xmm0
addsd 0xb0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rax, %rdi
callq 0x3a32
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%r14)
movq 0x28(%rbx), %r15
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x97cc(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq 0x2498(%rip), %rcx      # 0x8ea0
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
jmp 0x691f
pushq $0x38
popq %rdi
callq 0x2170
leaq 0x9780(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
leaq -0x462(%rip), %rcx      # 0x65f2
movq %rcx, 0x18(%rax)
movupd %xmm0, 0x20(%rax)
jmp 0x6910
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r15, %rdi
jmp 0x6a78
jmp 0x6a7f
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r12, %rdi
callq 0x2180
jmp 0x6a82
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x2290
nop