// File: mertyildiran[P]Plexus/plexus/plexus.cpp
// Function: Neuron::fire()
bool Neuron::fire()
{
    if (this->type != SENSORY_NEURON) {

        this->potential = this->calculate_potential();
        this->network->fire_counter++;
        this->fire_counter++;

        if (! std::isnan(this->desired_potential)) {

            this->loss = this->calculate_loss();
            int alteration_sign;
            if (this->loss > 0) {
                alteration_sign = -1;
            } else if (this->loss < 0) {
                alteration_sign = 1;
            } else {
                this->desired_potential = std::nan("None");
                return true;
            }

            double alteration_value = pow(this->loss, 2);
            alteration_value = alteration_value * pow(
                this->network->decay_factor,
                (this->network->fire_counter/1000)
            );

            for (auto& it: this->subscriptions) {
                it.first->desired_potential = it.first->potential
                    + alteration_sign
                    * this->derivative(it.first->potential);
                this->subscriptions[it.first] = it.second
                    + (alteration_value * alteration_sign)
                    * this->derivative(it.first->potential);
            }
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %fs:0x28, %rax
movq %rax, -0x8(%rbp)
movq %rdi, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x1, 0xa8(%rax)
je 0x16fa3
movq -0x50(%rbp), %rdi
callq 0x16bd0
movq -0x50(%rbp), %rax
movsd %xmm0, 0xa0(%rax)
movq 0x28(%rax), %rcx
movq 0x180(%rcx), %rdx
addq $0x1, %rdx
movq %rdx, 0x180(%rcx)
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movsd (%rax), %xmm0
callq 0x19460
testb $0x1, %al
jne 0x16fa1
movq -0x50(%rbp), %rdi
callq 0x16d30
movq -0x50(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16def
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x16e25
movq -0x50(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd 0x8(%rax), %xmm0
jbe 0x16e06
movl $0x1, -0x2c(%rbp)
jmp 0x16e23
leaq 0x1023f(%rip), %rdi     # 0x2704c
callq 0x16050
movq -0x50(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x1, -0x19(%rbp)
jmp 0x16fa7
jmp 0x16e25
movq -0x50(%rbp), %rax
movsd 0x8(%rax), %xmm0
movl $0x2, %edi
callq 0x19480
movq -0x50(%rbp), %rax
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq 0x28(%rax), %rcx
movsd 0x90(%rcx), %xmm0
movq 0x28(%rax), %rax
movq 0x180(%rax), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
callq 0x194b0
movq -0x50(%rbp), %rax
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
addq $0x30, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x19500
movq %rax, -0x10(%rbp)
movq -0x40(%rbp), %rdi
callq 0x19530
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x193d0
testb $0x1, %al
jne 0x16ec1
jmp 0x16f9f
leaq -0x10(%rbp), %rdi
callq 0x19560
movq -0x50(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movsd 0xa0(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movsd 0xa0(%rax), %xmm0
callq 0x16d00
movsd -0x80(%rbp), %xmm1
movq -0x50(%rbp), %rdi
movaps %xmm0, %xmm2
movsd -0x78(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x48(%rbp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x38(%rbp), %xmm0
cvtsi2sdl -0x2c(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movsd 0xa0(%rax), %xmm0
callq 0x16d00
movsd -0x70(%rbp), %xmm1
movq -0x50(%rbp), %rdi
movaps %xmm0, %xmm2
movsd -0x68(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
addq $0x30, %rdi
movq -0x48(%rbp), %rsi
callq 0x19590
movsd -0x60(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x10(%rbp), %rdi
callq 0x195c0
jmp 0x16eab
jmp 0x16fa1
jmp 0x16fa3
movb $0x0, -0x19(%rbp)
movb -0x19(%rbp), %al
movb %al, -0x81(%rbp)
movq %fs:0x28, %rax
movq -0x8(%rbp), %rcx
cmpq %rcx, %rax
jne 0x16fd3
movb -0x81(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
callq 0x16340
nopl (%rax,%rax)