// File: gkosae[P]ArduinoNeuralNet/neuralnet.cpp
// Function: NeuralNet::adjustWeights()
void NeuralNet::adjustWeights() {
    unsigned short count = layers.size();

    for(auto i = 1; i < count; ++i) {
        unsigned short current_layer_size = layers.at(i).size();

        for(auto j = 0; j <  current_layer_size; ++j) {
            unsigned short number_of_weights = layers.at(i).neurons.at(j).getNumberOfWeights();
            double delta = layers.at(i).neurons.at(j).delta;

            for(auto k = 0; k < number_of_weights; ++k) {
                double old_weight = layers.at(i).neurons.at(j).weights.at(k);
                double change_in_weight = (delta * layers.at(i).inputs.at(k)) + lambda*old_weight;
                double new_weight = old_weight - change_in_weight*learning_rate;
                layers.at(i).neurons.at(j).weights.at(k) = new_weight;
            }

            double old_threshold = layers.at(i).neurons.at(j).threshold;
            double change_in_threshold = delta * layers.at(i).neurons.at(j).bias;
            double new_threshold = old_threshold - change_in_threshold*learning_rate;
            layers.at(i).neurons.at(j).threshold = new_threshold;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x68(%rbp)
addq $0x18, %rdi
callq 0x82e0
movw %ax, -0xa(%rbp)
movl $0x1, -0x10(%rbp)
movl -0x10(%rbp), %eax
movzwl -0xa(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6765
movq -0x68(%rbp), %rdi
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
callq 0x8220
movw %ax, -0x12(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6755
movq -0x68(%rbp), %rdi
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
addq $0x18, %rdi
movslq -0x18(%rbp), %rsi
callq 0x8240
movq %rax, %rdi
callq 0x83e0
movq -0x68(%rbp), %rdi
movw %ax, -0x1a(%rbp)
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
addq $0x18, %rdi
movslq -0x18(%rbp), %rsi
callq 0x8240
movsd 0x38(%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6674
movq -0x68(%rbp), %rdi
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
addq $0x18, %rdi
movslq -0x18(%rbp), %rsi
callq 0x8240
movq %rax, %rdi
addq $0x20, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x2b10
movq -0x68(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x2b10
movsd -0x78(%rbp), %xmm0
movq -0x68(%rbp), %rdi
movsd (%rax), %xmm2
movsd 0x80(%rdi), %xmm1
mulsd -0x38(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm1
movsd -0x40(%rbp), %xmm0
movsd 0x8(%rdi), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
addq $0x18, %rdi
movslq -0x18(%rbp), %rsi
callq 0x8240
movq %rax, %rdi
addq $0x20, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x2b10
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x655c
movq -0x68(%rbp), %rdi
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
addq $0x18, %rdi
movslq -0x18(%rbp), %rsi
callq 0x8240
movq -0x68(%rbp), %rdi
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
addq $0x18, %rdi
movslq -0x18(%rbp), %rsi
callq 0x8240
movsd -0x88(%rbp), %xmm0
movq -0x68(%rbp), %rdi
mulsd 0x10(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
movsd 0x8(%rdi), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
addq $0x18, %rdi
movslq -0x10(%rbp), %rsi
callq 0x8280
movq %rax, %rdi
addq $0x18, %rdi
movslq -0x18(%rbp), %rsi
callq 0x8240
movsd -0x80(%rbp), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x64ee
jmp 0x6757
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x64bb
addq $0x90, %rsp
popq %rbp
retq
nop