// File: /workspace/github_c_makefile_star2_O3/stonezwr[P]SpiKL-IP/channel.C
// Function: Channel::BSA()
void Channel::BSA(){
    int length_kernel = 24;
    int length_signal = (_analog.size()*_step_analog)/_step_spikeT + 24;
    double threshold = 0.6;
    double error1, error2, temp;
    double * kernel = new double[length_kernel];
    double * signal = new double[length_signal];
    //double sig, noi;

    for(int i = 0; i < length_kernel; i++) kernel[i] = exp(-(i-double(length_kernel)/2)*(i-double(length_kernel)/2)/25);
    temp = 0;
    for(int i = 0; i < length_kernel; i++) temp += kernel[i];
    for(int i = 0; i < length_kernel; i++) kernel[i] /= temp;

    int index = 0;
    for(int i = 0; i < _analog.size(); i++)
        for(; index < (i+1)*_step_analog/_step_spikeT; index++)
            signal[index] = _analog[i]*2e3;
    for(; index < length_signal; index++) signal[index] = 0;

    int j;
    for(int i = 0; i < length_signal-24; i++){
        error1 = 0;
        error2 = 0;
        for(j = 0; j < length_kernel; j++){
            temp = signal[i+j] - kernel[j];
            error1 += (temp<0) ? -temp : temp;
            temp = signal[i+j];
            error2 += (temp<0) ? -temp : temp;
        }
        if(error1 < (error2-threshold)){
            _spikeT.push_back(i+1);
            for(j = 0; j < length_kernel; j++) signal[i+j] -= kernel[j];
        }
    }

    delete [] kernel;
    delete [] signal;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rcx
subq (%rdi), %rcx
sarq $0x3, %rcx
movslq 0x38(%rdi), %rax
imulq %rcx, %rax
movslq 0x3c(%rdi), %rcx
xorl %ebp, %ebp
xorl %edx, %edx
divq %rcx
movq %rax, %r14
leal 0x18(%rax), %r12d
movl $0xc0, %edi
callq 0x3030
movq %rax, %r15
movl %r12d, (%rsp)
movslq %r12d, %rcx
leaq (,%rcx,8), %rax
movq %rcx, 0x10(%rsp)
testl %ecx, %ecx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r12
leal -0xc(%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm0, %xmm0
divsd 0x130fe(%rip), %xmm0    # 0x17008
callq 0x35a0
movsd %xmm0, (%r15,%rbp,8)
incq %rbp
cmpq $0x18, %rbp
jne 0x3ef4
xorpd %xmm0, %xmm0
xorl %eax, %eax
addsd (%r15,%rax,8), %xmm0
incq %rax
cmpq $0x18, %rax
jne 0x3f24
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
xorl %eax, %eax
movupd (%r15,%rax,8), %xmm1
divpd %xmm0, %xmm1
movupd %xmm1, (%r15,%rax,8)
addq $0x2, %rax
cmpq $0x18, %rax
jne 0x3f39
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
subq %rcx, %rsi
je 0x405c
sarq $0x3, %rsi
movl 0x38(%rbx), %edi
cmpq $0x1, %rsi
adcq $0x0, %rsi
movl 0x3c(%rbx), %r8d
leaq 0x8(%r12), %r9
xorl %r10d, %r10d
movsd 0x1308a(%rip), %xmm0    # 0x17010
movdqa 0x13092(%rip), %xmm1    # 0x17020
movdqa 0x1309a(%rip), %xmm2    # 0x17030
pcmpeqd %xmm3, %xmm3
xorl %r11d, %r11d
movq %r10, %rbp
incq %r10
movl %edi, %eax
imull %r10d, %eax
cltd
idivl %r8d
cmpl %eax, %r11d
jge 0x4051
movslq %r11d, %r11
movsd (%rcx,%rbp,8), %xmm4
mulsd %xmm0, %xmm4
movslq %eax, %rbp
subq %r11, %rbp
leaq 0x1(%rbp), %rdx
andq $-0x2, %rdx
decq %rbp
movq %rbp, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
leaq (%r9,%r11,8), %r11
pxor %xmm2, %xmm5
xorl %ebp, %ebp
movq %rbp, %xmm6
pshufd $0x44, %xmm6, %xmm6     # xmm6 = xmm6[0,1,0,1]
por %xmm1, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm5, %xmm7
pcmpeqd %xmm5, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %r13d
notl %r13d
testb $0x1, %r13b
je 0x402f
movsd %xmm4, -0x8(%r11,%rbp,8)
pxor %xmm3, %xmm6
pextrw $0x4, %xmm6, %r13d
testb $0x1, %r13b
je 0x4045
movsd %xmm4, (%r11,%rbp,8)
addq $0x2, %rbp
cmpq %rbp, %rdx
jne 0x3fe7
movl %eax, %r11d
cmpq %rsi, %r10
jne 0x3f9d
jmp 0x405f
xorl %r11d, %r11d
cmpl (%rsp), %r11d
jge 0x4110
movslq %r11d, %rcx
movq 0x10(%rsp), %rdx
subq %rcx, %rdx
leaq 0x1(%rdx), %rax
andq $-0x2, %rax
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq (%r12,%rcx,8), %rcx
addq $0x8, %rcx
xorl %edx, %edx
movdqa 0x12f85(%rip), %xmm1    # 0x17020
movdqa 0x12f8d(%rip), %xmm2    # 0x17030
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movq %rdx, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm1, %xmm4
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %esi
notl %esi
testb $0x1, %sil
je 0x40f0
movq $0x0, -0x8(%rcx,%rdx,8)
pxor %xmm3, %xmm4
pextrw $0x4, %xmm4, %esi
testb $0x1, %sil
je 0x4107
movq $0x0, (%rcx,%rdx,8)
addq $0x2, %rdx
cmpq %rdx, %rax
jne 0x40ab
testl %r14d, %r14d
jle 0x41ec
leaq 0x18(%rbx), %rax
movq %rax, (%rsp)
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movapd 0x12f0e(%rip), %xmm3    # 0x17040
movsd 0x12ede(%rip), %xmm4    # 0x17018
leaq (%r12,%rbp,8), %r13
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm1
movapd %xmm1, %xmm2
subsd (%r15,%rax,8), %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movapd %xmm2, %xmm1
xorpd %xmm3, %xmm1
maxpd %xmm2, %xmm1
addpd %xmm1, %xmm0
incq %rax
cmpq $0x18, %rax
jne 0x4144
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm4, %xmm1
incq %rbp
ucomisd %xmm0, %xmm1
jbe 0x41e3
movl %ebp, 0xc(%rsp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x41a1
movl %ebp, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x41bf
movq (%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x463c
movsd 0x12e61(%rip), %xmm4    # 0x17018
movapd 0x12e81(%rip), %xmm3    # 0x17040
xorl %eax, %eax
movupd (%r15,%rax,8), %xmm0
movupd (%r13,%rax,8), %xmm1
subpd %xmm0, %xmm1
movupd %xmm1, (%r13,%rax,8)
addq $0x2, %rax
cmpq $0x18, %rax
jne 0x41c1
cmpq %r14, %rbp
jl 0x413a
movq %r15, %rdi
callq 0x33d0
movq %r12, %rdi
callq 0x33d0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop