// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %edx, %ebx
movq 0x78(%rsp), %r12
cmpl $0x2, %edx
jg 0x1387c
leaq 0xdc59b(%rip), %r14     # 0xefdda
leaq 0xdc5ca(%rip), %r15     # 0xefe10
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x164, %r8d            # imm = 0x164
movl %ebx, %r9d
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x164, %r8d            # imm = 0x164
movl %ebx, %r9d
jmp 0x13d4a
movl %r9d, %r15d
movl %r8d, %r13d
movl %ecx, %ebp
movq %rdi, %r14
movl %esi, (%rsp)
leal -0x1(%rbx), %eax
movq %rax, 0x8(%rsp)
leaq (,%rax,8), %rdi
callq 0x8460
testq %rax, %rax
je 0x13992
movzwl 0x70(%rsp), %ecx
movswl %cx, %r9d
movslq %ebp, %rsi
movslq %r15d, %r8
movslq %r13d, %r11
movslq (%rsp), %rdi
testw %r9w, %r9w
je 0x139d7
cmpw $0x1, %cx
jne 0x13c2e
movl %r9d, 0x4(%rsp)
leal (%rdi,%rdi), %ecx
movslq %ecx, %rcx
leaq (%r14,%rcx,8), %rdx
movsd (%rdx,%rsi,8), %xmm0
movsd (%r14,%rsi,8), %xmm3
movapd %xmm0, %xmm2
subsd %xmm3, %xmm2
movapd %xmm2, %xmm4
mulsd %xmm2, %xmm4
leaq (%r14,%rdi,8), %rcx
movsd (%rcx,%r11,8), %xmm1
movsd (%r14,%r11,8), %xmm5
subsd %xmm5, %xmm1
mulsd %xmm4, %xmm1
movsd (%rcx,%rsi,8), %xmm4
subsd %xmm4, %xmm0
subsd %xmm3, %xmm4
movsd (%rdx,%r11,8), %xmm3
subsd %xmm5, %xmm3
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm4
subsd %xmm4, %xmm1
mulsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movabsq $-0x4020000000000000, %rdx # imm = 0xBFE0000000000000
movq %rdx, (%r14,%r8,8)
movsd (%rcx,%rsi,8), %xmm0
subsd (%r14,%rsi,8), %xmm0
movsd (%rcx,%r11,8), %xmm2
subsd (%r14,%r11,8), %xmm2
movapd 0xdbe10(%rip), %xmm3    # 0xef780
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
subsd %xmm1, %xmm0
mulsd %xmm3, %xmm0
movsd %xmm0, (%rax)
jmp 0x139e9
leaq 0xdc484(%rip), %rbx     # 0xefe1d
leaq 0xdc470(%rip), %r14     # 0xefe10
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 %r12, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x16a, %r8d            # imm = 0x16A
xorl %eax, %eax
callq 0x8550
jmp 0x13d51
movl %r9d, 0x4(%rsp)
xorl %ecx, %ecx
movq %rcx, (%rax)
movq %rcx, (%r14,%r8,8)
xorpd %xmm0, %xmm0
movq %rsi, %r12
movl 0x8(%rsp), %r10d
leaq (,%rdi,8), %rsi
movq %r11, %rcx
leaq (,%r11,8), %r11
leaq (%r11,%rdi,8), %r15
movq %r8, 0x28(%rsp)
leaq (,%r8,8), %r13
leaq (%r13,%rdi,8), %rbp
leaq (,%r12,8), %r9
leaq (%r9,%rdi,8), %rdx
movq %rdi, 0x30(%rsp)
shlq $0x4, %rdi
movq %rcx, 0x20(%rsp)
leaq (%rdi,%rcx,8), %rcx
movq %r12, 0x18(%rsp)
leaq (%rdi,%r12,8), %rdi
movl $0x1, %r12d
movsd 0xdb2b1(%rip), %xmm1    # 0xeed00
movsd 0xdad91(%rip), %xmm2    # 0xee7e8
movsd 0xdbc11(%rip), %xmm3    # 0xef670
movq %r14, 0x10(%rsp)
movsd (%r14,%rdx), %xmm4
movsd (%r14,%r9), %xmm5
subsd %xmm5, %xmm4
movsd (%r14,%rdi), %xmm6
subsd %xmm5, %xmm6
divsd %xmm6, %xmm4
movsd (%r14,%r13), %xmm5
mulsd %xmm4, %xmm5
addsd %xmm1, %xmm5
movapd %xmm4, %xmm6
addsd %xmm2, %xmm6
divsd %xmm5, %xmm6
movsd %xmm6, (%r14,%rbp)
movsd (%r14,%rdi), %xmm6
movsd (%r14,%r9), %xmm7
movsd (%r14,%r15), %xmm8
mulsd %xmm0, %xmm4
movsd (%r14,%rcx), %xmm0
unpcklpd %xmm8, %xmm0            # xmm0 = xmm0[0],xmm8[0]
movhpd (%r14,%r11), %xmm8      # xmm8 = xmm8[0],mem[0]
subpd %xmm8, %xmm0
movsd (%r14,%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, %xmm0
movapd %xmm0, %xmm8
unpckhpd %xmm0, %xmm8            # xmm8 = xmm8[1],xmm0[1]
subsd %xmm8, %xmm0
mulsd %xmm3, %xmm0
subsd %xmm7, %xmm6
divsd %xmm6, %xmm0
subsd %xmm4, %xmm0
divsd %xmm5, %xmm0
movsd %xmm0, (%rax,%r12,8)
leaq 0x1(%r12), %r8
addq %rsi, %r14
movq %r8, %r12
cmpq %r8, %r10
jne 0x13a64
movzwl 0x70(%rsp), %ecx
testw %cx, %cx
movq 0x78(%rsp), %r15
je 0x13c6f
cmpw $0x1, %cx
movq 0x10(%rsp), %r10
jne 0x13d07
leal -0x3(%rbx), %ecx
movl (%rsp), %edx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%r10,%rcx,8), %rdi
movq 0x18(%rsp), %r14
movsd (%rdi,%r14,8), %xmm2
movq 0x8(%rsp), %rcx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%r10,%rcx,8), %r8
movsd (%r8,%r14,8), %xmm1
movapd %xmm2, %xmm4
subsd %xmm1, %xmm4
movapd %xmm4, %xmm5
mulsd %xmm4, %xmm5
addl $-0x2, %ebx
imull %ebx, %edx
movslq %edx, %rdx
leaq (%r10,%rdx,8), %r9
movq 0x20(%rsp), %r11
movsd (%r9,%r11,8), %xmm3
movsd (%r8,%r11,8), %xmm0
movapd %xmm3, %xmm6
subsd %xmm0, %xmm6
mulsd %xmm5, %xmm6
movsd (%r9,%r14,8), %xmm5
movapd %xmm5, %xmm7
subsd %xmm1, %xmm7
movsd (%rdi,%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 0xdbb7c(%rip), %xmm4    # 0xef780
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 0xdb0a4(%rip), %xmm0    # 0xeecd0
jmp 0x13c95
leaq 0xdc203(%rip), %rbx     # 0xefe38
leaq 0xdc1d4(%rip), %r14     # 0xefe10
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x187, %r8d            # imm = 0x187
xorl %eax, %eax
movl %r9d, %ebp
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %r12, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x187, %r8d            # imm = 0x187
jmp 0x13d47
addl $-0x2, %ebx
movl %ebx, %ecx
movl (%rsp), %edi
imull %edi, %ecx
movslq %ecx, %rdx
movq 0x8(%rsp), %rcx
imull %edi, %ecx
movslq %ecx, %rcx
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movq 0x10(%rsp), %r10
movl %ebx, %edi
movsd (%rax,%rdi,8), %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm1
movq 0x28(%rsp), %rdi
leaq (%r10,%rdi,8), %rdi
mulsd (%rdi,%rdx,8), %xmm0
addsd 0xda5a6(%rip), %xmm0    # 0xee260
divsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%rcx,8)
movslq %ebx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, %r8
movq 0x30(%rsp), %r9
imulq %r9, %r8
negq %rsi
imulq %r9, %rcx
movsd (%rdi,%rcx,8), %xmm0
mulsd (%rdi,%r8,8), %xmm0
addsd -0x8(%rax,%rdx,8), %xmm0
movsd %xmm0, (%rdi,%rcx,8)
addq %rsi, %rdi
decq %rdx
jg 0x13cdd
movq %rax, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x13d56
leaq 0xdc12a(%rip), %rbx     # 0xefe38
leaq 0xdc0fb(%rip), %r14     # 0xefe10
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x1b5, %r8d            # imm = 0x1B5
movl 0x4(%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 $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq