// File: kiudee[P]VAHD-Projekt/Node.cpp
// Function: Node::Init(InitObj*)
Action Node::Init(InitObj *init)
{
    // Initialize pointers and relays
    left = NULL;
    right = NULL;
    node0 = NULL;
    node1 = NULL;
    in = new Relay;

    // Unpack initstructor object:
    num = init->num;
    isReal = init->isReal;
    csvFile = init->csvFile;
    delete init;

    if (isReal) {
        node0left = node1left = false;
        //std::cout << num << " initialized\n";
        // connect to supervisor:
        IdPair *idp = new IdPair(new IdObj(num, new Identity(in), _debugID),
                                 new IdObj(num, new Identity(in), _debugID));
        parent->call(Supervisor::SetLink, idp);

        // create virtual nodes:

        std::shared_ptr<std::ofstream> tmpfile0(csvFile);
        InitObj *n0 = new InitObj(num / 2, false, tmpfile0);
        auto tmpnode0 = (Subject *) new Node((Object* &) n0);

        std::shared_ptr<std::ofstream> tmpfile1(csvFile);
        InitObj *n1 = new InitObj((1 + num) / 2, false, tmpfile1);
        auto tmpnode1 = (Subject *) new Node((Object* &) n1);
        NodePair *np = new NodePair(tmpnode0, tmpnode1);
        parent->call(Supervisor::AddVirtuals, np);
        _create((Subject *) this, (Subject *) tmpnode0);
        _create((Subject *) this, (Subject *) tmpnode1);
    } else {
        //std::cout << "virtual node init: " << num << "\n";
        IdObj *tempid = new IdObj(num, new Identity(in), _debugID);
        parent->call(Node::ConnectChild, tempid);
    }

    //std::cout << num << "\t" << _debugID << "\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq $0x0, 0xc8(%rax)
movq $0x0, 0xd0(%rax)
movq $0x0, 0xd8(%rax)
movq $0x0, 0xe0(%rax)
movl $0x48, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
callq 0x15340
jmp 0xea68
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movq %rax, 0xc0(%rdi)
movq -0x10(%rbp), %rax
movsd 0x28(%rax), %xmm0
movsd %xmm0, 0xb0(%rdi)
movq -0x10(%rbp), %rax
movb 0x20(%rax), %al
andb $0x1, %al
movb %al, 0xb8(%rdi)
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
addq $0xa0, %rdi
callq 0x61d0
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
cmpq $0x0, %rax
je 0xeadf
movq -0xf0(%rbp), %rdi
callq 0x153c0
movq -0xf0(%rbp), %rdi
movl $0x40, %esi
callq 0x31d0
movq -0xe8(%rbp), %rax
testb $0x1, 0xb8(%rax)
je 0xf160
movq -0xe8(%rbp), %rax
movb $0x0, 0x63(%rax)
movb $0x0, 0x62(%rax)
movl $0x30, %edi
callq 0x31c0
movq %rax, -0x100(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, -0xf8(%rbp)
jmp 0xeb26
movq -0xe8(%rbp), %rax
movsd 0xb0(%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
movl $0x28, %edi
callq 0x31c0
movq %rax, -0x108(%rbp)
jmp 0xeb50
movq -0x108(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq 0xc0(%rax), %rsi
callq 0x153e0
jmp 0xeb6c
movq -0x108(%rbp), %rsi
movsd -0x110(%rbp), %xmm0
movq -0xf8(%rbp), %rdi
movq -0xe8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x15520
jmp 0xeb93
movl $0x38, %edi
callq 0x31c0
movq %rax, -0x118(%rbp)
jmp 0xeba6
movq -0xe8(%rbp), %rax
movsd 0xb0(%rax), %xmm0
movsd %xmm0, -0x128(%rbp)
movl $0x28, %edi
callq 0x31c0
movq %rax, -0x120(%rbp)
jmp 0xebd0
movq -0x120(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq 0xc0(%rax), %rsi
callq 0x153e0
jmp 0xebec
movq -0x120(%rbp), %rsi
movsd -0x128(%rbp), %xmm0
movq -0x118(%rbp), %rdi
movq -0xe8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x15520
jmp 0xec13
movq -0x118(%rbp), %rdx
movq -0xf8(%rbp), %rsi
movq -0x100(%rbp), %rdi
callq 0x15570
jmp 0xec2f
movq -0xe8(%rbp), %rax
movq -0x100(%rbp), %rcx
movq %rcx, -0x28(%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 -0xb43a(%rip), %rax     # 0x3830
movq %rax, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x5ae0
jmp 0xec89
movq -0xe8(%rbp), %rsi
movq -0x130(%rbp), %rdx
movq -0x138(%rbp), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
movq -0xe8(%rbp), %rsi
addq $0xa0, %rsi
leaq -0x48(%rbp), %rdi
callq 0x5560
movl $0x40, %edi
callq 0x31c0
movq %rax, -0x140(%rbp)
jmp 0xecd1
movq -0xe8(%rbp), %rax
movb $0x1, -0x61(%rbp)
movsd 0xb0(%rax), %xmm0
movsd 0x8714(%rip), %xmm1     # 0x17400
mulsd %xmm1, %xmm0
movsd %xmm0, -0x150(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x148(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x5560
movq -0x140(%rbp), %rdi
movsd -0x150(%rbp), %xmm0
movq -0x148(%rbp), %rdx
xorl %esi, %esi
callq 0x5590
jmp 0xed2b
movb $0x0, -0x61(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x5540
movq -0x140(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0xe8, %edi
callq 0x31c0
movq %rax, -0x158(%rbp)
jmp 0xed56
movq -0x158(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x5600
jmp 0xed68
movq -0xe8(%rbp), %rsi
movq -0x158(%rbp), %rax
movq %rax, -0x70(%rbp)
addq $0xa0, %rsi
leaq -0x80(%rbp), %rdi
callq 0x5560
movl $0x40, %edi
callq 0x31c0
movq %rax, -0x160(%rbp)
jmp 0xed9d
movq -0xe8(%rbp), %rax
movb $0x1, -0x99(%rbp)
movsd 0xb0(%rax), %xmm0
movsd 0x864d(%rip), %xmm1     # 0x17408
addsd %xmm1, %xmm0
movsd 0x8639(%rip), %xmm1     # 0x17400
mulsd %xmm1, %xmm0
movsd %xmm0, -0x170(%rbp)
leaq -0x98(%rbp), %rdi
movq %rdi, -0x168(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x5560
movq -0x160(%rbp), %rdi
movsd -0x170(%rbp), %xmm0
movq -0x168(%rbp), %rdx
xorl %esi, %esi
callq 0x5590
jmp 0xee09
movb $0x0, -0x99(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5540
movq -0x160(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0xe8, %edi
callq 0x31c0
movq %rax, -0x178(%rbp)
jmp 0xee3d
movq -0x178(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x5600
jmp 0xee52
movq -0x178(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x30, %edi
callq 0x31c0
movq %rax, -0x180(%rbp)
jmp 0xee73
movq -0x180(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x155b0
jmp 0xee8c
movq -0xe8(%rbp), %rax
movq -0x180(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x190(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, -0x188(%rbp)
jmp 0xeebf
movq -0x188(%rbp), %rdi
leaq -0xaa4d(%rip), %rax     # 0x4480
movq %rax, -0xc0(%rbp)
movq $0x0, -0xb8(%rbp)
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0xb0(%rbp), %rcx
callq 0x5ae0
jmp 0xeefb
movq -0x188(%rbp), %rdx
movq -0xe8(%rbp), %rsi
movq -0x190(%rbp), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0xef1b
movq -0xe8(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %rsi, %rdi
callq 0x5720
jmp 0xef30
movq -0xe8(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %rsi, %rdi
callq 0x5720
jmp 0xef48
leaq -0x80(%rbp), %rdi
callq 0x5540
leaq -0x48(%rbp), %rdi
callq 0x5540
jmp 0xf2c7
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x48, %esi
callq 0x31d0
jmp 0xf2d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xf009
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xefba
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x31d0
movq -0xf8(%rbp), %rdi
movl $0x38, %esi
callq 0x31d0
jmp 0xf009
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xeff8
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x31d0
movq -0x118(%rbp), %rdi
movl $0x38, %esi
callq 0x31d0
movq -0x100(%rbp), %rdi
movl $0x30, %esi
callq 0x31d0
jmp 0xf2d0
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0xf2d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xf152
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x5540
testb $0x1, -0x61(%rbp)
jne 0xf06f
jmp 0xf080
movq -0x140(%rbp), %rdi
movl $0x40, %esi
callq 0x31d0
jmp 0xf152
movq -0x158(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0xe8, %esi
callq 0x31d0
jmp 0xf152
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xf149
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5540
testb $0x1, -0x99(%rbp)
jne 0xf0db
jmp 0xf0ec
movq -0x160(%rbp), %rdi
movl $0x40, %esi
callq 0x31d0
jmp 0xf149
movq -0x178(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0xe8, %esi
callq 0x31d0
jmp 0xf149
movq -0x180(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x30, %esi
callq 0x31d0
jmp 0xf149
movq -0x188(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x38, %esi
callq 0x31d0
leaq -0x80(%rbp), %rdi
callq 0x5540
leaq -0x48(%rbp), %rdi
callq 0x5540
jmp 0xf2d0
movl $0x38, %edi
callq 0x31c0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movq %rcx, -0x1a8(%rbp)
movsd 0xb0(%rax), %xmm0
movsd %xmm0, -0x1a0(%rbp)
movl $0x28, %edi
callq 0x31c0
movq %rax, -0x198(%rbp)
jmp 0xf19e
movq -0x198(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq 0xc0(%rax), %rsi
callq 0x153e0
jmp 0xf1ba
movq -0x198(%rbp), %rsi
movsd -0x1a0(%rbp), %xmm0
movq -0x1a8(%rbp), %rdi
movq -0xe8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x15520
jmp 0xf1e1
movq -0xe8(%rbp), %rax
movq -0x1a8(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x1b8(%rbp)
movl $0x38, %edi
callq 0x31c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1b0(%rbp)
leaq 0xc1(%rip), %rax        # 0xf2e0
movq %rax, -0xd8(%rbp)
movq $0x0, -0xd0(%rbp)
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0x5ae0
jmp 0xf24d
movq -0x1b0(%rbp), %rdx
movq -0xe8(%rbp), %rsi
movq -0x1b8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xf2c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xf295
movq -0x198(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x31d0
movq -0x1a8(%rbp), %rdi
movl $0x38, %esi
callq 0x31d0
jmp 0xf2d0
movq -0x1b0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x38, %esi
callq 0x31d0
jmp 0xf2d0
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x3330
nopl (%rax)