// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_spline
int array_spline(
		  double * array,
		  int n_columns,
		  int n_lines,
		  int index_x,   /** from 0 to (n_columns-1) */
		  int index_y,
		  int index_ddydx2,
		  short spline_mode,
		  ErrorMsg errmsg) {

  int i,k;
  double p,qn,sig,un;
  double * u;
  double dy_first;
  double dy_last;

  if (n_lines < 3) {
    class_sprintf(errmsg,"%s(L:%d) n_lines=%d, while routine needs n_lines >= 3",__func__,__LINE__,n_lines);
    return _FAILURE_;
  }

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

  if (spline_mode == _SPLINE_NATURAL_) {
    *(array+0*n_columns+index_ddydx2) = u[0] = 0.0;
  }
  else {
    if (spline_mode == _SPLINE_EST_DERIV_) {
      dy_first =
	((*(array+2*n_columns+index_x)-*(array+0*n_columns+index_x))*
	 (*(array+2*n_columns+index_x)-*(array+0*n_columns+index_x))*
	 (*(array+1*n_columns+index_y)-*(array+0*n_columns+index_y))-
	 (*(array+1*n_columns+index_x)-*(array+0*n_columns+index_x))*
	 (*(array+1*n_columns+index_x)-*(array+0*n_columns+index_x))*
	 (*(array+2*n_columns+index_y)-*(array+0*n_columns+index_y)))/
	((*(array+2*n_columns+index_x)-*(array+0*n_columns+index_x))*
	 (*(array+1*n_columns+index_x)-*(array+0*n_columns+index_x))*
	 (*(array+2*n_columns+index_x)-*(array+1*n_columns+index_x)));

      *(array+0*n_columns+index_ddydx2) = -0.5;

      u[0] =
	(3./(*(array+1*n_columns+index_x) -  *(array+0*n_columns+index_x)))*
	((*(array+1*n_columns+index_y) -  *(array+0*n_columns+index_y))/
	 (*(array+1*n_columns+index_x) -  *(array+0*n_columns+index_x))
	 -dy_first);
    }
    else {
      class_sprintf(errmsg,"%s(L:%d) Spline mode not identified: %d",__func__,__LINE__,spline_mode);
      return _FAILURE_;
    }
  }

  for (i=1; i < n_lines-1; i++) {

      sig = (*(array+i*n_columns+index_x) - *(array+(i-1)*n_columns+index_x))
	/ (*(array+(i+1)*n_columns+index_x) - *(array+(i-1)*n_columns+index_x));

      p = sig * *(array+(i-1)*n_columns+index_ddydx2) + 2.0;
      *(array+i*n_columns+index_ddydx2) = (sig-1.0)/p;
      u[i] = (*(array+(i+1)*n_columns+index_y) - *(array+i*n_columns+index_y))
	/ (*(array+(i+1)*n_columns+index_x) - *(array+i*n_columns+index_x))
	- (*(array+i*n_columns+index_y) - *(array+(i-1)*n_columns+index_y))
	/ (*(array+i*n_columns+index_x) - *(array+(i-1)*n_columns+index_x));
      u[i]= (6.0 * u[i] /
	     (*(array+(i+1)*n_columns+index_x) - *(array+(i-1)*n_columns+index_x))
	     - sig * u[i-1]) / p;

    }

  if (spline_mode == _SPLINE_NATURAL_) {
    qn=0.;
    un=0.;
  }
  else {
    if (spline_mode == _SPLINE_EST_DERIV_) {
      dy_last =
	((*(array+(n_lines-3)*n_columns+index_x)-*(array+(n_lines-1)*n_columns+index_x))*
	 (*(array+(n_lines-3)*n_columns+index_x)-*(array+(n_lines-1)*n_columns+index_x))*
	 (*(array+(n_lines-2)*n_columns+index_y)-*(array+(n_lines-1)*n_columns+index_y))-
	 (*(array+(n_lines-2)*n_columns+index_x)-*(array+(n_lines-1)*n_columns+index_x))*
	 (*(array+(n_lines-2)*n_columns+index_x)-*(array+(n_lines-1)*n_columns+index_x))*
	 (*(array+(n_lines-3)*n_columns+index_y)-*(array+(n_lines-1)*n_columns+index_y)))/
	((*(array+(n_lines-3)*n_columns+index_x)-*(array+(n_lines-1)*n_columns+index_x))*
	 (*(array+(n_lines-2)*n_columns+index_x)-*(array+(n_lines-1)*n_columns+index_x))*
	 (*(array+(n_lines-3)*n_columns+index_x)-*(array+(n_lines-2)*n_columns+index_x)));

      qn=0.5;
      un =
	(3./(*(array+(n_lines-1)*n_columns+index_x) -  *(array+(n_lines-2)*n_columns+index_x)))*
	(dy_last-(*(array+(n_lines-1)*n_columns+index_y) -  *(array+(n_lines-2)*n_columns+index_y))/
	 (*(array+(n_lines-1)*n_columns+index_x) -  *(array+(n_lines-2)*n_columns+index_x)));
    }
    else {
      class_sprintf(errmsg,"%s(L:%d) Spline mode not identified: %d",__func__,__LINE__,spline_mode);
      return _FAILURE_;
    }
  }

  *(array+(n_lines-1)*n_columns+index_ddydx2) =
    (un-qn*u[n_lines-2])/(qn* *(array+(n_lines-2)*n_columns+index_ddydx2)+1.0);

  for (k=n_lines-2; k>=0; k--)
    *(array+k*n_columns+index_ddydx2) = *(array+k*n_columns+index_ddydx2) *
      *(array+(k+1)*n_columns+index_ddydx2) + u[k];

  free(u);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r15d
movl %edx, %r9d
movq 0x88(%rsp), %rbx
cmpl $0x2, %edx
jg 0x1370a
leaq 0xdf6fd(%rip), %r14     # 0xf2dca
leaq 0xdf72c(%rip), %r15     # 0xf2e00
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x164, %r8d            # imm = 0x164
xorl %eax, %eax
movq %r9, %r12
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x164, %r8d            # imm = 0x164
movl %r12d, %r9d
jmp 0x13c15
movl %r8d, %r13d
movl %ecx, %r12d
movl %esi, %ebp
movq %rdi, 0x10(%rsp)
movq %r9, 0x20(%rsp)
leal -0x1(%r9), %r14d
leaq (,%r14,8), %rdi
callq 0x8460
testq %rax, %rax
je 0x1382f
movzwl 0x80(%rsp), %edx
movswl %dx, %r9d
movslq %r12d, %r10
movslq %r15d, %rcx
movslq %r13d, %rdi
movslq %ebp, %r8
testw %r9w, %r9w
je 0x13879
cmpw $0x1, %dx
jne 0x13aed
movl %r9d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
leal (%r8,%r8), %edx
movslq %edx, %rdx
movq 0x10(%rsp), %r9
leaq (%r9,%rdx,8), %rsi
movsd (%rsi,%r10,8), %xmm1
movsd (%r9,%r10,8), %xmm3
movapd %xmm1, %xmm2
subsd %xmm3, %xmm2
movapd %xmm2, %xmm4
mulsd %xmm2, %xmm4
leaq (%r9,%r8,8), %rdx
movsd (%rdx,%rdi,8), %xmm0
movsd (%r9,%rdi,8), %xmm5
subsd %xmm5, %xmm0
mulsd %xmm4, %xmm0
movsd (%rdx,%r10,8), %xmm4
subsd %xmm4, %xmm1
subsd %xmm3, %xmm4
movsd (%rsi,%rdi,8), %xmm3
subsd %xmm5, %xmm3
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm4
subsd %xmm4, %xmm0
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movabsq $-0x4020000000000000, %rsi # imm = 0xBFE0000000000000
movq %rsi, (%r9,%rcx,8)
movsd (%rdx,%r10,8), %xmm1
subsd (%r9,%r10,8), %xmm1
movsd (%rdx,%rdi,8), %xmm2
movq %r9, %rbx
subsd (%r9,%rdi,8), %xmm2
movapd 0xdef63(%rip), %xmm3    # 0xf2770
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
subsd %xmm0, %xmm1
mulsd %xmm3, %xmm1
movsd %xmm1, (%rax)
jmp 0x13893
leaq 0xdf5d7(%rip), %rbx     # 0xf2e0d
leaq 0xdf5c3(%rip), %r14     # 0xf2e00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x16a, %r8d            # imm = 0x16A
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x88(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x16a, %r8d            # imm = 0x16A
xorl %eax, %eax
callq 0x8550
jmp 0x13c1c
movl %r9d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
xorl %edx, %edx
movq %rdx, (%rax)
movq 0x10(%rsp), %rsi
movq %rsi, %rbx
movq %rdx, (%rsi,%rcx,8)
movq %r10, %rbp
cmpl $0x3, %r14d
movl $0x2, %r10d
movq %r14, 0x18(%rsp)
cmovgel %r14d, %r10d
movsd (%rax), %xmm3
leaq (,%r8,8), %rsi
leaq (,%rdi,8), %r11
leaq (%r11,%r8,8), %r15
movq %rcx, 0x38(%rsp)
leaq (,%rcx,8), %r12
leaq (%r12,%r8,8), %r13
leaq (,%rbp,8), %r9
leaq (%r9,%r8,8), %rdx
movq %r8, 0x40(%rsp)
shlq $0x4, %r8
movq %rdi, 0x30(%rsp)
leaq (%r8,%rdi,8), %rdi
movq %rbp, 0x28(%rsp)
leaq (%r8,%rbp,8), %rbp
movl $0x1, %ecx
movsd 0xde3fa(%rip), %xmm0    # 0xf1d00
movsd 0xddeda(%rip), %xmm1    # 0xf17e8
movsd 0xded5a(%rip), %xmm2    # 0xf2670
movsd (%rbx,%rdx), %xmm4
movsd (%rbx,%r9), %xmm5
subsd %xmm5, %xmm4
movsd (%rbx,%rbp), %xmm6
subsd %xmm5, %xmm6
divsd %xmm6, %xmm4
movsd (%rbx,%r12), %xmm5
mulsd %xmm4, %xmm5
addsd %xmm0, %xmm5
movapd %xmm4, %xmm6
addsd %xmm1, %xmm6
divsd %xmm5, %xmm6
movsd %xmm6, (%rbx,%r13)
movsd (%rbx,%rbp), %xmm6
movsd (%rbx,%r9), %xmm7
movsd (%rbx,%r15), %xmm8
mulsd %xmm3, %xmm4
movsd (%rbx,%rdi), %xmm3
unpcklpd %xmm8, %xmm3            # xmm3 = xmm3[0],xmm8[0]
movhpd (%rbx,%r11), %xmm8      # xmm8 = xmm8[0],mem[0]
subpd %xmm8, %xmm3
movsd (%rbx,%rdx), %xmm8
movapd %xmm6, %xmm9
unpcklpd %xmm8, %xmm9            # xmm9 = xmm9[0],xmm8[0]
unpcklpd %xmm7, %xmm8            # xmm8 = xmm8[0],xmm7[0]
subpd %xmm8, %xmm9
divpd %xmm9, %xmm3
movapd %xmm3, %xmm8
unpckhpd %xmm3, %xmm8            # xmm8 = xmm8[1],xmm3[1]
subsd %xmm8, %xmm3
mulsd %xmm2, %xmm3
subsd %xmm7, %xmm6
divsd %xmm6, %xmm3
subsd %xmm4, %xmm3
divsd %xmm5, %xmm3
movsd %xmm3, (%rax,%rcx,8)
leaq 0x1(%rcx), %r8
addq %rsi, %rbx
movq %r8, %rcx
cmpq %r8, %r10
jne 0x13916
movzwl 0x80(%rsp), %ecx
testw %cx, %cx
movl 0xc(%rsp), %r9d
movq 0x88(%rsp), %r15
je 0x13b33
cmpw $0x1, %cx
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %rbx
jne 0x13bd2
leal -0x3(%rbx), %ecx
imull %r9d, %ecx
movslq %ecx, %rcx
leaq (%r8,%rcx,8), %rcx
movq 0x28(%rsp), %r14
movsd (%rcx,%r14,8), %xmm2
movl %r10d, %edx
imull %r9d, %edx
movslq %edx, %rdx
leaq (%r8,%rdx,8), %rdx
movsd (%rdx,%r14,8), %xmm1
movapd %xmm2, %xmm4
subsd %xmm1, %xmm4
movapd %xmm4, %xmm5
mulsd %xmm4, %xmm5
leal -0x2(%rbx), %edi
imull %r9d, %edi
movslq %edi, %rdi
leaq (%r8,%rdi,8), %rdi
movq 0x30(%rsp), %r11
movsd (%rdi,%r11,8), %xmm3
movsd (%rdx,%r11,8), %xmm0
movapd %xmm3, %xmm6
subsd %xmm0, %xmm6
mulsd %xmm5, %xmm6
movsd (%rdi,%r14,8), %xmm5
movapd %xmm5, %xmm7
subsd %xmm1, %xmm7
movsd (%rcx,%r11,8), %xmm8
subsd %xmm0, %xmm8
mulsd %xmm7, %xmm4
mulsd %xmm7, %xmm7
mulsd %xmm8, %xmm7
subsd %xmm7, %xmm6
subsd %xmm5, %xmm2
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
unpcklpd %xmm4, %xmm5            # xmm5 = xmm5[0],xmm4[0]
movapd %xmm1, %xmm2
subpd %xmm5, %xmm2
mulpd %xmm1, %xmm5
movsd %xmm2, %xmm5            # xmm5 = xmm2[0],xmm5[1]
movapd 0xdecad(%rip), %xmm4    # 0xf2770
unpcklpd %xmm6, %xmm4            # xmm4 = xmm4[0],xmm6[0]
divpd %xmm5, %xmm4
subsd %xmm3, %xmm0
divsd %xmm2, %xmm0
movapd %xmm4, %xmm1
unpckhpd %xmm4, %xmm1            # xmm1 = xmm1[1],xmm4[1]
subsd %xmm0, %xmm1
mulsd %xmm4, %xmm1
movsd 0xde1e5(%rip), %xmm0    # 0xf1cd0
jmp 0x13b4a
leaq 0xdf334(%rip), %rbx     # 0xf2e28
leaq 0xdf305(%rip), %r14     # 0xf2e00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x187, %r8d            # imm = 0x187
movl %r9d, %ebp
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x88(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x187, %r8d            # imm = 0x187
jmp 0x13c12
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %rbx
movslq %ebx, %rdx
leaq -0x2(%rdx), %rdi
addl $-0x2, %ebx
movsd (%rax,%rbx,8), %xmm2
mulsd %xmm0, %xmm2
imull %r9d, %ebx
movslq %ebx, %rcx
movq 0x38(%rsp), %r11
leaq (%r8,%r11,8), %r8
mulsd (%r8,%rcx,8), %xmm0
subsd %xmm2, %xmm1
addsd 0xdd6e1(%rip), %xmm0    # 0xf1260
divsd %xmm0, %xmm1
imull %r9d, %r10d
movslq %r10d, %rcx
movsd %xmm1, (%r8,%rcx,8)
decq %rdx
movq %rdx, %r9
movq 0x40(%rsp), %rcx
imulq %rcx, %r9
negq %rsi
imulq %rcx, %rdi
movsd (%r8,%rdi,8), %xmm0
mulsd (%r8,%r9,8), %xmm0
addsd -0x8(%rax,%rdx,8), %xmm0
movsd %xmm0, (%r8,%rdi,8)
addq %rsi, %r8
decq %rdx
jg 0x13ba6
movq %rax, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x13c21
leaq 0xdf24f(%rip), %rbx     # 0xf2e28
leaq 0xdf220(%rip), %r14     # 0xf2e00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x1b5, %r8d            # imm = 0x1B5
movl 0x8(%rsp), %ebp
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x1b5, %r8d            # imm = 0x1B5
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8550
movl $0x1, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq