// File: /workspace/github_cpp_makefile_star2_O1/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 0x3160
movq %rax, %r15
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x4dae
leaq 0x68(%rbx), %rdi
movq %rsp, %rsi
movq %r15, (%rsi)
callq 0x65ca
movl $0x48, %edi
callq 0x3160
movq %rax, %r15
movq 0x20(%r14), %rsi
addq $0x28, %rsi
movq %rax, %rdi
callq 0x4e3c
leaq 0xa8(%rbx), %rdi
movq 0x20(%r14), %rsi
addq $0x20, %rsi
callq 0x6736
movq %r15, (%rax)
movq 0x20(%r14), %rdi
testq %rdi, %rdi
je 0x37b2
movl $0x38, %esi
callq 0x3170
leaq 0x28(%r14), %rdx
movq 0x88(%rbx), %rsi
cmpq 0x90(%rbx), %rsi
je 0x37d6
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x88(%rbx)
jmp 0x37e2
leaq 0x80(%rbx), %rdi
callq 0x6ac8
testq %r14, %r14
je 0x37f4
movl $0x30, %esi
movq %r14, %rdi
callq 0x3170
movl 0x60(%rbx), %eax
incl %eax
movl %eax, 0x60(%rbx)
cmpl 0x64(%rbx), %eax
jne 0x3a4c
cmpl $0x0, 0x64(%rbx)
jle 0x39af
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
movl $0x28, %edi
callq 0x3160
movq %rax, %r14
leaq 0xe95d(%rip), %rcx      # 0x12188
movq (%rcx), %rax
movq %rax, (%r14)
incq %rax
movq %rax, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0xe952(%rip), %rax      # 0x121a0
movq (%rax), %rax
testq %rax, %rax
je 0x385d
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 0x3160
leaq 0xe926(%rip), %rdx      # 0x121a8
movq (%rdx), %rcx
movq %rcx, (%rax)
incq %rcx
movq %rcx, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x466c(%rip), %rcx      # 0x7f08
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)
leal 0x1(%r13), %eax
cmpl %eax, 0x64(%rbx)
jle 0x392b
movq 0x68(%rbx), %rax
movq (%rax,%r13,4), %rax
movq 0x28(%rax), %r14
movl $0x38, %edi
callq 0x3160
movq 0x80(%rbx), %rcx
leaq 0xe8c0(%rip), %rsi      # 0x121a8
movq (%rsi), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x7768(%rip), %rdx      # 0xb06a
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)
leal 0x2(%r13), %eax
cmpl %eax, 0x64(%rbx)
jle 0x399b
movq 0x68(%rbx), %rax
movq (%rax,%r13,4), %rax
movq 0x28(%rax), %r14
movl $0x38, %edi
callq 0x3160
movq 0x80(%rbx), %rcx
leaq 0xe850(%rip), %rsi      # 0x121a8
movq (%rsi), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x76f8(%rip), %rdx      # 0xb06a
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)
incq %rbp
movslq 0x64(%rbx), %rax
addq $0x2, %r13
cmpq %rax, %rbp
jl 0x3817
movl $0x28, %edi
callq 0x3160
movq %rax, %r14
leaq 0xe7c5(%rip), %rax      # 0x12188
movq (%rax), %rcx
movq %rcx, (%r14)
incq %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0xe7ba(%rip), %rax      # 0x121a0
movq (%rax), %rax
testq %rax, %rax
je 0x39f8
movq %r14, %rcx
addq $0x8, %rcx
movq %rax, (%rcx)
movl $0x36b0, 0x20(%r14)     # imm = 0x36B0
movl $0x38, %edi
callq 0x3160
leaq 0xe797(%rip), %rcx      # 0x121a8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x10b(%rip), %rcx       # 0x3b36
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)
movslq 0x60(%rbx), %r15
cmpl 0x64(%rbx), %r15d
jle 0x3b04
movl $0x28, %edi
callq 0x3160
movq %rax, %r14
leaq 0xe71a(%rip), %rax      # 0x12188
movq (%rax), %rcx
movq %rcx, (%r14)
incq %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0xe70f(%rip), %rax      # 0x121a0
movq (%rax), %rax
testq %rax, %rax
je 0x3aa3
movq %r14, %rcx
addq $0x8, %rcx
movq %rax, (%rcx)
movl $0x5, 0x20(%r14)
movq 0x68(%rbx), %rax
movq -0x8(%rax,%r15,8), %rax
movq 0x28(%rax), %r15
movl $0x38, %edi
callq 0x3160
leaq 0xe6df(%rip), %rcx      # 0x121a8
movq (%rcx), %rdx
movq %rdx, (%rax)
incq %rdx
movq %rdx, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x4425(%rip), %rcx      # 0x7f08
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 0x3b25
movq %rax, %rbx
movl $0x38, %esi
movq %r15, %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x3280
nop