// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %rbx
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %r15
movq 0x20(%r12), %rsi
movq %rax, %rdi
callq 0x3766
leaq 0x68(%rbx), %rdi
leaq 0x10(%rsp), %rsi
movq %r15, (%rsi)
movq %rdi, 0x8(%rsp)
callq 0x4ca0
pushq $0x48
popq %rdi
callq 0x2170
movq %rax, %r15
movq 0x20(%r12), %rsi
addq $0x28, %rsi
movq %rax, %rdi
callq 0x37c0
leaq 0xa8(%rbx), %rdi
movq 0x20(%r12), %rsi
addq $0x20, %rsi
callq 0x4e32
movq %r15, (%rax)
movq 0x20(%r12), %rdi
pushq $0x38
popq %rsi
callq 0x2180
leaq 0x80(%rbx), %rdi
leaq 0x28(%r12), %rsi
movq %rdi, (%rsp)
callq 0x3872
pushq $0x30
popq %rsi
movq %r12, %rdi
callq 0x2180
movl 0x60(%rbx), %eax
movl 0x64(%rbx), %ecx
incl %eax
movl %eax, 0x60(%rbx)
cmpl %ecx, %eax
jne 0x286c
pushq $0x8
popq %r14
pushq $0x1
popq %r15
xorl %r13d, %r13d
movslq %eax, %r12
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %rbp
movq %rax, %rdi
callq 0x3a32
cmpq %r12, %r13
jge 0x2815
movl $0x5, 0x20(%rbp)
movq 0x68(%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x28(%rax), %r12
pushq $0x38
popq %rdi
callq 0x2170
leaq 0xda96(%rip), %rdx      # 0x101b8
movq (%rdx), %rcx
movq %rcx, (%rax)
incq %rcx
movq %rcx, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x3bca(%rip), %rcx      # 0x6306
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rbp, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%r12), %rcx
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x8(%rcx)
movl 0x64(%rbx), %eax
cmpl %r15d, %eax
jle 0x27af
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rax
movq 0x28(%rax), %r12
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %rbp
movq (%rsp), %rax
movq (%rax), %rcx
addq %r14, %rcx
movq %rbp, %rdi
leaq 0x5cf5(%rip), %rsi      # 0x848a
xorl %edx, %edx
callq 0x3890
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq *0x8(%rax)
movl 0x64(%rbx), %eax
leal 0x1(%r15), %ecx
cmpl %ecx, %eax
jle 0x2805
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rax
movq 0x28(%rax), %r12
pushq $0x38
popq %rdi
callq 0x2170
movq %rax, %rbp
movq (%rsp), %rax
movq (%rax), %rax
leaq (%rax,%r14), %rcx
addq $0x8, %rcx
movq %rbp, %rdi
leaq 0x5c9f(%rip), %rsi      # 0x848a
xorl %edx, %edx
callq 0x3890
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq *0x8(%rax)
movl 0x64(%rbx), %eax
incq %r13
addq $0x10, %r14
addl $0x2, %r15d
jmp 0x26e1
movl $0x36b0, 0x20(%rbp)     # imm = 0x36B0
pushq $0x38
popq %rdi
callq 0x2170
leaq 0xd98d(%rip), %rdx      # 0x101b8
movq (%rdx), %rcx
movq %rcx, (%rax)
incq %rcx
movq %rcx, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0xdb(%rip), %rcx        # 0x2920
movq %rcx, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rbp, 0x28(%rax)
andq $0x0, 0x30(%rax)
movq (%rbx), %rcx
movq %rbx, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq *0x48(%rcx)
movl 0x60(%rbx), %eax
movl 0x64(%rbx), %ecx
cmpl %ecx, %eax
jle 0x28e6
pushq $0x28
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
callq 0x3a32
movl $0x5, 0x20(%r14)
movslq 0x60(%rbx), %rax
movq 0x68(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rax
movq 0x28(%rax), %r15
pushq $0x38
popq %rdi
callq 0x2170
leaq 0xd90d(%rip), %rcx      # 0x101b8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x3a41(%rip), %rcx      # 0x6306
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)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x48
jmp 0x2901
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r15, %rdi
jmp 0x2912
jmp 0x2909
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %rbp, %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x2290
nop