// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_smooth_trg(double*, int, int, int, int, int, char*)
int array_smooth_trg(double * array,
		     int k_size,
		     int starting_k,
		     int eta_size,
		     int index_eta,
		     int radius, /*3, 5 or 7 */
		     ErrorMsg errmsg) {

  double * smooth;
  int i,j,jmin,jmax;
  double weigth;
  double *coeff;

  smooth=(double*)malloc(k_size*sizeof(double));
  if (smooth == NULL) {
    class_sprintf(errmsg,"%s(L:%d) Cannot allocate smooth",__func__,__LINE__);
    return _FAILURE_;
  }

  class_calloc(coeff,2*radius+1,sizeof(double),errmsg);

  switch(radius){
  case 3:
    weigth = 21;

    coeff[0] = -2;
    coeff[1] = 3;
    coeff[2] = 6;
    coeff[3] = 7;
    coeff[4] = 6;
    coeff[5] = 3;
    coeff[6] = -2;

    break;
  case 4:
    weigth = 231;

    coeff[0] = -21;
    coeff[1] = 14;
    coeff[2] = 39;
    coeff[3] = 54;
    coeff[4] = 59;
    coeff[5] = 54;
    coeff[6] = 39;
    coeff[7] = 14;
    coeff[8] = -21;

    break;
  case 5:
    weigth = 429;

    coeff[0] = -36;
    coeff[1] = 9;
    coeff[2] = 44;
    coeff[3] = 69;
    coeff[4] = 84;
    coeff[5] = 89;
    coeff[6] = 84;
    coeff[7] = 69;
    coeff[8] = 44;
    coeff[9] = 9;
    coeff[10] = -36;

    break;
  case 6:
    weigth = 143;

    coeff[0] = -11;
    coeff[1] = 0;
    coeff[2] = 9;
    coeff[3] = 16;
    coeff[4] = 21;
    coeff[5] = 24;
    coeff[6] = 25;
    coeff[7] = 24;
    coeff[8] = 21;
    coeff[9] = 16;
    coeff[10] = 9;
    coeff[11] = 0;
    coeff[12] = -11;

    break;
  case 7:
    weigth = 1105;

    coeff[0] = -78;
    coeff[1] = -13;
    coeff[2] = 42;
    coeff[3] = 87;
    coeff[4] = 122;
    coeff[5] = 147;
    coeff[6] = 162;
    coeff[7] = 167;
    coeff[8] = 162;
    coeff[9] = 147;
    coeff[10] = 122;
    coeff[11] = 87;
    coeff[12] = 42;
    coeff[13] = -13;
    coeff[14] = -78;

    break;

/*   case 8: */


  default:
    class_stop(errmsg,"Non valid radius %d: please chose between 3 4 5 or 6\n",radius);
    weigth=0;
    break;
  }

  for (i=starting_k; i<k_size-radius; i++) {
      smooth[i]=0.;
      jmin = MAX(i-radius,0);
      jmax = MIN(i+radius,k_size-1);
      for (j=jmin; j <= jmax; j++) {
	smooth[i] += coeff[j-jmin]*array[j+k_size*index_eta];
      }
      smooth[i] /= weigth;
  }

  for (i=starting_k; i<k_size-radius; i++)
    array[i+k_size*index_eta] = smooth[i];

  free(smooth);
  free(coeff);

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1028, %rsp           # imm = 0x1028
movl %r9d, %ebx
movl %r8d, %ebp
movl %edx, %r13d
movl %esi, %r15d
movq %rdi, 0x18(%rsp)
movq 0x1060(%rsp), %r12
movslq %esi, %rdi
shlq $0x3, %rdi
callq 0x8460
testq %rax, %rax
je 0x1adef
movq %rax, %r14
movl %ebp, 0xc(%rsp)
leal 0x1(,%rbx,2), %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x8250
testq %rax, %rax
je 0x1ae34
movq %rax, %rbp
leal -0x3(%rbx), %eax
cmpl $0x4, %eax
ja 0x1b1a5
leaq 0xd7a9b(%rip), %rcx     # 0xf2820
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movabsq $-0x4000000000000000, %rax # imm = 0xC000000000000000
movq %rax, (%rbp)
movsd 0xd7944(%rip), %xmm0    # 0xf26e8
movsd 0xd79ac(%rip), %xmm1    # 0xf2758
movl $0x30, %eax
movl $0x28, %ecx
movl $0x20, %edx
movsd 0xd799d(%rip), %xmm5    # 0xf2760
movl $0x18, %esi
movsd 0xd78a0(%rip), %xmm4    # 0xf2670
movl $0x10, %edi
movsd 0xd78a3(%rip), %xmm6    # 0xf2680
movl $0x8, %r8d
movaps %xmm4, %xmm3
movapd %xmm6, %xmm2
jmp 0x1b078
leaq 0xd875e(%rip), %rbx     # 0xf3554
leaq 0xd8777(%rip), %r14     # 0xf3574
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0xc47, %r8d            # imm = 0xC47
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %r12, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0xc47, %r8d            # imm = 0xC47
xorl %eax, %eax
callq 0x8550
jmp 0x1b1f9
leaq 0xd61c9(%rip), %rsi     # 0xf1004
leaq 0xd8743(%rip), %rdx     # 0xf3585
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %ecx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd61d7(%rip), %rsi     # 0xf1034
leaq 0xd8710(%rip), %rdx     # 0xf3574
movq %r12, %rdi
movl $0xc4b, %ecx            # imm = 0xC4B
jmp 0x1b1ef
movaps 0xd7918(%rip), %xmm0    # 0xf2790
movups %xmm0, (%rbp)
movaps 0xd791d(%rip), %xmm0    # 0xf27a0
movups %xmm0, 0x10(%rbp)
movaps 0xd7922(%rip), %xmm0    # 0xf27b0
movups %xmm0, 0x20(%rbp)
movaps 0xd7927(%rip), %xmm0    # 0xf27c0
movups %xmm0, 0x30(%rbp)
movabsq $0x4064400000000000, %rax # imm = 0x4064400000000000
movq %rax, 0x40(%rbp)
movsd 0xd77e5(%rip), %xmm0    # 0xf2698
movsd 0xd77e5(%rip), %xmm1    # 0xf26a0
movl $0x70, %eax
movsd 0xd77e0(%rip), %xmm2    # 0xf26a8
movl $0x68, %ecx
movsd 0xd77db(%rip), %xmm3    # 0xf26b0
movl $0x60, %edx
movsd 0xd77d6(%rip), %xmm5    # 0xf26b8
movl $0x58, %esi
movsd 0xd77d1(%rip), %xmm4    # 0xf26c0
movl $0x50, %edi
movsd 0xd77cc(%rip), %xmm6    # 0xf26c8
movl $0x48, %r8d
jmp 0x1b078
movaps 0xd78e2(%rip), %xmm0    # 0xf27f0
movups %xmm0, (%rbp)
movaps 0xd78e7(%rip), %xmm0    # 0xf2800
movups %xmm0, 0x10(%rbp)
movabsq $0x4055000000000000, %rax # imm = 0x4055000000000000
movq %rax, 0x20(%rbp)
movsd 0xd77c5(%rip), %xmm0    # 0xf26f8
movsd 0xd77c5(%rip), %xmm1    # 0xf2700
movl $0x50, %eax
movsd 0xd7798(%rip), %xmm2    # 0xf26e0
movl $0x48, %ecx
movsd 0xd77b3(%rip), %xmm3    # 0xf2708
movl $0x40, %edx
movsd 0xd77ae(%rip), %xmm5    # 0xf2710
movl $0x38, %esi
movsd 0xd77a9(%rip), %xmm4    # 0xf2718
movl $0x30, %edi
movsd 0xd77a4(%rip), %xmm6    # 0xf2720
movl $0x28, %r8d
jmp 0x1b078
movsd 0xd7741(%rip), %xmm0    # 0xf26d0
movups %xmm0, (%rbp)
movaps 0xd7836(%rip), %xmm0    # 0xf27d0
movups %xmm0, 0x10(%rbp)
movaps 0xd783b(%rip), %xmm0    # 0xf27e0
movups %xmm0, 0x20(%rbp)
movabsq $0x4039000000000000, %rax # imm = 0x4039000000000000
movq %rax, 0x30(%rbp)
movsd 0xd7719(%rip), %xmm0    # 0xf26d8
movsd 0xd7709(%rip), %xmm1    # 0xf26d0
movl $0x60, %eax
xorpd %xmm2, %xmm2
movl $0x58, %ecx
movsd 0xd7703(%rip), %xmm3    # 0xf26e0
movl $0x50, %edx
movsd 0xd680e(%rip), %xmm5    # 0xf17f8
movl $0x48, %esi
movsd 0xd76f1(%rip), %xmm4    # 0xf26e8
movl $0x40, %edi
movsd 0xd76ec(%rip), %xmm6    # 0xf26f0
movl $0x38, %r8d
jmp 0x1b078
movaps 0xd77fd(%rip), %xmm0    # 0xf2810
movups %xmm0, (%rbp)
movabsq $0x4043800000000000, %rax # imm = 0x4043800000000000
movq %rax, 0x10(%rbp)
movsd 0xd76fb(%rip), %xmm0    # 0xf2728
movsd 0xd76fb(%rip), %xmm1    # 0xf2730
movl $0x40, %eax
movsd 0xd76f6(%rip), %xmm2    # 0xf2738
movl $0x38, %ecx
movsd 0xd76f1(%rip), %xmm3    # 0xf2740
movl $0x30, %edx
movl $0x28, %esi
movsd 0xd76e7(%rip), %xmm4    # 0xf2748
movl $0x20, %edi
movsd 0xd76e2(%rip), %xmm6    # 0xf2750
movl $0x18, %r8d
movapd %xmm6, %xmm5
movsd %xmm6, (%rbp,%r8)
movsd %xmm4, (%rbp,%rdi)
movsd %xmm5, (%rbp,%rsi)
movsd %xmm3, (%rbp,%rdx)
movsd %xmm2, (%rbp,%rcx)
movsd %xmm1, (%rbp,%rax)
movl %r15d, %ecx
subl %ebx, %ecx
movslq %r13d, %rax
movq %rax, 0x10(%rsp)
movl %r13d, %eax
cmpl %r13d, %ecx
jle 0x1b15a
leal -0x1(%r15), %edx
movl 0xc(%rsp), %edi
imull %r15d, %edi
movl %eax, %esi
subl %ebx, %esi
movslq %edi, %r8
movslq %ecx, %rdi
movq 0x18(%rsp), %r9
leaq (%r9,%r8,8), %r8
xorl %r9d, %r9d
movq 0x10(%rsp), %r10
testl %esi, %esi
movl $0x0, %r11d
cmovgl %esi, %r11d
movq $0x0, (%r14,%r10,8)
movl %r10d, %r13d
subl %ebx, %r13d
testl %r13d, %r13d
cmovlel %r9d, %r13d
leal (%r10,%rbx), %r12d
cmpl %edx, %r12d
cmovgel %edx, %r12d
cmpl %r12d, %r13d
jg 0x1b140
decq %r11
movsd (%r14,%r10,8), %xmm1
movslq %r12d, %r12
movq %rbp, %r13
movsd (%r13), %xmm2
mulsd 0x8(%r8,%r11,8), %xmm2
addsd %xmm2, %xmm1
incq %r11
addq $0x8, %r13
cmpq %r12, %r11
jl 0x1b11d
movsd %xmm1, (%r14,%r10,8)
movsd (%r14,%r10,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r14,%r10,8)
incq %r10
incl %esi
cmpq %rdi, %r10
jl 0x1b0dd
cmpl %eax, %ecx
jle 0x1b191
movl 0xc(%rsp), %ecx
imull %r15d, %ecx
addl %eax, %ecx
movslq %ecx, %rcx
movq 0x18(%rsp), %rdx
leaq (%rdx,%rcx,8), %rdi
movq 0x10(%rsp), %rcx
leaq (%r14,%rcx,8), %rsi
notl %ebx
addl %r15d, %ebx
subl %eax, %ebx
leaq 0x8(,%rbx,8), %rdx
callq 0x82d0
movq %r14, %rdi
callq 0x8410
movq %rbp, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x1b1fe
leaq 0xd83df(%rip), %rsi     # 0xf358b
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd63c1(%rip), %rsi     # 0xf1585
leaq 0x820(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd5e54(%rip), %rsi     # 0xf1034
leaq 0xd838d(%rip), %rdx     # 0xf3574
movq %r12, %rdi
movl $0xca3, %ecx            # imm = 0xCA3
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq