// File: /workspace/github_c_makefile_star2_O3/stonezwr[P]SpiKL-IP/simulator.C
// Function: Simulator::LSMRun(long)
void Simulator::LSMRun(long tid){
    //_network->PrintAllNeuronName();

    char filename[64];
    int info, count;
    int x,y,loss_neuron;
    int Tid;
    double temp;
    FILE * Fp = NULL;
    FILE * Foutp = NULL;
    networkmode_t networkmode;

    Timer myTimer;

    srand(0);
    _network->IndexSpeech();
    cout<<"Number of speeches: "<<_network->NumSpeech()<<endl;

    //for(int count = 0; count < _network->NumSpeech(); count++){
    //    // empty files
    //    sprintf(filename,"outputs/spikepattern%d.dat",count);
    //    InitializeFile(filename);
    //}

    if(tid == 0){
        sprintf(filename, "i_weights_info.txt");
        _network->WriteSynWeightsToFile("input", "reservoir", filename);
        sprintf(filename, "r_weights_recurrent_info.txt");
        _network->WriteSynWeightsToFile("reservoir", "reservoir", filename);
        sprintf(filename, "o_weights_info.txt");
        _network->WriteSynWeightsToFile("reservoir", "output", filename);
    }

#ifdef _RM_ZERO_RES_WEIGHT
    _network->RemoveZeroWeights("reservoir");
#endif  


    // produce transient state
    networkmode = TRANSIENTSTATE;
    _network->LSMSetNetworkMode(networkmode);
    myTimer.Start();
    _network->LSMTransientSim(networkmode, tid, "train_sample");
    myTimer.End("running transient");

    // train the readout layer
    myTimer.Start();
    networkmode = READOUT; // choose the readout supervised algorithm here!
    _network->LSMSetNetworkMode(networkmode);
    Tid = (int)tid;
    cout<<"Tid:"<<Tid<<endl;
    _network->Fold(Tid);

    for(int iii = 0; iii < NUM_ITERS; iii++){
        if(tid == 0)    cout<<"Run the iteration: "<<iii<<endl;
            // random shuffle the training samples for better generalization
        _network->ShuffleTrainingSamples();
        _network->LSMSupervisedTraining(networkmode, tid, iii);
            _network->CurrentPerformance(iii);
        }
    myTimer.End("supervised training the readout"); 
    if(tid == 0){
        sprintf(filename, "o_weights_info_trained_all.txt");
        _network->WriteSelectedSynToFile("readout", filename);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x13b14
xorl %edi, %edi
callq 0x32a0
movq 0x18(%rbx), %rdi
callq 0x1000a
movq 0xdf7b(%rip), %r15      # 0x20fd0
leaq 0x6868(%rip), %rsi      # 0x198c4
movl $0x14, %edx
movq %r15, %rdi
callq 0x3340
movq 0x18(%rbx), %rax
movq 0x210(%rax), %rsi
subq 0x208(%rax), %rsi
shrq $0x3, %rsi
movq %r15, %rdi
callq 0x3560
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
testq %r14, %r14
jne 0x13275
movups 0x6818(%rip), %xmm0     # 0x198d9
movaps %xmm0, 0x40(%rsp)
movl $0x747874, 0x4f(%rsp)   # imm = 0x747874
movq 0x18(%rbx), %r15
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x4201(%rip), %rsi      # 0x172e4
leaq 0x41ff(%rip), %rdx      # 0x172e9
movq %rsp, %rdi
callq 0xaf16
leaq 0x30(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x4217(%rip), %rsi      # 0x17319
leaq 0x4219(%rip), %rdx      # 0x17322
leaq 0x20(%rsp), %rdi
callq 0xaf16
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
callq 0x10a3c
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x1313f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x13155
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32f0
movups 0x6790(%rip), %xmm0     # 0x198ec
movaps %xmm0, 0x40(%rsp)
movups 0x6791(%rip), %xmm0     # 0x198f9
movups %xmm0, 0x4d(%rsp)
movq 0x18(%rbx), %r15
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x419b(%rip), %rsi      # 0x17319
leaq 0x419d(%rip), %rdx      # 0x17322
callq 0xaf16
leaq 0x20(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x4180(%rip), %rsi      # 0x17319
leaq 0x4182(%rip), %rdx      # 0x17322
callq 0xaf16
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
callq 0x10a3c
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x131d1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x131e7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32f0
movups 0x671b(%rip), %xmm0     # 0x19909
movaps %xmm0, 0x40(%rsp)
movl $0x747874, 0x4f(%rsp)   # imm = 0x747874
movq 0x18(%rbx), %r15
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x410d(%rip), %rsi      # 0x17319
leaq 0x410f(%rip), %rdx      # 0x17322
callq 0xaf16
leaq 0x20(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x5263(%rip), %rsi      # 0x1848a
leaq 0x5262(%rip), %rdx      # 0x18490
callq 0xaf16
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
callq 0x10a3c
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x1325f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x13275
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32f0
movq 0x18(%rbx), %rdi
leaq 0x4099(%rip), %rsi      # 0x17319
callq 0x1069e
movq 0x18(%rbx), %rax
movl $0x0, 0x2c0(%rax)
leaq 0xe8(%rsp), %rdi
callq 0x13b28
movq 0x18(%rbx), %r15
leaq 0xd8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x6665(%rip), %rsi      # 0x1991c
leaq 0x666a(%rip), %rdx      # 0x19928
leaq 0xc8(%rsp), %r12
movq %r12, %rdi
callq 0xaf16
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
movq %r12, %rcx
callq 0xdf1c
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x132fb
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32f0
leaq 0xb8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x661a(%rip), %rsi      # 0x19929
leaq 0x6624(%rip), %rdx      # 0x1993a
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0xaf16
leaq 0xe8(%rsp), %rdi
movq %r15, %rsi
callq 0x13c84
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x13353
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32f0
leaq 0xe8(%rsp), %rdi
callq 0x13b28
movq 0x18(%rbx), %rax
movl $0x1, 0x2c0(%rax)
movq 0xdc5b(%rip), %r15      # 0x20fd0
leaq 0x65bf(%rip), %rsi      # 0x1993b
movl $0x4, %edx
movq %r15, %rdi
callq 0x3340
movq %r15, %rdi
movl %r14d, %esi
callq 0x3560
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x18(%rbx), %rax
movl %r14d, 0x22c(%rax)
xorl %ebp, %ebp
leaq 0x656e(%rip), %r12      # 0x19940
testq %r14, %r14
jne 0x1341b
movl $0x13, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3340
movq %r15, %rdi
movl %ebp, %esi
callq 0x3560
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x18(%rbx), %rdi
callq 0x103f8
movq 0x18(%rbx), %rdi
movl $0x1, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0xec2c
movq 0x18(%rbx), %rdi
movl %ebp, %esi
callq 0x1003e
incl %ebp
cmpl $0x1f4, %ebp            # imm = 0x1F4
jne 0x133d2
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x64f4(%rip), %rsi      # 0x19954
leaq 0x650c(%rip), %rdx      # 0x19973
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0xaf16
leaq 0xe8(%rsp), %rdi
movq %r15, %rsi
callq 0x13c84
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x134a4
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32f0
testq %r14, %r14
jne 0x1350a
movups 0x64d3(%rip), %xmm0     # 0x19983
movups %xmm0, 0x4f(%rsp)
movups 0x64b8(%rip), %xmm0     # 0x19974
movaps %xmm0, 0x40(%rsp)
movq 0x18(%rbx), %rbx
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x6497(%rip), %rsi      # 0x1996c
leaq 0x6497(%rip), %rdx      # 0x19973
movq %rsp, %rdi
callq 0xaf16
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x10788
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x1350a
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32f0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1353b
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
jne 0x13563
jmp 0x135c3
jmp 0x13557
jmp 0x1356a
jmp 0x1356a
jmp 0x1353b
jmp 0x13557
jmp 0x1356a
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x1355a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
jmp 0x1355a
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x135c3
movq 0x10(%rsp), %rsi
jmp 0x135bb
movq %rax, %rbx
jmp 0x135c3
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x135c3
movq 0x98(%rsp), %rsi
jmp 0x135bb
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x135c3
movq 0xb8(%rsp), %rsi
jmp 0x135bb
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x135c3
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32f0
movq %rbx, %rdi
callq 0x3570
nop