// File: mertyildiran[P]Plexus/plexus/plexus.cpp
// Function: Network::_ignite(Network*)
void Network::_ignite(Network* network)
{
    unsigned int motor_fire_counter = 0;
    std::vector<Neuron*> ban_list;
    for (;;) {
        if (network->freezer) {
            usleep(10);
            continue;
        }
        if (network->randomly_fire) {
            Neuron* neuron = random_sample(
                network->nonsensory_neurons,
                1
            )[0];
            if (neuron->type == MOTOR_NEURON) {
                if (1 != Random::get(1, network->motor_randomly_fire_rate))
                    continue;
                else
                    motor_fire_counter++;
            }
            neuron->fire();
            if (motor_fire_counter >= network->motor_neurons.size()) {
                if (network->dynamic_output) {
                    network->print_output();
                }
                network->output = network->get_output();
                network->wave_counter++;
                motor_fire_counter = 0;
            }
        } else {
            if (network->next_queue.empty()) {
                for (auto& neuron: network->motor_neurons) {
                    neuron->fire();
                }
                for (auto& neuron: ban_list) {
                    neuron->ban_counter = 0;
                }
                ban_list.clear();
                if (network->dynamic_output) {
                    network->print_output();
                }
                network->output = network->get_output();
                network->wave_counter++;

                if (network->first_queue.empty()) {
                    for (auto const& neuron: network->sensory_neurons) {
                        network->first_queue.insert(
                            neuron->publications.begin(),
                            neuron->publications.end()
                        );
                    }
                }
                network->next_queue = network->first_queue;
            }

            std::unordered_map<Neuron*, double> current_queue
                = network->next_queue;
            network->next_queue.clear();
            for (auto const& neuron: ban_list) {
                if (neuron->ban_counter > network->connectivity_sqrt)
                    current_queue.erase(neuron);
            }
            while (current_queue.size() > 0) {
                auto it = current_queue.begin();
                std::advance(it, rand() % current_queue.size());
                Neuron* neuron = it->first;
                current_queue.erase(neuron);
                if (neuron->ban_counter <= network->connectivity_sqrt) {
                    if (neuron->type == MOTOR_NEURON) {
                        continue;
                    }
                    neuron->fire();
                    ban_list.push_back(neuron);
                    neuron->ban_counter++;
                    network->next_queue.insert(
                        neuron->publications.begin(),
                        neuron->publications.end()
                    );
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %fs:0x28, %rax
movq %rax, -0x8(%rbp)
movq %rdi, -0x110(%rbp)
movl $0x0, -0x114(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x195f0
movq -0x110(%rbp), %rax
testb $0x1, 0x128(%rax)
je 0x17ca7
movl $0xa, %edi
callq 0x163e0
jmp 0x17c8e
jmp 0x17c72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
jmp 0x18349
movq -0x110(%rbp), %rax
testb $0x1, 0x80(%rax)
je 0x17e44
movq -0x110(%rbp), %rsi
addq $0x50, %rsi
leaq -0x50(%rbp), %rdi
callq 0x18fd0
jmp 0x17cd1
leaq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x1, %edx
callq 0x18df0
jmp 0x17ce5
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x19970
movq (%rax), %rax
movq %rax, -0x198(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x19100
leaq -0x50(%rbp), %rdi
callq 0x19100
movq -0x198(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
cmpl $0x2, 0xa8(%rax)
jne 0x17d90
movq -0x110(%rbp), %rax
movl 0x84(%rax), %esi
movl $0x1, %edi
callq 0x19990
movl %eax, -0x19c(%rbp)
jmp 0x17d4b
movl -0x19c(%rbp), %ecx
movl $0x1, %eax
cmpl %ecx, %eax
je 0x17d7f
jmp 0x17c72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x19100
jmp 0x18349
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x17d90
movq -0x130(%rbp), %rdi
callq 0x16d50
jmp 0x17d9e
movl -0x114(%rbp), %eax
movq %rax, -0x1a8(%rbp)
movq -0x110(%rbp), %rdi
addq $0x30, %rdi
callq 0x18dd0
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
cmpq %rcx, %rax
jb 0x17e3f
movq -0x110(%rbp), %rax
testb $0x1, 0x88(%rax)
je 0x17dea
movq -0x110(%rbp), %rdi
callq 0x18390
jmp 0x17de8
jmp 0x17dea
movq -0x110(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x184c0
jmp 0x17dfc
movq -0x110(%rbp), %rdi
addq $0x110, %rdi            # imm = 0x110
leaq -0x68(%rbp), %rsi
callq 0x19a30
leaq -0x68(%rbp), %rdi
callq 0x19910
movq -0x110(%rbp), %rax
movq 0x178(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x178(%rax)
movl $0x0, -0x114(%rbp)
jmp 0x18344
movq -0x110(%rbp), %rdi
addq $0xd8, %rdi
callq 0x19a60
testb $0x1, %al
jne 0x17e60
jmp 0x180e0
movq -0x110(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rdi
callq 0x19160
movq %rax, -0x70(%rbp)
movq -0x138(%rbp), %rdi
callq 0x191b0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x19210
testb $0x1, %al
jne 0x17ea5
jmp 0x17ed3
leaq -0x70(%rbp), %rdi
callq 0x19250
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rax
movq (%rax), %rdi
callq 0x16d50
jmp 0x17ec6
jmp 0x17ec8
leaq -0x70(%rbp), %rdi
callq 0x19350
jmp 0x17e92
leaq -0x20(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x19160
movq %rax, -0x80(%rbp)
movq -0x148(%rbp), %rdi
callq 0x191b0
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x19210
testb $0x1, %al
jne 0x17f17
jmp 0x17f46
leaq -0x80(%rbp), %rdi
callq 0x19250
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0xac(%rax)
leaq -0x80(%rbp), %rdi
callq 0x19350
jmp 0x17f01
leaq -0x20(%rbp), %rdi
callq 0x19a80
movq -0x110(%rbp), %rax
testb $0x1, 0x88(%rax)
je 0x17f6f
movq -0x110(%rbp), %rdi
callq 0x18390
jmp 0x17f6d
jmp 0x17f6f
movq -0x110(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x184c0
jmp 0x17f84
movq -0x110(%rbp), %rdi
addq $0x110, %rdi            # imm = 0x110
leaq -0xa0(%rbp), %rsi
callq 0x19a30
leaq -0xa0(%rbp), %rdi
callq 0x19910
movq -0x110(%rbp), %rax
movq 0x178(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x178(%rax)
movq -0x110(%rbp), %rdi
addq $0xa0, %rdi
callq 0x19a60
testb $0x1, %al
jne 0x17fdf
jmp 0x180bf
movq -0x110(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
callq 0x19160
movq %rax, -0xa8(%rbp)
movq -0x158(%rbp), %rdi
callq 0x191b0
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x19210
testb $0x1, %al
jne 0x18033
jmp 0x180bd
leaq -0xa8(%rbp), %rdi
callq 0x19250
movq %rax, -0x160(%rbp)
movq -0x110(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0x1b0(%rbp)
movq -0x160(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0x19500
movq %rax, -0x168(%rbp)
movq -0x160(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0x19530
movq -0x1b0(%rbp), %rdi
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rsi
movq -0x170(%rbp), %rdx
callq 0x19aa0
jmp 0x180aa
jmp 0x180ac
leaq -0xa8(%rbp), %rdi
callq 0x19350
jmp 0x18017
jmp 0x180bf
movq -0x110(%rbp), %rdi
movq %rdi, %rsi
addq $0xa0, %rsi
addq $0xd8, %rdi
callq 0x19b00
jmp 0x180de
jmp 0x180e0
movq -0x110(%rbp), %rsi
addq $0xd8, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x19b30
jmp 0x180fc
movq -0x110(%rbp), %rdi
addq $0xd8, %rdi
callq 0x19b60
leaq -0x20(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rdi
callq 0x19160
movq %rax, -0xf0(%rbp)
movq -0x178(%rbp), %rdi
callq 0x191b0
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x19210
testb $0x1, %al
jne 0x18159
jmp 0x181d5
leaq -0xf0(%rbp), %rdi
callq 0x19250
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rax
movq (%rax), %rax
movl 0xac(%rax), %eax
movq -0x110(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x181c2
movq -0x180(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x19b80
jmp 0x1819d
jmp 0x181c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x18c70
jmp 0x18349
jmp 0x181c4
leaq -0xf0(%rbp), %rdi
callq 0x19350
jmp 0x18140
jmp 0x181d7
leaq -0xe8(%rbp), %rdi
callq 0x18c90
cmpq $0x0, %rax
jbe 0x18338
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x19500
movq %rax, -0x100(%rbp)
callq 0x16080
movq -0x1c0(%rbp), %rdi
cltq
movq %rax, -0x1b8(%rbp)
callq 0x18c90
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
leaq -0x100(%rbp), %rdi
callq 0x19bb0
jmp 0x18241
leaq -0x100(%rbp), %rdi
callq 0x19c00
movq (%rax), %rax
movq %rax, -0x108(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x19b80
jmp 0x1826c
movq -0x108(%rbp), %rax
movl 0xac(%rax), %eax
movq -0x110(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jg 0x18333
movq -0x108(%rbp), %rax
cmpl $0x2, 0xa8(%rax)
jne 0x1829e
jmp 0x181d7
movq -0x108(%rbp), %rdi
callq 0x16d50
jmp 0x182ac
leaq -0x20(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x19c30
jmp 0x182be
movq -0x108(%rbp), %rax
movl 0xac(%rax), %ecx
incl %ecx
movl %ecx, 0xac(%rax)
movq -0x110(%rbp), %rax
addq $0xd8, %rax
movq %rax, -0x1c8(%rbp)
movq -0x108(%rbp), %rdi
addq $0x68, %rdi
callq 0x19500
movq %rax, -0x188(%rbp)
movq -0x108(%rbp), %rdi
addq $0x68, %rdi
callq 0x19530
movq -0x1c8(%rbp), %rdi
movq %rax, -0x190(%rbp)
movq -0x188(%rbp), %rsi
movq -0x190(%rbp), %rdx
callq 0x19aa0
jmp 0x18331
jmp 0x18333
jmp 0x181d7
leaq -0xe8(%rbp), %rdi
callq 0x18c70
jmp 0x17c72
leaq -0x20(%rbp), %rdi
callq 0x19100
movq -0x120(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq %fs:0x28, %rax
movq -0x8(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1837e
movq -0x1d0(%rbp), %rdi
callq 0x164e0
callq 0x16340
nopw %cs:(%rax,%rax)