// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm1, 0x30(%rsp)
movl %r9d, 0xc(%rsp)
movl %r8d, %r13d
movsd %xmm0, (%rsp)
movl %ecx, %ebx
movl %edx, %r14d
movl %esi, %r12d
movq %rdi, %r15
leaq 0x10(%rdi), %rax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rdi)
andq $0x0, 0x20(%rdi)
leaq 0x30(%rdi), %rax
movq %rax, 0x18(%rsp)
movupd %xmm0, 0x30(%rdi)
andq $0x0, 0x40(%rdi)
leaq 0xd0(%rdi), %rax
movupd %xmm0, 0x50(%rdi)
movupd %xmm0, 0x60(%rdi)
movupd %xmm0, 0x70(%rdi)
movq %rax, 0xa0(%rdi)
pushq $0x1
popq %rax
movq %rax, 0xa8(%rdi)
movupd %xmm0, 0xb0(%rdi)
movl $0x3f800000, %ecx       # imm = 0x3F800000
movl %ecx, 0xc0(%rdi)
movupd %xmm0, 0xc8(%rdi)
leaq 0x108(%rdi), %rdx
movq %rdx, 0xd8(%rdi)
movq %rax, 0xe0(%rdi)
movupd %xmm0, 0xe8(%rdi)
movl %ecx, 0xf8(%rdi)
leaq 0x110(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x148(%rdi), %rax
movq %rax, 0x28(%rsp)
movupd %xmm0, 0x100(%rdi)
movupd %xmm0, 0x110(%rdi)
andq $0x0, 0x120(%rdi)
movupd %xmm0, 0x130(%rdi)
movupd %xmm0, 0x168(%rdi)
movupd %xmm0, 0x158(%rdi)
movupd %xmm0, 0x148(%rdi)
movl %r8d, (%rdi)
movq 0xa467(%rip), %rdi      # 0x13fa0
leaq 0x5531(%rip), %rsi      # 0xf071
callq 0x9290
movq %rax, %rbp
cvtsi2sd %r13d, %xmm1
movsd 0x54bb(%rip), %xmm0     # 0xf010
callq 0x9440
movsd 0x549e(%rip), %xmm1     # 0xf000
divsd %xmm0, %xmm1
movq %rbp, %rdi
movapd %xmm1, %xmm0
callq 0x93d0
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x9310
cvtsi2sd %r12d, %xmm0
mulsd (%rsp), %xmm0
cvttsd2si %xmm0, %eax
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movl %eax, 0x4(%r15)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x9ba7
sqrtsd %xmm0, %xmm0
jmp 0x9bac
callq 0x9220
cvttsd2si %xmm0, %eax
movl %eax, 0x8(%r15)
movq 0xa3e5(%rip), %rdi      # 0x13fa0
leaq 0x54d2(%rip), %rsi      # 0xf094
callq 0x9290
movl 0x4(%r15), %esi
movq %rax, %rdi
callq 0x9430
leaq 0x54f0(%rip), %rsi      # 0xf0ca
movq %rax, %rdi
callq 0x9290
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x9310
movslq %r12d, %rsi
movq 0x28(%rsp), %rdi
callq 0xab88
xorl %ebp, %ebp
testl %r12d, %r12d
cmovgl %r12d, %ebp
subl $0x1, %ebp
jb 0x9c22
movl $0xb0, %edi
callq 0x92a0
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x95ec
jmp 0x9c03
movq 0xa377(%rip), %rdi      # 0x13fa0
movl %r12d, %esi
callq 0x9430
leaq 0x54a5(%rip), %rsi      # 0xf0dd
movq %rax, %rdi
callq 0x9290
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x9310
movl %r14d, 0x28(%r15)
movslq %r14d, %rsi
movq 0x20(%rsp), %rdi
callq 0xab88
movl 0x28(%r15), %esi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x9e1c
movl %ebx, 0x48(%r15)
movslq %ebx, %rsi
movq 0x18(%rsp), %rdi
callq 0xab88
movl 0x48(%r15), %esi
pushq $0x2
popq %rdx
movq %r15, %rdi
callq 0x9e1c
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0xa00a
pushq $0x3
popq %rsi
movq %r15, %rdi
callq 0xa00a
movq %r15, %rdi
xorl %esi, %esi
callq 0xa00a
movl 0xc(%rsp), %eax
movb %al, 0x80(%r15)
movq 0x38(%r15), %rcx
movq 0x58(%r15), %rax
subq 0x50(%r15), %rax
sarq $0x3, %rax
subq 0x30(%r15), %rcx
sarq $0x3, %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %xmm0
punpckldq 0x5360(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5368(%rip), %xmm0     # 0xf050
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x84(%r15)
movb 0x70(%rsp), %al
movb %al, 0x88(%r15)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x90(%r15)
andl $0x0, 0x98(%r15)
movq %r15, %rdi
callq 0xa14a
andq $0x0, 0x180(%r15)
movslq 0x48(%r15), %rsi
movq 0x10(%rsp), %rdi
callq 0xac1e
andq $0x0, 0x178(%r15)
xorl %eax, %eax
movb %al, 0x128(%r15)
movb %al, 0x140(%r15)
movq %r15, %rdi
callq 0xa1d4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9d74
movq %rax, (%rsp)
jmp 0x9d8b
movq %rax, (%rsp)
movl $0xb0, %esi
movq %r13, %rdi
callq 0x92b0
leaq 0x50(%r15), %r14
leaq 0xa0(%r15), %r12
leaq 0xd8(%r15), %r13
leaq 0x130(%r15), %rbp
leaq 0x160(%r15), %rdi
leaq 0x138(%r15), %rbx
addq $0x68, %r15
callq 0xc5aa
movq 0x28(%rsp), %rdi
callq 0xc5aa
movq %rbx, %rdi
callq 0xacb4
movq %rbp, %rdi
callq 0xacb4
movq 0x10(%rsp), %rdi
callq 0xca0c
movq %r13, %rdi
callq 0xae06
movq %r12, %rdi
callq 0xae06
movq %r15, %rdi
callq 0xc5aa
movq %r14, %rdi
callq 0xc5aa
movq 0x18(%rsp), %rdi
callq 0xc5aa
movq 0x20(%rsp), %rdi
callq 0xc5aa
movq (%rsp), %rdi
callq 0x9470