// File: /workspace/github_c_makefile_star2_O2/stonezwr[P]SpiKL-IP/network.C
// Function: Network::LoadSynWeightsFromFile(char const*, char*)
void Network::LoadSynWeightsFromFile(const char * syn_type, char * filename){
    ifstream f_in(filename);
    if(!f_in.is_open()){
        cout<<"In Network::LoadSynWeightsFromFile(), cannot open the file: "<<filename<<endl;
        assert(0);
    }

    synapsetype_t read_syn_type = INVALID;
    DetermineSynType(syn_type, read_syn_type, "LoadSynWeightsFromFile()");
    assert(read_syn_type != INVALID);
    vector<Synapse*> tmp;

    const vector<Synapse*> & synapses = 
        read_syn_type == RESERVOIR_SYN ? _rsynapses : 
        read_syn_type == READOUT_SYN ? _rosynapses :
        read_syn_type == INPUT_SYN ? _isynapses : tmp;

    assert(!synapses.empty());  
    // load the synaptic weights from file:
    // the synaptic weight is stored in the file in the same order as the corresponding synapses store in the vector
    int index;
    string pre;
    string post;
    
    double weight;
    while(f_in>>index>>pre>>post>>weight){//>>pre_ext>>post_ext){
        if(index < 0 || index >= synapses.size()){
            cout<<"In Network::LoadSynWeightsFromFile(), the index of the synapse you read : "<<index<<" is out of bound of the container stores the synapses!!"<<endl;
            exit(EXIT_FAILURE);
        }

        assert(strcmp(pre.c_str(), synapses[index]->PreNeuron()->Name()) == 0);
        assert(strcmp(post.c_str(), synapses[index]->PostNeuron()->Name()) == 0);
        synapses[index]->Weight(weight);
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x70(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x35a0
leaq 0xe8(%rsp), %rdi
callq 0x30a0
testb %al, %al
je 0xe692
leaq 0x4(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x7f09(%rip), %rcx      # 0x1637c
movq %r15, %rsi
callq 0xdbce
movl 0x4(%rsp), %eax
cmpl $0x3, %eax
je 0xe6d7
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
cmpl $0x2, %eax
je 0xe4a8
testl %eax, %eax
jne 0xe4b1
addq $0x118, %rbx            # imm = 0x118
jmp 0xe4c4
addq $0x130, %rbx            # imm = 0x130
jmp 0xe4c4
addq $0x148, %rbx            # imm = 0x148
cmpl $0x1, %eax
leaq 0x10(%rsp), %rax
cmovneq %rax, %rbx
movq (%rbx), %rax
cmpq 0x8(%rbx), %rax
je 0xe6f6
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x40(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
movq %rsp, %r15
leaq 0x50(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x8(%rsp), %rbp
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x31a0
movq %rax, %rdi
movq %r12, %rsi
callq 0x3380
movq %rax, %rdi
movq %r13, %rsi
callq 0x3380
movq %rax, %rdi
movq %rbp, %rsi
callq 0x31c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xe5dd
movslq (%rsp), %rax
testq %rax, %rax
js 0xe617
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0xe617
movq 0x50(%rsp), %r14
movq (%rcx,%rax,8), %rdi
callq 0xa8a0
movq %rax, %rdi
callq 0x5d1a
movq %r14, %rdi
movq %rax, %rsi
callq 0x33d0
testl %eax, %eax
jne 0xe673
movq 0x30(%rsp), %r14
movslq (%rsp), %rax
movq (%rbx), %rcx
movq (%rcx,%rax,8), %rdi
callq 0xa8a4
movq %rax, %rdi
callq 0x5d1a
movq %r14, %rdi
movq %rax, %rsi
callq 0x33d0
testl %eax, %eax
jne 0xe654
movslq (%rsp), %rax
movq (%rbx), %rcx
movq (%rcx,%rax,8), %rax
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rax)
jmp 0xe505
leaq 0x30(%rsp), %rdi
callq 0x3150
leaq 0x50(%rsp), %rdi
callq 0x3150
leaq 0x10(%rsp), %rdi
callq 0x9226
leaq 0x70(%rsp), %rdi
callq 0x30d0
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x119aa(%rip), %rdi     # 0x1ffc8
leaq 0x7d89(%rip), %rsi      # 0x163ae
callq 0x32a0
movl (%rsp), %esi
movq %rax, %rdi
callq 0x3530
leaq 0x7dbd(%rip), %rsi      # 0x163f9
movq %rax, %rdi
callq 0x32a0
movq %rax, %rdi
callq 0x3160
pushq $0x1
popq %rdi
callq 0x3330
leaq 0x7e15(%rip), %rdi      # 0x16470
leaq 0x6d50(%rip), %rsi      # 0x153b2
leaq 0x7cd8(%rip), %rcx      # 0x16341
movl $0x43a, %edx            # imm = 0x43A
callq 0x31b0
leaq 0x7db7(%rip), %rdi      # 0x16431
leaq 0x6d31(%rip), %rsi      # 0x153b2
leaq 0x7cb9(%rip), %rcx      # 0x16341
movl $0x439, %edx            # imm = 0x439
callq 0x31b0
movq 0x1192f(%rip), %rdi     # 0x1ffc8
leaq 0x7bc6(%rip), %rsi      # 0x16266
callq 0x32a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %rax, %rdi
callq 0x3160
leaq 0x6cf1(%rip), %rdi      # 0x153b0
leaq 0x6cec(%rip), %rsi      # 0x153b2
leaq 0x7c74(%rip), %rcx      # 0x16341
movl $0x41e, %edx            # imm = 0x41E
callq 0x31b0
leaq 0x7cb7(%rip), %rdi      # 0x16395
leaq 0x6ccd(%rip), %rsi      # 0x153b2
leaq 0x7c55(%rip), %rcx      # 0x16341
movl $0x423, %edx            # imm = 0x423
callq 0x31b0
leaq 0x79a1(%rip), %rdi      # 0x1609e
leaq 0x6cae(%rip), %rsi      # 0x153b2
leaq 0x7c36(%rip), %rcx      # 0x16341
movl $0x42b, %edx            # imm = 0x42B
callq 0x31b0
jmp 0xe717
movq %rax, %rbx
jmp 0xe73f
jmp 0xe71e
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3150
leaq 0x50(%rsp), %rdi
callq 0x3150
leaq 0x10(%rsp), %rdi
callq 0x9226
leaq 0x70(%rsp), %rdi
callq 0x30d0
movq %rbx, %rdi
callq 0x3540
nop