// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movq 0x1050(%rsp), %r12
movslq %esi, %rdi
shlq $0x3, %rdi
callq 0x8460
testq %rax, %rax
je 0x1aee7
movq %rax, %r14
movl %r13d, 0x4(%rsp)
leal 0x1(,%rbx,2), %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x8250
testq %rax, %rax
je 0x1af2c
movq %rax, %r13
leal -0x3(%rbx), %eax
cmpl $0x4, %eax
ja 0x1b27c
leaq 0xd49b3(%rip), %rcx     # 0xef830
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movabsq $-0x4000000000000000, %rax # imm = 0xC000000000000000
movq %rax, (%r13)
movsd 0xd484c(%rip), %xmm0    # 0xef6e8
movsd 0xd48bc(%rip), %xmm1    # 0xef760
movl $0x30, %eax
movl $0x28, %ecx
movl $0x20, %edx
movsd 0xd48ad(%rip), %xmm5    # 0xef768
movl $0x18, %esi
movsd 0xd47a8(%rip), %xmm4    # 0xef670
movl $0x10, %edi
movsd 0xd47ab(%rip), %xmm6    # 0xef680
movl $0x8, %r8d
movaps %xmm4, %xmm3
movapd %xmm6, %xmm2
jmp 0x1b171
leaq 0xd5676(%rip), %rbx     # 0xf0564
leaq 0xd568f(%rip), %r14     # 0xf0584
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 0x1b2d0
leaq 0xd30d1(%rip), %rsi     # 0xee004
leaq 0xd565b(%rip), %rdx     # 0xf0595
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %ecx
xorl %eax, %eax
callq 0x30af0
leaq 0xd30df(%rip), %rsi     # 0xee034
leaq 0xd5628(%rip), %rdx     # 0xf0584
movq %r12, %rdi
movl $0xc4b, %ecx            # imm = 0xC4B
jmp 0x1b2c6
movaps 0xd4830(%rip), %xmm0    # 0xef7a0
movups %xmm0, (%r13)
movaps 0xd4834(%rip), %xmm0    # 0xef7b0
movups %xmm0, 0x10(%r13)
movaps 0xd4838(%rip), %xmm0    # 0xef7c0
movups %xmm0, 0x20(%r13)
movaps 0xd483c(%rip), %xmm0    # 0xef7d0
movups %xmm0, 0x30(%r13)
movabsq $0x4064400000000000, %rax # imm = 0x4064400000000000
movq %rax, 0x40(%r13)
movsd 0xd46e9(%rip), %xmm0    # 0xef698
movsd 0xd46e9(%rip), %xmm1    # 0xef6a0
movl $0x70, %eax
movsd 0xd46e4(%rip), %xmm2    # 0xef6a8
movl $0x68, %ecx
movsd 0xd46df(%rip), %xmm3    # 0xef6b0
movl $0x60, %edx
movsd 0xd46da(%rip), %xmm5    # 0xef6b8
movl $0x58, %esi
movsd 0xd46d5(%rip), %xmm4    # 0xef6c0
movl $0x50, %edi
movsd 0xd46d0(%rip), %xmm6    # 0xef6c8
movl $0x48, %r8d
jmp 0x1b171
movaps 0xd47f6(%rip), %xmm0    # 0xef800
movups %xmm0, (%r13)
movaps 0xd47fa(%rip), %xmm0    # 0xef810
movups %xmm0, 0x10(%r13)
movabsq $0x4055000000000000, %rax # imm = 0x4055000000000000
movq %rax, 0x20(%r13)
movsd 0xd46cf(%rip), %xmm0    # 0xef700
movsd 0xd46cf(%rip), %xmm1    # 0xef708
movl $0x50, %eax
movsd 0xd469a(%rip), %xmm2    # 0xef6e0
movl $0x48, %ecx
movsd 0xd46bd(%rip), %xmm3    # 0xef710
movl $0x40, %edx
movsd 0xd46b8(%rip), %xmm5    # 0xef718
movl $0x38, %esi
movsd 0xd46b3(%rip), %xmm4    # 0xef720
movl $0x30, %edi
movsd 0xd46ae(%rip), %xmm6    # 0xef728
movl $0x28, %r8d
jmp 0x1b171
movabsq $-0x3fda000000000000, %rax # imm = 0xC026000000000000
movq %rax, (%r13)
movaps 0xd4746(%rip), %xmm0    # 0xef7e0
movups %xmm0, 0x10(%r13)
movaps 0xd474a(%rip), %xmm0    # 0xef7f0
movups %xmm0, 0x20(%r13)
movsd 0xd461d(%rip), %xmm0    # 0xef6d0
movsd 0xd461d(%rip), %xmm1    # 0xef6d8
movl $0x60, %eax
movsd 0xd4618(%rip), %xmm2    # 0xef6e0
movl $0x50, %ecx
movsd 0xd3723(%rip), %xmm3    # 0xee7f8
movl $0x48, %edx
movsd 0xd4606(%rip), %xmm5    # 0xef6e8
movl $0x40, %esi
movsd 0xd4601(%rip), %xmm4    # 0xef6f0
movl $0x38, %edi
movsd 0xd45fc(%rip), %xmm6    # 0xef6f8
movl $0x30, %r8d
jmp 0x1b171
movaps 0xd4715(%rip), %xmm0    # 0xef820
movups %xmm0, (%r13)
movabsq $0x4043800000000000, %rax # imm = 0x4043800000000000
movq %rax, 0x10(%r13)
movsd 0xd460a(%rip), %xmm0    # 0xef730
movsd 0xd460a(%rip), %xmm1    # 0xef738
movl $0x40, %eax
movsd 0xd4605(%rip), %xmm2    # 0xef740
movl $0x38, %ecx
movsd 0xd4600(%rip), %xmm3    # 0xef748
movl $0x30, %edx
movl $0x28, %esi
movsd 0xd45f6(%rip), %xmm4    # 0xef750
movl $0x20, %edi
movsd 0xd45f1(%rip), %xmm6    # 0xef758
movl $0x18, %r8d
movapd %xmm6, %xmm5
movsd %xmm6, (%r13,%r8)
movsd %xmm4, (%r13,%rdi)
movsd %xmm5, (%r13,%rsi)
movsd %xmm3, (%r13,%rdx)
movsd %xmm2, (%r13,%rcx)
movsd %xmm1, (%r13,%rax)
movl %r15d, %eax
subl %ebx, %eax
cmpl %ebp, %eax
jle 0x1b268
leal -0x1(%r15), %ecx
movl 0x4(%rsp), %esi
imull %r15d, %esi
movl %ebp, %edx
subl %ebx, %edx
movl %esi, 0x4(%rsp)
movslq %esi, %r8
movslq %ebp, %rsi
movslq %eax, %rdi
movq 0x8(%rsp), %r9
leaq (%r9,%r8,8), %r8
xorl %r9d, %r9d
testl %edx, %edx
movl $0x0, %r10d
cmovgl %edx, %r10d
movl %esi, %r12d
subl %ebx, %r12d
testl %r12d, %r12d
cmovlel %r9d, %r12d
leal (%rsi,%rbx), %r11d
cmpl %ecx, %r11d
cmovgel %ecx, %r11d
xorpd %xmm1, %xmm1
cmpl %r11d, %r12d
jg 0x1b224
decq %r10
movl %r11d, %r11d
movq %r13, %r12
movsd (%r12), %xmm2
mulsd 0x8(%r8,%r10,8), %xmm2
addsd %xmm2, %xmm1
incq %r10
addq $0x8, %r12
cmpq %r11, %r10
jb 0x1b207
divsd %xmm0, %xmm1
movsd %xmm1, (%r14,%rsi,8)
incq %rsi
incl %edx
cmpq %rdi, %rsi
jl 0x1b1d1
cmpl %ebp, %eax
jle 0x1b268
movl 0x4(%rsp), %eax
addl %ebp, %eax
cltq
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movslq %ebp, %rax
leaq (%r14,%rax,8), %rsi
notl %ebx
addl %r15d, %ebx
subl %ebp, %ebx
leaq 0x8(,%rbx,8), %rdx
callq 0x82d0
movq %r14, %rdi
callq 0x8410
movq %r13, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x1b2d5
leaq 0xd5318(%rip), %rsi     # 0xf059b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x30af0
leaq 0xd32ea(%rip), %rsi     # 0xee585
leaq 0x810(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
leaq 0xd2d7d(%rip), %rsi     # 0xee034
leaq 0xd52c6(%rip), %rdx     # 0xf0584
movq %r12, %rdi
movl $0xca3, %ecx            # imm = 0xCA3
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq