// File: /workspace/github_cpp_makefile_star2_O1/gkosae[P]ArduinoNeuralNet/neuralnet.cpp
// Function: NeuralNet::backpropagateErrors()
void NeuralNet::backpropagateErrors() {
    // Calculate delta (backpropagating error) for output layer
    unsigned short output_layer_size = layers.back().size();

    for(auto i = 0; i < output_layer_size; ++i) {

        layers.back().neurons.at(i).delta = (actual_output.at(current_sample).at(i) -
                                             expected_output.at(current_sample).at(i)) *
                                             layers.back().neurons.at(i).sigmoidPrime();
    }

    unsigned short number_of_hidden_layers = layers.size() - 2;

    for(auto i = number_of_hidden_layers; i > 0 ; --i) {

      unsigned short current_layer_size = layers.at(i).size();
      unsigned short next_layer_size = layers.at(i+1).size();

      for(auto j = 0; j < current_layer_size; ++j) {

          double delta = 0;
          for(auto k = 0; k <  next_layer_size; k++) {
              delta += (layers.at(i+1).neurons.at(k).delta *
                        layers.at(i+1).neurons.at(k).weights.at(j) *
                        layers.at(i).neurons.at(j).sigmoidPrime());
          }

          layers.at(i).neurons.at(j).delta = delta;
      }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbp
movq 0x20(%rdi), %rcx
movl -0x10(%rcx), %eax
subl -0x18(%rcx), %eax
shrl $0x6, %eax
andl $0xffff, %eax           # imm = 0xFFFF
je 0x3836
movl %eax, %r15d
movl $0x38, %r12d
xorl %r14d, %r14d
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movl 0x78(%rbp), %esi
movq 0x30(%rbp), %r8
movq 0x38(%rbp), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x3ac1
leaq (%rsi,%rsi,2), %rcx
movq (%r8,%rcx,8), %rax
movq 0x8(%r8,%rcx,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r14, %rdx
jbe 0x3aca
movq 0x48(%rbp), %r8
movq 0x50(%rbp), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x3ac1
movq (%r8,%rcx,8), %rsi
movq 0x8(%r8,%rcx,8), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
cmpq %r14, %rdx
jbe 0x3aca
movq 0x20(%rbp), %rcx
movq -0x18(%rcx), %rbx
movq -0x10(%rcx), %rdx
subq %rbx, %rdx
sarq $0x6, %rdx
cmpq %r14, %rdx
jbe 0x3aca
movsd (%rax,%r14,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd (%rsi,%r14,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd -0x30(%rbx,%r12), %xmm0
movaps 0x3884(%rip), %xmm1     # 0x7040
xorps %xmm1, %xmm0
callq 0x2270
movsd %xmm0, 0x10(%rsp)
movsd -0x30(%rbx,%r12), %xmm0
xorpd 0x3867(%rip), %xmm0     # 0x7040
callq 0x2270
movq 0x20(%rbp), %rcx
movq -0x18(%rcx), %rax
movq -0x10(%rcx), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r14, %rdx
jbe 0x3aca
movsd 0x20(%rsp), %xmm1
subsd 0x18(%rsp), %xmm1
addsd 0x380a(%rip), %xmm0     # 0x7018
mulsd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, (%rax,%r12)
incq %r14
addq $0x40, %r12
cmpq %r14, %r15
jne 0x3709
movl 0x20(%rbp), %eax
subl 0x18(%rbp), %eax
shrl $0x4, %eax
imull $0xffffaaab, %eax, %esi # imm = 0xFFFFAAAB
addw $-0x2, %si
je 0x3a87
movzwl %si, %esi
movq 0x18(%rbp), %rax
movq 0x20(%rbp), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x3ac1
leaq 0x1(%rsi), %r8
movq %r8, 0x8(%rsp)
cmpq %r8, %rdx
jbe 0x3aa2
leaq (%rsi,%rsi,2), %rdx
movq %rdx, 0x28(%rsp)
shll $0x4, %edx
movl 0x20(%rax,%rdx), %ecx
subl 0x18(%rax,%rdx), %ecx
shrl $0x6, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
je 0x3a7e
movq 0x8(%rsp), %rdx
leaq (%rdx,%rdx,2), %r9
movl %r9d, %edx
shll $0x4, %edx
movl 0x20(%rax,%rdx), %r8d
subl 0x18(%rax,%rdx), %r8d
shrl $0x6, %r8d
movzwl %r8w, %eax
movq %rax, 0x30(%rsp)
movl %ecx, %eax
movq %rax, 0x38(%rsp)
movq 0x28(%rsp), %rax
shll $0x4, %eax
movq %rax, 0x40(%rsp)
shll $0x4, %r9d
movq %r9, 0x50(%rsp)
xorl %r15d, %r15d
movq %rsi, 0x48(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x3a1d
xorpd %xmm0, %xmm0
movl $0x38, %r14d
xorl %r13d, %r13d
movq 0x18(%rbp), %rax
movq 0x20(%rbp), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq 0x8(%rsp), %rdx
jbe 0x3aa2
movq 0x50(%rsp), %rdx
movq 0x18(%rax,%rdx), %rcx
movq 0x20(%rax,%rdx), %rdx
subq %rcx, %rdx
sarq $0x6, %rdx
cmpq %r13, %rdx
jbe 0x3ab0
movq -0x18(%rcx,%r14), %rsi
movq -0x10(%rcx,%r14), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x3a96
movq 0x28(%rsp), %rdx
shll $0x4, %edx
movq 0x18(%rax,%rdx), %rbx
movq 0x20(%rax,%rdx), %rdx
subq %rbx, %rdx
sarq $0x6, %rdx
cmpq %r15, %rdx
jbe 0x3a96
movsd (%rcx,%r14), %xmm1
mulsd (%rsi,%r15,8), %xmm1
movsd %xmm1, 0x18(%rsp)
movq %r15, %r12
shlq $0x6, %r12
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rbx,%r12), %xmm0
movaps 0x367f(%rip), %xmm1     # 0x7040
xorps %xmm1, %xmm0
callq 0x2270
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rbx,%r12), %xmm0
xorpd 0x3662(%rip), %xmm0     # 0x7040
callq 0x2270
addsd 0x362d(%rip), %xmm0     # 0x7018
mulsd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm1
addsd %xmm1, %xmm0
incq %r13
addq $0x40, %r14
cmpq %r13, 0x30(%rsp)
jne 0x3911
jmp 0x3a21
xorpd %xmm0, %xmm0
movq 0x18(%rbp), %rax
movq 0x20(%rbp), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
movq 0x48(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x3ac1
movq 0x40(%rsp), %rdx
movq 0x18(%rax,%rdx), %rcx
movq 0x20(%rax,%rdx), %rdx
subq %rcx, %rdx
sarq $0x6, %rdx
cmpq %r15, %rdx
jbe 0x3a96
movq %r15, %rax
shlq $0x6, %rax
movsd %xmm0, 0x38(%rcx,%rax)
incq %r15
cmpq 0x38(%rsp), %r15
jne 0x38f8
decw %si
jne 0x384f
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3616(%rip), %rdi      # 0x70b3
movq %r15, %rsi
jmp 0x3aba
leaq 0x360a(%rip), %rdi      # 0x70b3
movq 0x8(%rsp), %rsi
jmp 0x3aba
leaq 0x35fc(%rip), %rdi      # 0x70b3
movq %r13, %rsi
xorl %eax, %eax
callq 0x21d0
leaq 0x35eb(%rip), %rdi      # 0x70b3
jmp 0x3aba
leaq 0x35e2(%rip), %rdi      # 0x70b3
movq %r14, %rsi
jmp 0x3aba