// File: 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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
movq %rdi, %rsi
addq $0xc8, %rsi
xorl %edx, %edx
callq 0xf670
movq -0xa8(%rbp), %rdi
movq %rdi, %rsi
addq $0xd0, %rsi
movl $0x1, %edx
callq 0xf670
movq -0xa8(%rbp), %rdi
callq 0xf740
cmpq $0x0, -0x10(%rbp)
je 0xfa98
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x14890
testb $0x1, %al
jne 0xfa93
jmp 0xfa98
jmp 0x1029b
cmpq $0x0, -0x10(%rbp)
jne 0x101b9
movq -0xa8(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0xfc1a
movl $0x38, %edi
callq 0x31c0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, -0xc0(%rbp)
movsd 0xb0(%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
movl $0x28, %edi
callq 0x31c0
movq %rax, -0xb0(%rbp)
jmp 0xfaf6
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rax
movq 0xc0(%rax), %rsi
callq 0x153e0
jmp 0xfb12
movq -0xb0(%rbp), %rsi
movsd -0xb8(%rbp), %xmm0
movq -0xc0(%rbp), %rdi
movq -0xa8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x15520
jmp 0xfb39
movq -0xa8(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movq 0xc8(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0xd0(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
leaq -0x15b(%rip), %rax      # 0xfa20
movq %rax, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x5ae0
jmp 0xfb9a
movq -0xc8(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq -0xd0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xfc1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xfbe2
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x31d0
movq -0xc0(%rbp), %rdi
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
movq -0xa8(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0xfd91
movl $0x38, %edi
callq 0x31c0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, -0xe8(%rbp)
movsd 0xb0(%rax), %xmm0
movsd %xmm0, -0xe0(%rbp)
movl $0x28, %edi
callq 0x31c0
movq %rax, -0xd8(%rbp)
jmp 0xfc6d
movq -0xd8(%rbp), %rdi
movq -0xa8(%rbp), %rax
movq 0xc0(%rax), %rsi
callq 0x153e0
jmp 0xfc89
movq -0xd8(%rbp), %rsi
movsd -0xe0(%rbp), %xmm0
movq -0xe8(%rbp), %rdi
movq -0xa8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x15520
jmp 0xfcb0
movq -0xa8(%rbp), %rax
movq -0xe8(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movq 0xd0(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0xf8(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xf0(%rbp)
leaq -0x2d2(%rip), %rax      # 0xfa20
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x18(%rbp), %rcx
callq 0x5ae0
jmp 0xfd11
movq -0xf0(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq -0xf8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xfd91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xfd59
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x31d0
movq -0xe8(%rbp), %rdi
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
movq -0xa8(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
jne 0x100da
movq -0xa8(%rbp), %rax
movsd 0xb0(%rax), %xmm0
movsd 0x764b(%rip), %xmm1     # 0x17408
ucomisd %xmm1, %xmm0
jbe 0x100da
movq -0xa8(%rbp), %rdi
movq 0xc0(%rdi), %rsi
movq (%rdi), %rax
callq *0x58(%rax)
cmpl $0x0, %eax
je 0x100da
movq -0xa8(%rbp), %rax
testb $0x1, 0xb8(%rax)
je 0xff8e
movq -0xa8(%rbp), %rax
testb $0x1, 0x62(%rax)
je 0xff11
movq -0xa8(%rbp), %rax
testb $0x1, 0x63(%rax)
je 0xff11
movl $0x28, %edi
callq 0x31c0
movq %rax, %rdi
movq -0xa8(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x100(%rbp)
movsd 0xb0(%rax), %xmm0
movsd 0x75d0(%rip), %xmm1     # 0x17418
addsd %xmm1, %xmm0
callq 0x15c50
jmp 0xfe53
movq -0xa8(%rbp), %rax
movq -0x100(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x110(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x108(%rbp)
leaq -0xaa6e(%rip), %rax     # 0x5420
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x5ae0
jmp 0xfead
movq -0x108(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq -0x110(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xff89
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x31d0
jmp 0x102a4
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
movl $0x38, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x118(%rbp)
leaq -0x50f(%rip), %rax      # 0xfa20
movq %rax, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x10(%rbp), %rcx
callq 0x5ae0
jmp 0xff4e
movq -0x118(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq (%rsi), %rax
movq %rsi, %rdi
callq *0x48(%rax)
jmp 0xff89
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
jmp 0x100d5
movq 0x1103b(%rip), %rdi     # 0x20fd0
leaq 0x726e(%rip), %rsi      # 0x1720a
callq 0x31b0
movq %rax, %rdi
movq -0xa8(%rbp), %rax
movsd 0xb0(%rax), %xmm0
movsd 0x744d(%rip), %xmm1     # 0x17408
movsd %xmm1, -0x128(%rbp)
subsd %xmm1, %xmm0
callq 0x3370
movq %rax, %rdi
leaq 0x723a(%rip), %rsi      # 0x17210
callq 0x31b0
movl $0x28, %edi
callq 0x31c0
movsd -0x128(%rbp), %xmm1
movq %rax, %rdi
movq -0xa8(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x120(%rbp)
movsd 0xb0(%rax), %xmm0
subsd %xmm1, %xmm0
callq 0x15c50
jmp 0x10014
movq -0xa8(%rbp), %rax
movq -0x120(%rbp), %rcx
movq %rcx, -0x78(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x138(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x130(%rbp)
leaq 0x4b51(%rip), %rax      # 0x14ba0
movq %rax, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x78(%rbp), %rcx
callq 0x5ae0
jmp 0x10074
movq -0x130(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq -0x138(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x100d5
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x31d0
jmp 0x102a4
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
jmp 0x101b4
movl $0x28, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x140(%rbp)
movl $0x5, %esi
callq 0x5a90
jmp 0x100fd
movq -0x140(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x148(%rbp)
leaq -0xba9(%rip), %rax      # 0xf580
movq %rax, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
leaq -0x90(%rbp), %rcx
callq 0x5ae0
jmp 0x10157
movq -0x148(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq (%rsi), %rax
movq %rsi, %rdi
callq *0x48(%rax)
jmp 0x101b4
movq -0x140(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x31d0
jmp 0x102a4
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0x102a4
jmp 0x1029b
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
callq 0x14080
movq -0xa8(%rbp), %rax
movq -0x10(%rbp), %rcx
movsd 0x20(%rcx), %xmm0
ucomisd 0xb0(%rax), %xmm0
jbe 0x1020c
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq %rdi, %rdx
addq $0xd0, %rdx
movl $0x1, %ecx
callq 0x143e0
jmp 0x10299
movq -0xa8(%rbp), %rax
movq -0x10(%rbp), %rcx
movsd 0x20(%rcx), %xmm1
movsd 0xb0(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x10248
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq %rdi, %rdx
addq $0xc8, %rdx
xorl %ecx, %ecx
callq 0x143e0
jmp 0x10297
movq -0xa8(%rbp), %rax
testb $0x1, 0xb8(%rax)
je 0x10276
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq %rdi, %rdx
addq $0xc8, %rdx
xorl %ecx, %ecx
callq 0x143e0
jmp 0x10295
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq %rdi, %rdx
addq $0xd0, %rdx
movl $0x1, %ecx
callq 0x143e0
jmp 0x10297
jmp 0x10299
jmp 0x1029b
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x3330
nopl (%rax)