// File: /workspace/github_cpp_makefile_star2_O3/kiudee[P]VAHD-Projekt/Supervisor.cpp
// Function: Supervisor::SetLink(IdPair*)
Action Supervisor::SetLink(IdPair *idop)
{
    NumObj *numo;

    Nodes.push_back(new NodeRelay(idop->ido1));
    Relay *temprelay = new Relay(idop->ido1->id);//TODO please review
    subjects[idop->ido1->num] = temprelay;
    delete idop->ido1;
    StartID.push_back(idop->ido2);
    delete idop;
    count++;

    // If the last Node has registered we can link them with relays
    if (count == total) {
        for (int i = 0; i < total; i++) {
            // make sure that node i periodically wakes up
            numo = new NumObj(5);
            Nodes[i]->out->call(Node::Wakeup, numo);

            // initially connect node i to nodes 2i and 2i+1
            if (2 * i + 1 < total) {
                Nodes[i]->out->call(Node::Join, StartID[2 * i + 1]);
            }
            if (2 * i + 2 < total) {
                Nodes[i]->out->call(Node::Join, StartID[2 * i + 2]);
            }
        }

        numo = new NumObj(14000);
        call(Supervisor::Wakeup, numo);
    }
    if (count > total) {
        numo = new NumObj(5);
        Nodes[count - 1]->out->call(Node::Wakeup, numo);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl $0x38, %edi
callq 0x2160
movq %rax, %r15
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x3d6c
leaq 0x68(%rbx), %rdi
movq %rsp, %rsi
movq %r15, (%rsi)
callq 0x5512
movl $0x48, %edi
callq 0x2160
movq %rax, %r15
movq 0x20(%r14), %rsi
addq $0x28, %rsi
movq %rax, %rdi
callq 0x3dfc
leaq 0xa8(%rbx), %rdi
movq 0x20(%r14), %rsi
addq $0x20, %rsi
callq 0x5686
movq %r15, (%rax)
movq 0x20(%r14), %rdi
movl $0x38, %esi
callq 0x2170
leaq 0x28(%r14), %rdx
movq 0x88(%rbx), %rsi
cmpq 0x90(%rbx), %rsi
je 0x27c1
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x88(%rbx)
jmp 0x27cd
leaq 0x80(%rbx), %rdi
callq 0x5a0a
movl $0x30, %esi
movq %r14, %rdi
callq 0x2170
movl 0x60(%rbx), %ecx
movl 0x64(%rbx), %eax
leal 0x1(%rcx), %ebp
movl %ebp, 0x60(%rbx)
cmpl %eax, %ebp
jne 0x2a3e
testl %ecx, %ecx
js 0x299b
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
movl $0x28, %edi
callq 0x2160
movq %rax, %r14
leaq 0xe976(%rip), %rcx      # 0x11188
movq (%rcx), %rax
movq %rax, (%r14)
incq %rax
movq %rax, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0xe96b(%rip), %rax      # 0x111a0
movq (%rax), %rax
testq %rax, %rax
je 0x2844
leaq 0x8(%r14), %rcx
movq %rax, (%rcx)
movl $0x5, 0x20(%r14)
movq 0x68(%rbx), %rax
movq (%rax,%r13,4), %rax
movq 0x28(%rax), %r15
movl $0x38, %edi
callq 0x2160
leaq 0xe93f(%rip), %rdx      # 0x111a8
movq (%rdx), %rcx
movq %rcx, (%rax)
incq %rcx
movq %rcx, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x45fd(%rip), %rcx      # 0x6e80
movq %rcx, 0x18(%rax)
movq %r12, 0x20(%rax)
movq %r14, 0x28(%rax)
movq %r12, 0x30(%rax)
movq (%r15), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
movl 0x64(%rbx), %eax
leal 0x1(%r13), %ecx
cmpl %ecx, %eax
jle 0x2917
movq 0x68(%rbx), %rax
movq (%rax,%r13,4), %rax
movq 0x28(%rax), %r14
movl $0x38, %edi
callq 0x2160
movq 0x80(%rbx), %rcx
leaq 0xe8d7(%rip), %rsi      # 0x111a8
movq (%rsi), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x7837(%rip), %rdx      # 0xa122
movq %rdx, 0x18(%rax)
movq %r12, 0x20(%rax)
movq 0x8(%rcx,%r13,8), %rdx
movq %rdx, 0x28(%rax)
movq %r12, 0x30(%rax)
movq %r12, 0x8(%rcx,%r13,8)
movq (%r14), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
movl 0x64(%rbx), %eax
leal 0x2(%r13), %ecx
cmpl %ecx, %eax
jle 0x2989
movq 0x68(%rbx), %rax
movq (%rax,%r13,4), %rax
movq 0x28(%rax), %r14
movl $0x38, %edi
callq 0x2160
movq 0x80(%rbx), %rcx
leaq 0xe865(%rip), %rsi      # 0x111a8
movq (%rsi), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x77c5(%rip), %rdx      # 0xa122
movq %rdx, 0x18(%rax)
movq %r12, 0x20(%rax)
movq 0x10(%rcx,%r13,8), %rdx
movq %rdx, 0x28(%rax)
movq %r12, 0x30(%rax)
movq %r12, 0x10(%rcx,%r13,8)
movq (%r14), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
movl 0x64(%rbx), %eax
incq %rbp
cltq
addq $0x2, %r13
cmpq %rax, %rbp
jl 0x27fe
movl $0x28, %edi
callq 0x2160
movq %rax, %r14
leaq 0xe7d9(%rip), %rax      # 0x11188
movq (%rax), %rcx
movq %rcx, (%r14)
incq %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0xe7ce(%rip), %rax      # 0x111a0
movq (%rax), %rax
testq %rax, %rax
je 0x29e4
movq %r14, %rcx
addq $0x8, %rcx
movq %rax, (%rcx)
movl $0x36b0, 0x20(%r14)     # imm = 0x36B0
movl $0x38, %edi
callq 0x2160
leaq 0xe7ab(%rip), %rcx      # 0x111a8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x10d(%rip), %rcx       # 0x2b24
movq %rcx, 0x18(%rax)
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movq %r14, 0x28(%rax)
movq %rcx, 0x30(%rax)
movq (%rbx), %rcx
movq %rbx, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x48(%rcx)
movl 0x60(%rbx), %ebp
movl 0x64(%rbx), %eax
cmpl %eax, %ebp
jle 0x2af3
movl $0x28, %edi
callq 0x2160
movq %rax, %r14
leaq 0xe72e(%rip), %rax      # 0x11188
movq (%rax), %rcx
movq %rcx, (%r14)
incq %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0xe723(%rip), %rax      # 0x111a0
movq (%rax), %rax
testq %rax, %rax
je 0x2a8f
movq %r14, %rcx
addq $0x8, %rcx
movq %rax, (%rcx)
movl $0x5, 0x20(%r14)
movq 0x68(%rbx), %rax
movslq %ebp, %rcx
movq -0x8(%rax,%rcx,8), %rax
movq 0x28(%rax), %r15
movl $0x38, %edi
callq 0x2160
leaq 0xe6f0(%rip), %rcx      # 0x111a8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x43ae(%rip), %rcx      # 0x6e80
movq %rcx, 0x18(%rax)
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movq %r14, 0x28(%rax)
movq %rcx, 0x30(%rax)
movq (%r15), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x48, %esi
jmp 0x2b14
movq %rax, %rbx
movl $0x38, %esi
movq %r15, %rdi
callq 0x2170
movq %rbx, %rdi
callq 0x2280