// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movq 0x20(%rdi), %rcx
movq -0x18(%rcx), %r15
movq -0x10(%rcx), %rdx
movl %edx, %eax
subl %r15d, %eax
shrl $0x6, %eax
andl $0xffff, %eax           # imm = 0xFFFF
je 0x38bf
movl %eax, %r12d
movl $0x38, %r13d
xorl %r14d, %r14d
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
movq 0x8(%rsp), %rax
movl 0x78(%rax), %esi
movq 0x30(%rax), %r8
movq 0x38(%rax), %rax
subq %r8, %rax
sarq $0x3, %rax
imulq %rbp, %rax
cmpq %rsi, %rax
jbe 0x3b67
leaq (%rsi,%rsi,2), %rdi
movq (%r8,%rdi,8), %rcx
movq 0x8(%r8,%rdi,8), %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x3b5b
movq 0x8(%rsp), %rax
movq 0x48(%rax), %r8
movq 0x50(%rax), %rax
subq %r8, %rax
sarq $0x3, %rax
imulq %rbp, %rax
cmpq %rsi, %rax
jbe 0x3b67
movq (%r8,%rdi,8), %rsi
movq 0x8(%r8,%rdi,8), %rax
subq %rsi, %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x3b5b
subq %r15, %rdx
sarq $0x6, %rdx
cmpq %r14, %rdx
jbe 0x3b73
movsd (%rcx,%r14,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd (%rsi,%r14,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd -0x30(%r15,%r13), %xmm0
movaps 0x3803(%rip), %xmm1     # 0x7040
xorps %xmm1, %xmm0
callq 0x2270
movsd %xmm0, 0x18(%rsp)
movsd -0x30(%r15,%r13), %xmm0
xorpd 0x37e6(%rip), %xmm0     # 0x7040
callq 0x2270
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rcx), %r15
movq -0x10(%rcx), %rdx
movq %rdx, %rax
subq %r15, %rax
sarq $0x6, %rax
cmpq %r14, %rax
jbe 0x3b5b
movsd 0x28(%rsp), %xmm1
subsd 0x20(%rsp), %xmm1
addsd 0x3781(%rip), %xmm0     # 0x7018
mulsd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, (%r15,%r13)
incq %r14
addq $0x40, %r13
cmpq %r14, %r12
jne 0x378c
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %ecx, %edx
subl %eax, %edx
shrl $0x4, %edx
imull $0xffffaaab, %edx, %esi # imm = 0xFFFFAAAB
addw $-0x2, %si
je 0x3b18
movzwl %si, %esi
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdi, %rdx
cmpq %rsi, %rdx
jbe 0x3b52
leaq 0x1(%rsi), %r8
movq %r8, 0x10(%rsp)
cmpq %r8, %rdx
jbe 0x3b33
leaq (%rsi,%rsi,2), %r9
movl %r9d, %edi
shll $0x4, %edi
movl 0x20(%rax,%rdi), %edx
subl 0x18(%rax,%rdi), %edx
shrl $0x6, %edx
andl $0xffff, %edx           # imm = 0xFFFF
je 0x3b0f
movq 0x10(%rsp), %rdi
leaq (%rdi,%rdi,2), %r8
movq %r8, 0x50(%rsp)
shll $0x4, %r8d
movl 0x20(%rax,%r8), %edi
subl 0x18(%rax,%r8), %edi
shrl $0x6, %edi
movzwl %di, %edi
movq %rdi, 0x30(%rsp)
movl %edx, %edx
movq %rdx, 0x40(%rsp)
movl %r9d, %edx
shll $0x4, %edx
movq %rdx, 0x48(%rsp)
xorl %ebp, %ebp
movq %rsi, 0x38(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x3ab8
xorpd %xmm0, %xmm0
movl $0x38, %r14d
xorl %r13d, %r13d
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rax
movq 0x20(%rcx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq 0x10(%rsp), %rdx
jbe 0x3b33
movq 0x50(%rsp), %rdx
shll $0x4, %edx
movq 0x18(%rax,%rdx), %rcx
movq 0x20(%rax,%rdx), %rdx
subq %rcx, %rdx
sarq $0x6, %rdx
cmpq %r13, %rdx
jbe 0x3b41
movq -0x18(%rcx,%r14), %rsi
movq -0x10(%rcx,%r14), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x3b27
movl %r9d, %edx
shll $0x4, %edx
movq 0x18(%rax,%rdx), %rbx
movq 0x20(%rax,%rdx), %rdx
subq %rbx, %rdx
sarq $0x6, %rdx
cmpq %rbp, %rdx
jbe 0x3b27
movq %r9, %r15
movsd (%rcx,%r14), %xmm1
mulsd (%rsi,%rbp,8), %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbp, %r12
shlq $0x6, %r12
movsd %xmm0, 0x28(%rsp)
movsd 0x8(%rbx,%r12), %xmm0
movaps 0x35f9(%rip), %xmm1     # 0x7040
xorps %xmm1, %xmm0
callq 0x2270
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rbx,%r12), %xmm0
xorpd 0x35dc(%rip), %xmm0     # 0x7040
callq 0x2270
addsd 0x35a7(%rip), %xmm0     # 0x7018
mulsd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm1
addsd %xmm1, %xmm0
incq %r13
addq $0x40, %r14
cmpq %r13, 0x30(%rsp)
movq %r15, %r9
jne 0x398f
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rax
movq 0x20(%rcx), %rcx
movq 0x38(%rsp), %rsi
jmp 0x3abc
xorpd %xmm0, %xmm0
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdi, %rdx
cmpq %rsi, %rdx
jbe 0x3b52
movq 0x48(%rsp), %rdx
movq 0x18(%rax,%rdx), %rdi
movq 0x20(%rax,%rdx), %rdx
subq %rdi, %rdx
sarq $0x6, %rdx
cmpq %rbp, %rdx
jbe 0x3b27
movq %rbp, %rdx
shlq $0x6, %rdx
movsd %xmm0, 0x38(%rdi,%rdx)
incq %rbp
cmpq 0x40(%rsp), %rbp
jne 0x3976
decw %si
jne 0x38df
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x35b5(%rip), %rdi      # 0x70e3
movq %rbp, %rsi
jmp 0x3b4b
leaq 0x35a9(%rip), %rdi      # 0x70e3
movq 0x10(%rsp), %rsi
jmp 0x3b4b
leaq 0x359b(%rip), %rdi      # 0x70e3
movq %r13, %rsi
xorl %eax, %eax
callq 0x21d0
leaq 0x358a(%rip), %rdi      # 0x70e3
jmp 0x3b4b
leaq 0x3581(%rip), %rdi      # 0x70e3
movq %r14, %rsi
jmp 0x3b6e
leaq 0x3575(%rip), %rdi      # 0x70e3
movq %rax, %rdx
jmp 0x3b4b
leaq 0x3569(%rip), %rdi      # 0x70e3
movq %r14, %rsi
jmp 0x3b4b
nop