// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%rsp)
addq $0x10, %rbx
leaq 0x22f5(%rip), %rsi      # 0x62a1
movq %rbx, %rdi
callq 0x2150
leaq 0x22fd(%rip), %rsi      # 0x62b8
movq %rbx, %rdi
callq 0x2150
leaq 0x2316(%rip), %rsi      # 0x62e0
movq %rbx, %rdi
callq 0x2150
leaq 0x2321(%rip), %rsi      # 0x62fa
movq %rbx, %rdi
callq 0x2150
leaq 0x232c(%rip), %rsi      # 0x6314
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2742
leaq 0x231a(%rip), %rsi      # 0x6318
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x2742
leaq 0x2309(%rip), %rsi      # 0x631d
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x2742
leaq 0x22f7(%rip), %rsi      # 0x6321
movq %rbx, %r15
movq %rbx, %rdi
callq 0x2150
movq 0x10(%rsp), %rax
leaq 0x18(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x18(%rax), %rax
movl 0x20(%rax), %ecx
subl 0x18(%rax), %ecx
shrl $0x6, %ecx
movzwl %cx, %r12d
negl %r12d
pushq $0x1
popq %r14
leaq 0x22d0(%rip), %rbx      # 0x6332
leaq 0x78(%rsp), %r13
leaq 0x23fb(%rip), %rbp      # 0x6469
leal (%r12,%r14), %eax
cmpl $0x1, %eax
je 0x40dc
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2150
movq %rax, %rdi
movq %r13, %rsi
callq 0x2130
movq %rax, %rdi
movl %r14d, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x2299(%rip), %rsi      # 0x633b
callq 0x2150
movq %r15, %rdi
leaq 0x228e(%rip), %rsi      # 0x633f
callq 0x2150
movq %rax, %rdi
movq %r13, %rsi
callq 0x2130
movq %rax, %rdi
movl %r14d, %esi
callq 0x2250
incl %r14d
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2150
jmp 0x406e
leaq 0x226d(%rip), %rsi      # 0x6350
movq %r15, %rbx
movq %r15, %rdi
callq 0x2150
leaq 0x2276(%rip), %rsi      # 0x636b
movq %rbx, %rdi
callq 0x2150
leaq 0x2288(%rip), %rsi      # 0x638c
movq %rbx, %rdi
callq 0x2150
movq 0x10(%rsp), %rcx
movq 0x20(%rcx), %rax
subq 0x18(%rcx), %rax
pushq $0x30
popq %rcx
cqto
idivq %rcx
addl $0xfffe, %eax           # imm = 0xFFFE
movzwl %ax, %eax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
cmpq 0x28(%rsp), %r12
je 0x4393
movq %rbx, %rdi
leaq 0x2257(%rip), %rsi      # 0x639d
callq 0x2150
incq %r12
movq %rax, %rdi
movl %r12d, %esi
callq 0x2250
movq %rax, %rdi
pushq $0xa
popq %rsi
callq 0x2180
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x47c0
movl 0x20(%rax), %ecx
subl 0x18(%rax), %ecx
shrl $0x6, %ecx
movzwl %cx, %eax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
cmpq 0x30(%rsp), %rbp
je 0x4310
movq %r15, %rdi
leaq 0x2199(%rip), %rsi      # 0x6332
callq 0x2150
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2130
movq %rax, %rdi
movl %r12d, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x215f(%rip), %rsi      # 0x631f
callq 0x2150
leaq 0x1(%rbp), %rsi
movq %rax, %rdi
movq %rsi, 0x20(%rsp)
callq 0x2250
movq %rax, %rdi
leaq 0x21cf(%rip), %rsi      # 0x63af
callq 0x2150
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x47c0
addq $0x18, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x479e
movl 0x28(%rax), %ecx
subl 0x20(%rax), %ecx
shrl $0x3, %ecx
movzwl %cx, %r13d
leal -0x1(%r13), %ebx
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x426a
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x47c0
addq $0x18, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x479e
addq $0x20, %rax
movq %rax, %rdi
movq %r14, %rsi
callq 0x264c
movsd (%rax), %xmm0
movq %r15, %rdi
callq 0x21f0
cmpq %r14, %rbx
je 0x4265
movq %r15, %rdi
leaq 0x2161(%rip), %rsi      # 0x63c1
callq 0x2150
incq %r14
jmp 0x4215
movq %r15, %rdi
leaq 0x214c(%rip), %rsi      # 0x63c0
callq 0x2150
movq %rax, %r14
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x47c0
addq $0x18, %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x479e
movsd 0x18(%rax), %xmm0
movq %r14, %rdi
callq 0x21f0
movq %rax, %rdi
leaq 0x208d(%rip), %rsi      # 0x633c
callq 0x2150
movq %r15, %rdi
leaq 0x2081(%rip), %rsi      # 0x633f
callq 0x2150
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2130
movq %rax, %rdi
movl %r12d, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x203a(%rip), %rsi      # 0x631f
callq 0x2150
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x2250
movq %rax, %rdi
leaq 0x2168(%rip), %rsi      # 0x6469
callq 0x2150
movq 0x20(%rsp), %rbp
jmp 0x4184
movq %r15, %rbx
movq %r15, %rdi
leaq 0x20a7(%rip), %rsi      # 0x63c4
callq 0x2150
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2130
movq %rax, %rdi
movl %r12d, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x201e(%rip), %rsi      # 0x6362
callq 0x2150
movq %rbx, %rdi
leaq 0x2079(%rip), %rsi      # 0x63cc
callq 0x2150
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2130
movq %rax, %rdi
movl %r12d, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x20ef(%rip), %rsi      # 0x6469
callq 0x2150
movq %rbx, %rdi
leaq 0x2003(%rip), %rsi      # 0x638c
callq 0x2150
jmp 0x4131
leaq 0x2045(%rip), %rsi      # 0x63df
movq %rbx, %rdi
callq 0x2150
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movl -0x10(%rax), %ecx
subl -0x18(%rax), %ecx
shrl $0x6, %ecx
movzwl %cx, %eax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
leaq 0x58(%rsp), %rbx
leaq 0x1ff7(%rip), %r13      # 0x63c1
cmpq 0x20(%rsp), %rbp
je 0x450c
movq %r15, %rdi
leaq 0x1f53(%rip), %rsi      # 0x6332
callq 0x2150
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2130
leaq 0x1(%rbp), %rbx
movq %rax, %rdi
movl %ebx, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x1fa8(%rip), %rsi      # 0x63af
callq 0x2150
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
addq $-0x18, %rdi
movq %rbp, %rsi
callq 0x479e
movq %rbx, 0x18(%rsp)
movl 0x28(%rax), %ecx
subl 0x20(%rax), %ecx
shrl $0x3, %ecx
movzwl %cx, %ebx
leal -0x1(%rbx), %r14d
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x4483
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
addq $-0x18, %rdi
movq %rbp, %rsi
callq 0x479e
addq $0x20, %rax
movq %rax, %rdi
movq %r12, %rsi
callq 0x264c
movsd (%rax), %xmm0
movq %r15, %rdi
callq 0x21f0
cmpq %r12, %r14
je 0x447e
movq %r15, %rdi
movq %r13, %rsi
callq 0x2150
incq %r12
jmp 0x4439
movq %r15, %rdi
leaq 0x1f33(%rip), %rsi      # 0x63c0
callq 0x2150
leaq 0x58(%rsp), %rbx
movq 0x18(%rsp), %r14
movq %rax, %r12
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
addq $-0x18, %rdi
movq %rbp, %rsi
callq 0x479e
movsd 0x18(%rax), %xmm0
movq %r12, %rdi
callq 0x21f0
movq %rax, %rdi
leaq 0x1e71(%rip), %rsi      # 0x633c
callq 0x2150
movq %r15, %rdi
leaq 0x1e65(%rip), %rsi      # 0x633f
callq 0x2150
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2130
movq %rax, %rdi
movl %r14d, %esi
callq 0x2250
movq %rax, %rdi
leaq 0x1f6a(%rip), %rsi      # 0x6469
callq 0x2150
movq %r14, %rbp
jmp 0x43ca
leaq 0x1ede(%rip), %rsi      # 0x63f1
movq %r15, %rdi
callq 0x2150
leaq 0x1eeb(%rip), %rsi      # 0x640d
movq %r15, %rdi
callq 0x2150
leaq 0x1e5b(%rip), %rsi      # 0x638c
movq %r15, %rdi
callq 0x2150
leaq 0x1f3d(%rip), %rsi      # 0x647d
movq %r15, %rdi
callq 0x2150
leaq 0x1ee0(%rip), %rsi      # 0x642f
movq %r15, %rdi
callq 0x2150
leaq 0x1ee9(%rip), %rsi      # 0x6447
movq %r15, %rdi
callq 0x2150
leaq 0x1eea(%rip), %rsi      # 0x6457
movq %r15, %rdi
callq 0x2150
leaq 0x1f01(%rip), %rsi      # 0x647d
movq %r15, %rdi
callq 0x2150
leaq 0x1ee2(%rip), %rsi      # 0x646d
movq %r15, %rdi
callq 0x2150
leaq 0x38(%rsp), %rdi
callq 0x2080
leaq 0x58(%rsp), %rdi
callq 0x2080
leaq 0x78(%rsp), %rdi
callq 0x2080
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x45e5
jmp 0x45e5
movq %rax, %rbx
jmp 0x45f2
movq %rax, %rbx
jmp 0x45fc
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
jmp 0x45e5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2080
leaq 0x58(%rsp), %rdi
callq 0x2080
leaq 0x78(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2260