// File: /workspace/github_c_makefile_star2_O2/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 $0x138, %rsp            # imm = 0x138
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x11150
xorl %edi, %edi
callq 0x3290
movq 0x18(%rbx), %rdi
callq 0xd862
movq 0xf66b(%rip), %rdi      # 0x1ffc8
leaq 0x5f40(%rip), %rsi      # 0x168a4
callq 0x32a0
movq 0x18(%rbx), %rcx
movq 0x210(%rcx), %rsi
subq 0x208(%rcx), %rsi
shrq $0x3, %rsi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3160
testq %r14, %r14
jne 0x10ae9
movups 0x5f1a(%rip), %xmm0     # 0x168b9
movaps %xmm0, 0x50(%rsp)
movl $0x747874, 0x5f(%rsp)   # imm = 0x747874
movq 0x18(%rbx), %r15
leaq 0x390d(%rip), %rsi      # 0x142c4
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x8d8c
leaq 0x392c(%rip), %rsi      # 0x142f9
leaq 0x30(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x8d8c
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %r15, %rdi
callq 0xe0e4
leaq 0x30(%rsp), %rdi
callq 0x3150
leaq 0x10(%rsp), %rdi
callq 0x3150
movups 0x5ebe(%rip), %xmm0     # 0x168cc
movaps %xmm0, 0x50(%rsp)
movups 0x5ebf(%rip), %xmm0     # 0x168d9
movups %xmm0, 0x5d(%rsp)
movq 0x18(%rbx), %r15
leaq 0x38cf(%rip), %rsi      # 0x142f9
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x8d8c
leaq 0x38b9(%rip), %rsi      # 0x142f9
leaq 0x30(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x8d8c
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %r15, %rdi
callq 0xe0e4
leaq 0x30(%rsp), %rdi
callq 0x3150
leaq 0x10(%rsp), %rdi
callq 0x3150
movups 0x5e68(%rip), %xmm0     # 0x168e9
movaps %xmm0, 0x50(%rsp)
movl $0x747874, 0x5f(%rsp)   # imm = 0x747874
movq 0x18(%rbx), %r15
leaq 0x3860(%rip), %rsi      # 0x142f9
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x8d8c
leaq 0x49bb(%rip), %rsi      # 0x1546a
leaq 0x30(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x8d8c
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %r15, %rdi
callq 0xe0e4
leaq 0x30(%rsp), %rdi
callq 0x3150
leaq 0x10(%rsp), %rdi
callq 0x3150
movq 0x18(%rbx), %rdi
leaq 0x3805(%rip), %rsi      # 0x142f9
callq 0xde00
movq 0x18(%rbx), %rax
andl $0x0, 0x2c0(%rax)
leaq 0xf8(%rsp), %rdi
callq 0x11164
movq 0x18(%rbx), %r15
leaq 0x5de0(%rip), %rsi      # 0x168fc
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x8d8c
leaq 0xd8(%rsp), %rcx
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0xbe5a
leaq 0xd8(%rsp), %rdi
callq 0x3150
leaq 0x5db2(%rip), %rsi      # 0x16909
leaq 0xb8(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x8d8c
leaq 0xf8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x11252
leaq 0xb8(%rsp), %rdi
callq 0x3150
leaq 0xf8(%rsp), %rdi
callq 0x11164
movq 0x18(%rbx), %rax
movl $0x1, 0x2c0(%rax)
movq 0xf41b(%rip), %r15      # 0x1ffc8
leaq 0x5d67(%rip), %rsi      # 0x1691b
movq %r15, %rdi
callq 0x32a0
movq %rax, %rdi
movl %r14d, %esi
callq 0x3530
movq %rax, %rdi
callq 0x3160
movq 0x18(%rbx), %rax
movl %r14d, 0x22c(%rax)
xorl %ebp, %ebp
leaq 0x5d3d(%rip), %r12      # 0x16920
pushq $0x1
popq %r13
cmpl $0x1f4, %ebp            # imm = 0x1F4
je 0x10c3a
testq %r14, %r14
jne 0x10c11
movq %r15, %rdi
movq %r12, %rsi
callq 0x32a0
movq %rax, %rdi
movl %ebp, %esi
callq 0x3530
movq %rax, %rdi
callq 0x3160
movq 0x18(%rbx), %rdi
callq 0xdbb8
movq 0x18(%rbx), %rdi
movl %r13d, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0xc792
movq 0x18(%rbx), %rdi
movl %ebp, %esi
callq 0xd88e
incl %ebp
jmp 0x10be7
leaq 0x5cf3(%rip), %rsi      # 0x16934
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x8d8c
leaq 0xf8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x11252
leaq 0x98(%rsp), %rdi
callq 0x3150
testq %r14, %r14
jne 0x10cc8
movups 0x5ce2(%rip), %xmm0     # 0x16963
movups %xmm0, 0x5f(%rsp)
movups 0x5cc7(%rip), %xmm0     # 0x16954
movaps %xmm0, 0x50(%rsp)
movq 0x18(%rbx), %rbx
leaq 0x5caf(%rip), %rsi      # 0x1694c
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x8d8c
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0xdee8
leaq 0x10(%rsp), %rdi
callq 0x3150
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10cf9
jmp 0x10d35
jmp 0x10cea
jmp 0x10cf9
jmp 0x10d35
jmp 0x10cea
jmp 0x10cf9
jmp 0x10d35
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3150
jmp 0x10cfc
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x10d2e
jmp 0x10d35
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x10d2e
jmp 0x10d35
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x10d2e
jmp 0x10d35
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x3150
jmp 0x10d38
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3540