// File: /workspace/github_c_makefile_star2_O2/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 $0x1018, %rsp           # imm = 0x1018
movl %r9d, %ebx
movl %r8d, %r13d
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %r12
movslq %esi, %rdi
shlq $0x3, %rdi
callq 0x8490
testq %rax, %rax
je 0x18cef
movq %rax, %r14
movl %r13d, 0x4(%rsp)
movq %r12, 0x8(%rsp)
leal 0x1(,%rbx,2), %eax
movslq %eax, %rdi
pushq $0x8
popq %r13
movq %r13, %rsi
callq 0x8270
testq %rax, %rax
je 0x18d39
movq %rax, %r12
leal -0x3(%rbx), %eax
cmpl $0x4, %eax
ja 0x1901c
leaq 0xcdb5b(%rip), %rcx     # 0xe67f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movabsq $-0x4000000000000000, %rax # imm = 0xC000000000000000
movq %rax, (%r12)
movsd 0xcda0c(%rip), %xmm0    # 0xe66c0
movsd 0xcda7c(%rip), %xmm1    # 0xe6738
pushq $0x30
popq %rax
pushq $0x28
popq %rcx
pushq $0x20
popq %rdx
movsd 0xcda73(%rip), %xmm5    # 0xe6740
pushq $0x18
popq %rsi
movsd 0xcd978(%rip), %xmm4    # 0xe6650
pushq $0x10
popq %rdi
movsd 0xcda65(%rip), %xmm6    # 0xe6748
movaps %xmm4, %xmm3
movapd %xmm6, %xmm2
jmp 0x18f53
leaq 0xce82e(%rip), %rbx     # 0xe7524
leaq 0xce847(%rip), %r14     # 0xe7544
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0xc47, %r8d            # imm = 0xC47
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x1050(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0xc47, %r8d            # imm = 0xC47
xorl %eax, %eax
callq 0x8580
jmp 0x19075
leaq 0xcc2c4(%rip), %rsi     # 0xe5004
leaq 0xce80e(%rip), %rdx     # 0xe7555
leaq 0x10(%rsp), %rbx
pushq $0x8
popq %rcx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0xcc2d4(%rip), %rsi     # 0xe5034
leaq 0xce7dd(%rip), %rdx     # 0xe7544
movq 0x1050(%rsp), %rdi
movl $0xc4b, %ecx            # imm = 0xC4B
jmp 0x1906b
movaps 0xcd9e0(%rip), %xmm0    # 0xe6760
movups %xmm0, (%r12)
movaps 0xcd9e4(%rip), %xmm0    # 0xe6770
movups %xmm0, 0x10(%r12)
movaps 0xcd9e7(%rip), %xmm0    # 0xe6780
movups %xmm0, 0x20(%r12)
movaps 0xcd9ea(%rip), %xmm0    # 0xe6790
movups %xmm0, 0x30(%r12)
movabsq $0x4064400000000000, %rax # imm = 0x4064400000000000
movq %rax, 0x40(%r12)
movsd 0xcd8ad(%rip), %xmm0    # 0xe6670
movsd 0xcd8ad(%rip), %xmm1    # 0xe6678
pushq $0x70
popq %rax
movsd 0xcd8aa(%rip), %xmm2    # 0xe6680
pushq $0x68
popq %rcx
movsd 0xcd8a7(%rip), %xmm3    # 0xe6688
pushq $0x60
popq %rdx
movsd 0xcd8a4(%rip), %xmm5    # 0xe6690
pushq $0x58
popq %rsi
movsd 0xcd8a1(%rip), %xmm4    # 0xe6698
pushq $0x50
popq %rdi
movsd 0xcd89e(%rip), %xmm6    # 0xe66a0
pushq $0x48
jmp 0x18eed
movaps 0xcd9b0(%rip), %xmm0    # 0xe67c0
movups %xmm0, (%r12)
movaps 0xcd9b4(%rip), %xmm0    # 0xe67d0
movups %xmm0, 0x10(%r12)
movabsq $0x4055000000000000, %rax # imm = 0x4055000000000000
movq %rax, 0x20(%r12)
movsd 0xcd89f(%rip), %xmm0    # 0xe66d8
movsd 0xcd89f(%rip), %xmm1    # 0xe66e0
pushq $0x50
popq %rax
movsd 0xcd86c(%rip), %xmm2    # 0xe66b8
pushq $0x48
popq %rcx
movsd 0xcd891(%rip), %xmm3    # 0xe66e8
pushq $0x40
popq %rdx
movsd 0xcd88e(%rip), %xmm5    # 0xe66f0
pushq $0x38
popq %rsi
movsd 0xcd88b(%rip), %xmm4    # 0xe66f8
pushq $0x30
popq %rdi
movsd 0xcd888(%rip), %xmm6    # 0xe6700
pushq $0x28
jmp 0x18eed
movabsq $-0x3fda000000000000, %rax # imm = 0xC026000000000000
movq %rax, (%r12)
movaps 0xcd90f(%rip), %xmm0    # 0xe67a0
movups %xmm0, 0x10(%r12)
movaps 0xcd912(%rip), %xmm0    # 0xe67b0
movups %xmm0, 0x20(%r12)
movsd 0xcd7fc(%rip), %xmm0    # 0xe66a8
movsd 0xcd7fc(%rip), %xmm1    # 0xe66b0
pushq $0x60
popq %rax
movsd 0xcd7f9(%rip), %xmm2    # 0xe66b8
pushq $0x50
popq %rcx
movsd 0xcc92e(%rip), %xmm3    # 0xe57f8
pushq $0x48
popq %rdx
movsd 0xcd7eb(%rip), %xmm5    # 0xe66c0
pushq $0x40
popq %rsi
movsd 0xcd7e8(%rip), %xmm4    # 0xe66c8
pushq $0x38
popq %rdi
movsd 0xcd7e5(%rip), %xmm6    # 0xe66d0
pushq $0x30
popq %r13
jmp 0x18f53
movaps 0xcd8e8(%rip), %xmm0    # 0xe67e0
movups %xmm0, (%r12)
movabsq $0x4043800000000000, %rax # imm = 0x4043800000000000
movq %rax, 0x10(%r12)
movsd 0xcd7f4(%rip), %xmm0    # 0xe6708
movsd 0xcd7f4(%rip), %xmm1    # 0xe6710
pushq $0x40
popq %rax
movsd 0xcd7f1(%rip), %xmm2    # 0xe6718
pushq $0x38
popq %rcx
movsd 0xcd7ee(%rip), %xmm3    # 0xe6720
pushq $0x30
popq %rdx
pushq $0x28
popq %rsi
movsd 0xcd7e8(%rip), %xmm4    # 0xe6728
pushq $0x20
popq %rdi
movsd 0xcd7e5(%rip), %xmm6    # 0xe6730
pushq $0x18
popq %r13
movapd %xmm6, %xmm5
movsd %xmm6, (%r12,%r13)
movsd %xmm4, (%r12,%rdi)
movsd %xmm5, (%r12,%rsi)
movsd %xmm3, (%r12,%rdx)
movsd %xmm2, (%r12,%rcx)
movsd %xmm1, (%r12,%rax)
movl %r15d, %ecx
subl %ebx, %ecx
movl 0x4(%rsp), %eax
imull %r15d, %eax
decl %r15d
movslq %eax, %rdx
movslq %ebp, %rax
subl %ebx, %ebp
movslq %ecx, %rcx
movq 0x8(%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
movq %rax, %rsi
cmpq %rcx, %rsi
jge 0x19003
testl %ebp, %ebp
movl $0x0, %edi
cmovgl %ebp, %edi
leal (%rsi,%rbx), %r8d
cmpl %r15d, %r8d
cmovgel %r15d, %r8d
movslq %r8d, %r8
xorpd %xmm1, %xmm1
movq %r12, %r9
cmpq %r8, %rdi
jg 0x18fe4
movsd (%r9), %xmm2
mulsd (%rdx,%rdi,8), %xmm2
addsd %xmm2, %xmm1
movsd %xmm1, (%r14,%rsi,8)
incq %rdi
addq $0x8, %r9
jmp 0x18fc2
divsd %xmm0, %xmm1
movsd %xmm1, (%r14,%rsi,8)
incq %rsi
incl %ebp
jmp 0x18f9e
movsd (%r14,%rax,8), %xmm0
movsd %xmm0, (%rdx,%rax,8)
incq %rax
cmpq %rcx, %rax
jl 0x18ff5
movq %r14, %rdi
callq 0x8430
movq %r12, %rdi
callq 0x8430
xorl %eax, %eax
jmp 0x19078
leaq 0xce538(%rip), %rsi     # 0xe755b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2e014
leaq 0xcc54a(%rip), %rsi     # 0xe5585
leaq 0x810(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2e014
leaq 0xcbfdd(%rip), %rsi     # 0xe5034
leaq 0xce4e6(%rip), %rdx     # 0xe7544
movq 0x1050(%rsp), %rdi
movl $0xca3, %ecx            # imm = 0xCA3
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq