// File: /workspace/github_cpp_makefile_star2_O1/gkosae[P]ArduinoNeuralNet/neuralnet.cpp
// Function: NeuralNet::writeBody(std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>>&)
void NeuralNet::writeBody(stringstream& ss) {
    ss << "NeuralNet network{};\n\n";

    ss << "// Function to populate neural network\n";
    ss << "void populateNetwork() {\n";
    ss << "\tvector<Neuron> temp{};\n\n";

    std::string input_neuron_prefix = "in_";
    std::string output_neuron_prefix = "out_";
    std::string hidden_layer_prefix = "hi_";

    ss << "\t// Input layer\n";
    unsigned short number_of_inputs = layers.front().size();
    for(auto i = 0; i < number_of_inputs; i++) {
      ss << "\tNeuron " << input_neuron_prefix << i+1 << "{};";
      ss << "\ttemp.push_back(" << input_neuron_prefix << i+1 << ");\n";
    }

    ss << "\tLayer input_layer{temp};\n";
    ss << "\tnetwork.addLayer(input_layer);\n";
    ss << "\ttemp.clear();\n\n";

    // Create hidden layers
    unsigned short number_of_hidden_layers = layers.size() - 2;
    for(auto i = 0; i < number_of_hidden_layers; i++) {

        ss << "\t// Hidden layer " << i+1 << '\n';
        unsigned int current_layer_size = layers.at(i+1).size();
        for(auto j = 0; j < current_layer_size; j++) {
            ss << "\tNeuron " << hidden_layer_prefix << i+1 << "_" << j+1 << "{vector<double>{";
            unsigned short number_of_weights = layers.at(i+1).neurons.at(j).weights.size();

            for(auto k = 0; k <  number_of_weights; k++) {
              ss << layers.at(i+1).neurons.at(j).weights.at(k);
              if(k != number_of_weights - 1) ss << ", ";
            }

            ss << "}, " << layers.at(i+1).neurons.at(j).threshold << "};";
            ss << "\ttemp.push_back(" << hidden_layer_prefix << i+1 << "_" << j+1 << ");\n";
        }

        ss << "\tLayer " << hidden_layer_prefix << i+1 << "{temp};\n";
        ss << "\tnetwork.addLayer(" << hidden_layer_prefix << i+1 << ");\n";
        ss << "\ttemp.clear();\n\n";
    }


    ss << "\t// Output layer\n";
    unsigned short number_of_outputs = layers.back().size();
    for(auto i = 0; i < number_of_outputs; i++) {
      ss << "\tNeuron " << output_neuron_prefix << i+1 << "{vector<double>{";

      unsigned short number_of_weights = layers.back().neurons.at(i).weights.size();

      for(auto j = 0; j < number_of_weights; j++) {
        ss << layers.back().neurons.at(i).weights.at(j);
        if(j != number_of_weights - 1)ss << ", ";
      }

      ss << "}, " << layers.back().neurons.at(i).threshold << "};";
      ss << "\ttemp.push_back(" << output_neuron_prefix << i+1 << ");\n";
    }

    ss << "\tLayer output_layer{temp};\n";
    ss << "\tnetwork.addLayer(output_layer);\n";
    ss << "\ttemp.clear();\n\n";

    ss << "}\n\n";

    ss << "// Arduino boilerplate\n";
    ss << "void setup() {\n";
    ss << "\t populateNetwork();\n";
    ss << "}\n\n";
    ss << "void loop() {\n \n}\n\n";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
addq $0x10, %rbx
leaq 0x2bfd(%rip), %rsi      # 0x72b9
movl $0x16, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2c00(%rip), %rsi      # 0x72d0
movl $0x27, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2c14(%rip), %rsi      # 0x72f8
movl $0x19, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2c1a(%rip), %rsi      # 0x7312
movl $0x19, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2c17(%rip), %rsi      # 0x732c
leaq 0x2c13(%rip), %rdx      # 0x732f
leaq 0x68(%rsp), %rdi
callq 0x2850
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2bfa(%rip), %rsi      # 0x7330
leaq 0x2bf7(%rip), %rdx      # 0x7334
leaq 0x48(%rsp), %rdi
callq 0x2850
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2bde(%rip), %rsi      # 0x7335
leaq 0x2bda(%rip), %rdx      # 0x7338
leaq 0x20(%rsp), %rdi
callq 0x2850
leaq 0x2bca(%rip), %rsi      # 0x7339
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2190
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x20(%rax), %ecx
subl 0x18(%rax), %ecx
shrl $0x6, %ecx
movzwl %cx, %r13d
negl %r13d
movl $0x1, %r15d
leaq 0x2ba8(%rip), %r14      # 0x734a
leaq 0x2bae(%rip), %rbp      # 0x7357
leaq 0x2cd1(%rip), %r12      # 0x7481
leal (%r15,%r13), %eax
cmpl $0x1, %eax
je 0x4843
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2190
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movl %r15d, %esi
callq 0x2250
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2b5a(%rip), %rsi      # 0x7353
callq 0x2190
movl $0x10, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2190
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movl %r15d, %esi
callq 0x2250
incl %r15d
movl $0x3, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
jmp 0x47b0
leaq 0x2b1e(%rip), %rsi      # 0x7368
movl $0x1a, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2b25(%rip), %rsi      # 0x7383
movl $0x20, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2b32(%rip), %rsi      # 0x73a4
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2190
movq 0x8(%rsp), %rcx
movl 0x20(%rcx), %eax
subl 0x18(%rcx), %eax
shrl $0x4, %eax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
addl $0xfffe, %eax           # imm = 0xFFFE
movzwl %ax, %eax
movq %rax, 0x88(%rsp)
xorl %ebp, %ebp
leaq 0x2a8b(%rip), %r15      # 0x7337
movq %rbx, 0x18(%rsp)
cmpq 0x88(%rsp), %rbp
je 0x4c7e
movl $0x11, %edx
movq %rbx, %rdi
leaq 0x2ae7(%rip), %rsi      # 0x73b5
callq 0x2190
incq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2250
movb $0xa, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7(%rsp), %rsi
callq 0x2190
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 %rbp, %rdx
jbe 0x4fcc
leaq (,%rbp,2), %r12
addq %rbp, %r12
shlq $0x4, %r12
movl 0x20(%rax,%r12), %ecx
subl 0x18(%rax,%r12), %ecx
shrl $0x6, %ecx
movzwl %cx, %eax
movq %rax, 0x90(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x90(%rsp), %rax
je 0x4bdd
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x29d6(%rip), %rsi      # 0x734a
callq 0x2190
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movl %ebp, %esi
callq 0x2250
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2190
movq 0x10(%rsp), %rax
leaq 0x1(%rax), %rsi
movq %r13, %rdi
movq %rsi, 0x40(%rsp)
callq 0x2250
movl $0x10, %edx
movq %rax, %rdi
leaq 0x29fa(%rip), %rsi      # 0x73c7
callq 0x2190
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %rbp, %rdx
jbe 0x4f96
movq 0x18(%rcx,%r12), %rax
movq 0x20(%rcx,%r12), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
movq 0x10(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x4f99
movq %rsi, %r13
shlq $0x6, %r13
movl 0x28(%rax,%r13), %ecx
subl 0x20(%rax,%r13), %ecx
shrl $0x3, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
je 0x4add
leal -0x1(%rcx), %ebx
movl %ecx, %r14d
xorl %r15d, %r15d
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 %rbp, %rdx
jbe 0x4f85
movq 0x18(%rax,%r12), %rcx
movq 0x20(%rax,%r12), %rdx
subq %rcx, %rdx
sarq $0x6, %rdx
cmpq 0x10(%rsp), %rdx
jbe 0x4f79
movq 0x20(%rcx,%r13), %rax
movq 0x28(%rcx,%r13), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x4f80
movsd (%rax,%r15,8), %xmm0
movq 0x18(%rsp), %rdi
callq 0x2200
cmpq %r15, %rbx
je 0x4ad1
movl $0x2, %edx
movq 0x18(%rsp), %rdi
leaq 0x290d(%rip), %rsi      # 0x73d9
callq 0x2190
incq %r15
cmpq %r15, %r14
jne 0x4a45
movl $0x3, %edx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
leaq 0x28e7(%rip), %rsi      # 0x73d8
callq 0x2190
leaq 0x283a(%rip), %r15      # 0x7337
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 %rbp, %rdx
jbe 0x4f96
movq 0x18(%rax,%r12), %rcx
movq 0x20(%rax,%r12), %rdx
subq %rcx, %rdx
sarq $0x6, %rdx
movq 0x10(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x4f99
movsd 0x18(%rcx,%r13), %xmm0
movq %rbx, %rdi
callq 0x2200
movl $0x2, %edx
movq %rax, %rdi
leaq 0x27ef(%rip), %rsi      # 0x7354
callq 0x2190
movl $0x10, %edx
movq %rbx, %rdi
leaq 0x27de(%rip), %rsi      # 0x7357
callq 0x2190
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movl %ebp, %esi
callq 0x2250
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2190
movq %r13, %rdi
movq 0x40(%rsp), %rsi
callq 0x2250
movl $0x3, %edx
movq %rax, %rdi
leaq 0x28b8(%rip), %rsi      # 0x7481
callq 0x2190
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x4952
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x27f0(%rip), %rsi      # 0x73dc
callq 0x2190
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movl %ebp, %esi
callq 0x2250
movl $0x8, %edx
movq %rax, %rdi
leaq 0x275e(%rip), %rsi      # 0x737a
callq 0x2190
movl $0x12, %edx
movq %rbx, %rdi
leaq 0x27b4(%rip), %rsi      # 0x73e4
callq 0x2190
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movl %ebp, %esi
callq 0x2250
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2821(%rip), %rsi      # 0x7481
callq 0x2190
movl $0x10, %edx
movq %rbx, %rdi
leaq 0x2730(%rip), %rsi      # 0x73a4
callq 0x2190
jmp 0x48b1
leaq 0x2772(%rip), %rsi      # 0x73f7
movl $0x11, %edx
movq %rbx, %rdi
callq 0x2190
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movl -0x10(%rax), %ecx
subl -0x18(%rax), %ecx
shrl $0x6, %ecx
movzwl %cx, %eax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
cmpq 0x10(%rsp), %r12
je 0x4e5f
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x2681(%rip), %rsi      # 0x734a
callq 0x2190
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
leaq 0x1(%r12), %r13
movq %rax, %rdi
movl %r13d, %esi
callq 0x2250
movl $0x10, %edx
movq %rax, %rdi
leaq 0x26c8(%rip), %rsi      # 0x73c7
callq 0x2190
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rcx), %rax
movq -0x10(%rcx), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r12, %rdx
jbe 0x4fbb
movq %r12, %rbp
shlq $0x6, %rbp
movl 0x28(%rax,%rbp), %ecx
subl 0x20(%rax,%rbp), %ecx
shrl $0x3, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
je 0x4db6
leal -0x1(%rcx), %ebx
movl %ecx, %r14d
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rcx), %rax
movq -0x10(%rcx), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r12, %rdx
jbe 0x4faa
movq 0x20(%rax,%rbp), %rcx
movq 0x28(%rax,%rbp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x4fa7
movsd (%rcx,%r15,8), %xmm0
movq 0x18(%rsp), %rdi
callq 0x2200
cmpq %r15, %rbx
je 0x4dae
movl $0x2, %edx
movq 0x18(%rsp), %rdi
leaq 0x2630(%rip), %rsi      # 0x73d9
callq 0x2190
incq %r15
cmpq %r15, %r14
jne 0x4d48
movl $0x3, %edx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
leaq 0x260e(%rip), %rsi      # 0x73d8
callq 0x2190
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rcx), %rax
movq -0x10(%rcx), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r12, %rdx
jbe 0x4fbb
movsd 0x18(%rax,%rbp), %xmm0
movq %rbx, %rdi
callq 0x2200
movl $0x2, %edx
movq %rax, %rdi
leaq 0x2547(%rip), %rsi      # 0x7354
callq 0x2190
movl $0x10, %edx
movq %rbx, %rdi
leaq 0x2536(%rip), %rsi      # 0x7357
callq 0x2190
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movl %r13d, %esi
callq 0x2250
movl $0x3, %edx
movq %rax, %rdi
leaq 0x262f(%rip), %rsi      # 0x7481
callq 0x2190
movq %r13, %r12
jmp 0x4caf
leaq 0x25a3(%rip), %rsi      # 0x7409
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x25ab(%rip), %rsi      # 0x7425
movl $0x21, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2516(%rip), %rsi      # 0x73a4
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x25f3(%rip), %rsi      # 0x7495
movl $0x3, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2591(%rip), %rsi      # 0x7447
movl $0x17, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2595(%rip), %rsi      # 0x745f
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x2591(%rip), %rsi      # 0x746f
movl $0x15, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x25a3(%rip), %rsi      # 0x7495
movl $0x3, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x257f(%rip), %rsi      # 0x7485
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2190
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x4f2f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4f4b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x4f67
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2180
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rsi
jmp 0x4f88
movq %r15, %rsi
jmp 0x4f88
movq %rbp, %rsi
leaq 0x2124(%rip), %rdi      # 0x70b3
xorl %eax, %eax
callq 0x21d0
movq %rbp, %rsi
leaq 0x2113(%rip), %rdi      # 0x70b3
xorl %eax, %eax
callq 0x21d0
movq %r15, %r12
leaq 0x2102(%rip), %rdi      # 0x70b3
movq %r12, %rsi
xorl %eax, %eax
callq 0x21d0
leaq 0x20f1(%rip), %rdi      # 0x70b3
movq %r12, %rsi
xorl %eax, %eax
callq 0x21d0
leaq 0x20e0(%rip), %rdi      # 0x70b3
movq %rbp, %rsi
xorl %eax, %eax
callq 0x21d0
jmp 0x5009
jmp 0x5009
movq %rax, %rbx
jmp 0x5028
movq %rax, %rbx
jmp 0x5044
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
jmp 0x5009
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5028
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x5044
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x5060
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2260