// File: mertyildiran[P]Plexus/plexus/plexus.cpp
// Function: Network::Network(int, int, int, double, int, bool, bool, bool, double)
Network::Network(
    int size,
    int input_dim = 0,
    int output_dim = 0,
    double connectivity = 0.01,
    int precision = 2,
    bool randomly_fire = false,
    bool dynamic_output = false,
    bool visualization = false,
    double decay_factor = 1.0
)
{
    this->precision = precision;
    std::cout << "\nPrecision of the network will be "
        << 1.0 / pow(10, precision) << '\n';
    this->connectivity = static_cast<int>(size * connectivity);
    this->connectivity_sqrt = static_cast<int>(sqrt(this->connectivity));
    std::cout << "Each individual non-sensory neuron will subscribe to "
        << this->connectivity << " different neurons" << '\n';

    this->neurons.reserve(size);
    for (int i = 0; i < size; i++) {
        new Neuron(*this);
    }
    std::cout << size << " neurons created" << '\n';

    this->input_dim = input_dim;
    this->sensory_neurons.reserve(this->input_dim);
    this->pick_neurons_by_type(this->input_dim, SENSORY_NEURON);

    this->output_dim = output_dim;
    this->motor_neurons.reserve(this->output_dim);
    this->pick_neurons_by_type(this->output_dim, MOTOR_NEURON);

    this->get_neurons_by_type(NON_SENSORY_NEURON);
    this->get_neurons_by_type(NON_MOTOR_NEURON);
    this->get_neurons_by_type(INTER_NEURON);
    this->randomly_fire = randomly_fire;
    this->motor_randomly_fire_rate = sqrt(
        this->nonsensory_neurons.size() / this->motor_neurons.size()
    );

    this->dynamic_output = dynamic_output;

    this->decay_factor = decay_factor;

    this->initiated_neurons = 0;
    this->initiate_subscriptions();

    this->fire_counter = 0;
    this->output.reserve(this->output_dim);
    this->wave_counter = 0;

    this->freezer = false;
    this->thread_kill_signal = false;
    this->ignite();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl %r9d, %eax
movl %ecx, -0xb0(%rbp)
movl %edx, -0xac(%rbp)
movl %esi, %r9d
movl -0xb0(%rbp), %esi
movq %rdi, %r10
movl -0xac(%rbp), %edi
movb %al, %dl
movb 0x18(%rbp), %al
movb 0x10(%rbp), %cl
movq %r10, -0x8(%rbp)
movl %r9d, -0xc(%rbp)
movl %edi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movsd %xmm0, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
andb $0x1, %dl
movb %dl, -0x25(%rbp)
andb $0x1, %cl
movb %cl, -0x26(%rbp)
andb $0x1, %al
movb %al, -0x27(%rbp)
movsd %xmm1, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x50(%rbp)
addq $0x10, %rdi
movq %rdi, -0xa8(%rbp)
callq 0x195f0
movq -0x50(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0xa0(%rbp)
callq 0x195f0
movq -0x50(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x98(%rbp)
callq 0x195f0
movq -0x50(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x90(%rbp)
callq 0x195f0
movq -0x50(%rbp), %rdi
addq $0xa0, %rdi
movq %rdi, -0x88(%rbp)
callq 0x18b70
movq -0x50(%rbp), %rdi
addq $0xd8, %rdi
movq %rdi, -0x80(%rbp)
callq 0x18b70
movq -0x50(%rbp), %rdi
addq $0x110, %rdi            # imm = 0x110
movq %rdi, -0x78(%rbp)
callq 0x19610
movq -0x50(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movq %rdi, -0x70(%rbp)
callq 0x19630
movq -0x50(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq %rdi, -0x68(%rbp)
callq 0x19630
movq -0x50(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
movq %rdi, -0x60(%rbp)
callq 0x195f0
movq -0x50(%rbp), %rdi
addq $0x160, %rdi            # imm = 0x160
movq %rdi, -0x58(%rbp)
callq 0x195f0
movq -0x50(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, (%rax)
movq 0x19e64(%rip), %rdi     # 0x30f98
leaq 0xff16(%rip), %rsi      # 0x27051
callq 0x162b0
movq %rax, -0x48(%rbp)
jmp 0x17146
movl -0x24(%rbp), %esi
movl $0xa, %edi
callq 0x19650
movsd %xmm0, -0xb8(%rbp)
jmp 0x1715d
movq -0x48(%rbp), %rdi
movsd -0xb8(%rbp), %xmm1
movsd 0xfe8f(%rip), %xmm0     # 0x27000
divsd %xmm1, %xmm0
callq 0x16540
movq %rax, -0xc0(%rbp)
jmp 0x17183
movq -0xc0(%rbp), %rdi
movl $0xa, %esi
callq 0x16380
jmp 0x17196
movq -0x50(%rbp), %rax
cvtsi2sdl -0xc(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x4(%rax)
movl 0x4(%rax), %edi
callq 0x19680
movsd %xmm0, -0xc8(%rbp)
jmp 0x171c1
movq -0x50(%rbp), %rax
movsd -0xc8(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x8(%rax)
movq 0x19dbd(%rip), %rdi     # 0x30f98
leaq 0xfe92(%rip), %rsi      # 0x27074
callq 0x162b0
movq %rax, -0xd0(%rbp)
jmp 0x171f0
movq -0xd0(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x164a0
movq %rax, -0xd8(%rbp)
jmp 0x1720c
movq -0xd8(%rbp), %rdi
leaq 0xfe90(%rip), %rsi      # 0x270aa
callq 0x162b0
movq %rax, -0xe0(%rbp)
jmp 0x17228
movq -0xe0(%rbp), %rdi
movl $0xa, %esi
callq 0x16380
jmp 0x1723b
movq -0x50(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
movslq -0xc(%rbp), %rsi
callq 0x196a0
jmp 0x17251
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x172c5
movl $0xb0, %edi
callq 0x162c0
movq %rax, -0xe8(%rbp)
jmp 0x17273
movq -0x50(%rbp), %rsi
movq -0xe8(%rbp), %rdi
callq 0x166c0
jmp 0x17285
jmp 0x17287
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x17258
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x17474
movq -0xe8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0xb0, %esi
callq 0x162d0
jmp 0x17474
movl -0xc(%rbp), %esi
movq 0x19cc9(%rip), %rdi     # 0x30f98
callq 0x164a0
movq %rax, -0xf0(%rbp)
jmp 0x172dd
movq -0xf0(%rbp), %rdi
leaq 0xfdd2(%rip), %rsi      # 0x270bd
callq 0x162b0
movq %rax, -0xf8(%rbp)
jmp 0x172f9
movq -0xf8(%rbp), %rdi
movl $0xa, %esi
callq 0x16380
jmp 0x1730c
movq -0x50(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, 0x28(%rax)
movq %rax, %rdi
addq $0x10, %rdi
movslq 0x28(%rax), %rsi
callq 0x196a0
jmp 0x17328
movq -0x50(%rbp), %rdi
movl 0x28(%rdi), %esi
movl $0x1, %edx
callq 0x174f0
jmp 0x1733b
movq -0x50(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, 0x48(%rax)
movq %rax, %rdi
addq $0x30, %rdi
movslq 0x48(%rax), %rsi
callq 0x196a0
jmp 0x17357
movq -0x50(%rbp), %rdi
movl 0x48(%rdi), %esi
movl $0x2, %edx
callq 0x174f0
jmp 0x1736a
movq -0x50(%rbp), %rdi
movl $0x4, %esi
callq 0x17890
jmp 0x1737a
movq -0x50(%rbp), %rdi
movl $0x3, %esi
callq 0x17890
jmp 0x1738a
movq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x17890
jmp 0x17397
movq -0x50(%rbp), %rdi
movb -0x25(%rbp), %al
andb $0x1, %al
movb %al, 0x80(%rdi)
addq $0x50, %rdi
callq 0x18dd0
movq -0x50(%rbp), %rdi
movq %rax, -0x108(%rbp)
addq $0x30, %rdi
callq 0x18dd0
movq %rax, %rcx
movq -0x108(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
callq 0x197a0
movsd %xmm0, -0x100(%rbp)
jmp 0x173e4
movq -0x50(%rbp), %rdi
movsd -0x100(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x84(%rdi)
movb -0x26(%rbp), %al
andb $0x1, %al
movb %al, 0x88(%rdi)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x90(%rdi)
movl $0x0, 0x98(%rdi)
callq 0x17a90
jmp 0x17423
movq -0x50(%rbp), %rax
movq $0x0, 0x180(%rax)
movq %rax, %rdi
addq $0x110, %rdi            # imm = 0x110
movslq 0x48(%rax), %rsi
callq 0x197e0
jmp 0x17447
movq -0x50(%rbp), %rdi
movq $0x0, 0x178(%rdi)
movb $0x0, 0x128(%rdi)
movb $0x0, 0x140(%rdi)
callq 0x17b90
jmp 0x1746b
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x19100
movq -0x60(%rbp), %rdi
callq 0x19100
movq -0x68(%rbp), %rdi
callq 0x198e0
movq -0x70(%rbp), %rdi
callq 0x198e0
movq -0x78(%rbp), %rdi
callq 0x19910
movq -0x80(%rbp), %rdi
callq 0x18c70
movq -0x88(%rbp), %rdi
callq 0x18c70
movq -0x90(%rbp), %rdi
callq 0x19100
movq -0x98(%rbp), %rdi
callq 0x19100
movq -0xa0(%rbp), %rdi
callq 0x19100
movq -0xa8(%rbp), %rdi
callq 0x19100
movq -0x38(%rbp), %rdi
callq 0x164e0
nop