// File: /workspace/github_c_makefile_star2_O1/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 0x13e78
xorl %edi, %edi
callq 0x32a0
movq 0x18(%rbx), %rdi
callq 0x102d4
movq 0xdc0f(%rip), %r15      # 0x20fd0
leaq 0x645c(%rip), %rsi      # 0x19824
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 0x135e1
movups 0x640c(%rip), %xmm0     # 0x19839
movaps %xmm0, 0x40(%rsp)
movl $0x747874, 0x4f(%rsp)   # imm = 0x747874
movq 0x18(%rbx), %r15
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x3e75(%rip), %rsi      # 0x172c4
leaq 0x3e73(%rip), %rdx      # 0x172c9
movq %rsp, %rdi
callq 0xb190
leaq 0x30(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3e8b(%rip), %rsi      # 0x172f9
leaq 0x3e8d(%rip), %rdx      # 0x17302
leaq 0x20(%rsp), %rdi
callq 0xb190
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
callq 0x10d3a
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x134ab
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x134c1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32f0
movups 0x6384(%rip), %xmm0     # 0x1984c
movaps %xmm0, 0x40(%rsp)
movups 0x6385(%rip), %xmm0     # 0x19859
movups %xmm0, 0x4d(%rsp)
movq 0x18(%rbx), %r15
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x3e0f(%rip), %rsi      # 0x172f9
leaq 0x3e11(%rip), %rdx      # 0x17302
callq 0xb190
leaq 0x20(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x3df4(%rip), %rsi      # 0x172f9
leaq 0x3df6(%rip), %rdx      # 0x17302
callq 0xb190
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
callq 0x10d3a
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x1353d
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x13553
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32f0
movups 0x630f(%rip), %xmm0     # 0x19869
movaps %xmm0, 0x40(%rsp)
movl $0x747874, 0x4f(%rsp)   # imm = 0x747874
movq 0x18(%rbx), %r15
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x3d81(%rip), %rsi      # 0x172f9
leaq 0x3d83(%rip), %rdx      # 0x17302
callq 0xb190
leaq 0x20(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x4e57(%rip), %rsi      # 0x183ea
leaq 0x4e56(%rip), %rdx      # 0x183f0
callq 0xb190
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r15, %rdi
callq 0x10d3a
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x135cb
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x135e1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x32f0
movq 0x18(%rbx), %rdi
leaq 0x3d0d(%rip), %rsi      # 0x172f9
callq 0x10978
movq 0x18(%rbx), %rax
movl $0x0, 0x2c0(%rax)
leaq 0xe8(%rsp), %rdi
callq 0x13e8c
movq 0x18(%rbx), %r15
leaq 0xd8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x6259(%rip), %rsi      # 0x1987c
leaq 0x625e(%rip), %rdx      # 0x19888
leaq 0xc8(%rsp), %r12
movq %r12, %rdi
callq 0xb190
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
movq %r12, %rcx
callq 0xe1a6
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13667
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32f0
leaq 0xb8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x620e(%rip), %rsi      # 0x19889
leaq 0x6218(%rip), %rdx      # 0x1989a
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0xb190
leaq 0xe8(%rsp), %rdi
movq %r15, %rsi
callq 0x13fe8
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x136bf
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32f0
leaq 0xe8(%rsp), %rdi
callq 0x13e8c
movq 0x18(%rbx), %rax
movl $0x1, 0x2c0(%rax)
movq 0xd8ef(%rip), %r15      # 0x20fd0
leaq 0x61b3(%rip), %rsi      # 0x1989b
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 0x6162(%rip), %r12      # 0x198a0
testq %r14, %r14
jne 0x13787
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 0x106b4
movq 0x18(%rbx), %rdi
movl $0x1, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0xeeba
movq 0x18(%rbx), %rdi
movl %ebp, %esi
callq 0x10308
incl %ebp
cmpl $0x1f4, %ebp            # imm = 0x1F4
jne 0x1373e
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x60e8(%rip), %rsi      # 0x198b4
leaq 0x6100(%rip), %rdx      # 0x198d3
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0xb190
leaq 0xe8(%rsp), %rdi
movq %r15, %rsi
callq 0x13fe8
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x13810
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32f0
testq %r14, %r14
jne 0x13876
movups 0x60c7(%rip), %xmm0     # 0x198e3
movups %xmm0, 0x4f(%rsp)
movups 0x60ac(%rip), %xmm0     # 0x198d4
movaps %xmm0, 0x40(%rsp)
movq 0x18(%rbx), %rbx
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x608b(%rip), %rsi      # 0x198cc
leaq 0x608b(%rip), %rdx      # 0x198d3
movq %rsp, %rdi
callq 0xb190
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x10a56
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x13876
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 0x138a7
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
jne 0x138cf
jmp 0x1392f
jmp 0x138c3
jmp 0x138d6
jmp 0x138d6
jmp 0x138a7
jmp 0x138c3
jmp 0x138d6
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x138c6
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32f0
jmp 0x138c6
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x1392f
movq 0x10(%rsp), %rsi
jmp 0x13927
movq %rax, %rbx
jmp 0x1392f
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x1392f
movq 0x98(%rsp), %rsi
jmp 0x13927
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1392f
movq 0xb8(%rsp), %rsi
jmp 0x13927
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1392f
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32f0
movq %rbx, %rdi
callq 0x3570
nop