// File: /workspace/github_c_makefile_star2_O0/stonezwr[P]SpiKL-IP/network.C
// Function: Network::LSMAddSynapse(Neuron*, NeuronGroup*, int, int, int, bool)
void Network::LSMAddSynapse(Neuron * pre, NeuronGroup * post, int npost, int value, int random, bool fixed){
    Neuron * neuron;
    double factor;
    double weight_limit;
    bool liquid = false;
    int D_weight_limit;
    if(fixed == true){
        /***** this is for the case of input synapses: *****/
        weight_limit = value;
        D_weight_limit = value;
    }else{
        weight_limit = value;
        D_weight_limit = value;
    }

    if(npost < 0){
        assert(npost == -1);
        for(neuron = post->First(); neuron != NULL; neuron = post->Next()){
            if(random == 2){
                /*** This is for the case of continuous readout weights: ***/
                /*** Remember to change the netlist to                   ***/
                /*** lsmsynapse reservoir output -1 -1 8 2, 2 is random  ***/
                /*** The initial weights are in W_max*(-1 to 1)          ***/
                factor = rand()%100000;
                factor = factor*2/99999-1;
            }else if(random == 0) factor = 0;
            else assert(0);
            double weight = value*factor/weight_limit;
            // set the sign of the readout weight the same as pre-neuron E/I might be hampful for the performance
            // if((!pre->IsExcitatory() && weight > 0) ||(pre->IsExcitatory() && weight < 0))  weight = -1*weight; 
            //if(weight > 0)  weight = weight*0.5;
            LSMAddSynapse(pre,neuron,weight,fixed,weight_limit,liquid);
        }
    }else{
        /*** This is for adding input synapses!! ***/
        assert(random == 1);
        for(int i = 0; i < npost; i++){
            neuron = post->Order(rand()%post->Size());
            factor = rand()%2;
            factor = factor*2-1;
            LSMAddSynapse(pre,neuron,value*factor,fixed,weight_limit,liquid);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb 0x10(%rbp), %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
andb $0x1, %al
movb %al, -0x25(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movb $0x0, -0x41(%rbp)
movb -0x25(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x1e3e2
cvtsi2sdl -0x20(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x1e3f2
cvtsi2sdl -0x20(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x1e512
cmpl $-0x1, -0x1c(%rbp)
jne 0x1e404
jmp 0x1e423
leaq 0x170be(%rip), %rdi     # 0x354c9
leaq 0x16f08(%rip), %rsi     # 0x3531a
movl $0xa9, %edx
leaq 0x17047(%rip), %rcx     # 0x35465
callq 0x4210
movq -0x18(%rbp), %rdi
callq 0xf110
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1e50d
cmpl $0x2, -0x24(%rbp)
jne 0x1e483
callq 0x4100
movl $0x186a0, %ecx          # imm = 0x186A0
cltd
idivl %ecx
cvtsi2sd %edx, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x15bc1(%rip), %xmm0    # 0x34020
mulsd -0x38(%rbp), %xmm0
movsd 0x16e7c(%rip), %xmm1    # 0x352e8
divsd %xmm1, %xmm0
movsd 0x16148(%rip), %xmm1    # 0x345c0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1e4b4
cmpl $0x0, -0x24(%rbp)
jne 0x1e493
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1e4b2
leaq 0x16e7e(%rip), %rdi     # 0x35318
leaq 0x16e79(%rip), %rsi     # 0x3531a
movl $0xb3, %edx
leaq 0x16fb8(%rip), %rcx     # 0x35465
callq 0x4210
jmp 0x1e4b4
movq -0x60(%rbp), %rdi
cvtsi2sdl -0x20(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movsd -0x50(%rbp), %xmm0
movb -0x25(%rbp), %cl
movsd -0x40(%rbp), %xmm1
movb -0x41(%rbp), %al
xorl %r8d, %r8d
movl %r8d, %r9d
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %ecx
movzbl %al, %r8d
callq 0x12da0
movq -0x18(%rbp), %rdi
callq 0xf1d0
movq %rax, -0x30(%rbp)
jmp 0x1e430
jmp 0x1e5f4
cmpl $0x1, -0x24(%rbp)
jne 0x1e51a
jmp 0x1e539
leaq 0x16f8e(%rip), %rdi     # 0x354af
leaq 0x16df2(%rip), %rsi     # 0x3531a
movl $0xbc, %edx
leaq 0x16f31(%rip), %rcx     # 0x35465
callq 0x4210
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1e5f2
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0x4100
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rdi
callq 0x24070
movq -0x70(%rbp), %rdi
movl %eax, %ecx
movl -0x64(%rbp), %eax
cltd
idivl %ecx
movl %edx, %esi
callq 0xf490
movq %rax, -0x30(%rbp)
callq 0x4100
movq -0x60(%rbp), %rdi
movl $0x2, %ecx
cltd
idivl %ecx
cvtsi2sd %edx, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
addsd %xmm0, %xmm0
movsd 0x15ff1(%rip), %xmm1    # 0x34598
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
cvtsi2sdl -0x20(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movb -0x25(%rbp), %cl
movsd -0x40(%rbp), %xmm1
movb -0x41(%rbp), %al
xorl %r8d, %r8d
movl %r8d, %r9d
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %ecx
movzbl %al, %r8d
callq 0x12da0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1e540
jmp 0x1e5f4
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)