// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x68(%rbp)
movl $0x18, -0xc(%rbp)
callq 0x57f0
movq -0x68(%rbp), %rcx
movslq 0x38(%rcx), %rdx
imulq %rdx, %rax
movslq 0x3c(%rcx), %rcx
xorl %edx, %edx
divq %rcx
addq $0x18, %rax
movl %eax, -0x10(%rbp)
movsd 0x2f141(%rip), %xmm0    # 0x34008
movsd %xmm0, -0x18(%rbp)
movslq -0xc(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, -0x38(%rbp)
movslq -0x10(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4030
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4fa5
cvtsi2sdl -0x44(%rbp), %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
movsd 0x2f0e1(%rip), %xmm2    # 0x34020
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
cvtsi2sdl -0x44(%rbp), %xmm1
cvtsi2sdl -0xc(%rbp), %xmm2
movsd 0x2f0b0(%rip), %xmm3    # 0x34020
divsd %xmm3, %xmm2
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x2f094(%rip), %xmm1    # 0x34018
divsd %xmm1, %xmm0
callq 0x4710
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x4f25
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4fde
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x4fb4
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x5013
movsd -0x30(%rbp), %xmm1
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4fe5
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x68(%rbp), %rdi
movslq -0x54(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0x57f0
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jae 0x509f
jmp 0x5040
movq -0x68(%rbp), %rcx
movl -0x50(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
imull 0x38(%rcx), %eax
cltd
idivl 0x3c(%rcx)
movl %eax, %ecx
movl -0x74(%rbp), %eax
cmpl %ecx, %eax
jge 0x5092
movq -0x68(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x5810
movsd 0x2ef9a(%rip), %xmm0    # 0x34010
mulsd (%rax), %xmm0
movq -0x40(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x5040
jmp 0x5094
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x5021
jmp 0x50a1
movl -0x50(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x50c4
movq -0x40(%rbp), %rax
movslq -0x50(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x50a1
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl -0x10(%rbp), %ecx
subl $0x18, %ecx
cmpl %ecx, %eax
jge 0x5260
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x51dd
movq -0x40(%rbp), %rax
movl -0x5c(%rbp), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x5150
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x515a
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x40(%rbp), %rax
movl -0x5c(%rbp), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x51b0
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x51bd
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x50f3
movsd -0x20(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5250
movq -0x68(%rbp), %rdi
addq $0x18, %rdi
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x5830
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x524e
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x40(%rbp), %rax
movl -0x5c(%rbp), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5213
jmp 0x5250
jmp 0x5252
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x50cb
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x527d
movq -0x90(%rbp), %rdi
callq 0x44d0
movq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
je 0x529a
movq -0x98(%rbp), %rdi
callq 0x44d0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)