// File: /workspace/github_c_makefile_star2_O2/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), %r14
cmpl $0x2, %edx
jg 0x11b6a
movq %r14, %r12
leaq 0xd526d(%rip), %r14     # 0xe6d9a
leaq 0xd529c(%rip), %r15     # 0xe6dd0
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x164, %r8d            # imm = 0x164
movl %ebx, %r9d
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x164, %r8d            # imm = 0x164
movl %ebx, %r9d
jmp 0x1204c
movl %r9d, %r13d
movl %r8d, %r15d
movl %ecx, %ebp
movq %rdi, %r12
movq %rsi, 0x8(%rsp)
leal -0x1(%rbx), %eax
movq %rax, 0x10(%rsp)
leaq (,%rax,8), %rdi
callq 0x8490
testq %rax, %rax
je 0x11c89
movzwl 0x70(%rsp), %ecx
movswl %cx, %r9d
testw %r9w, %r9w
je 0x11cd1
cmpw $0x1, %cx
jne 0x11f2a
movl %r9d, 0x4(%rsp)
movq 0x8(%rsp), %rsi
leal (%rsi,%rsi), %ecx
movslq %ecx, %rcx
leaq (%r12,%rcx,8), %rdx
movslq %ebp, %r14
movsd (%rdx,%r14,8), %xmm0
movsd (%r12,%r14,8), %xmm3
movapd %xmm0, %xmm2
subsd %xmm3, %xmm2
movapd %xmm2, %xmm4
mulsd %xmm2, %xmm4
movslq %esi, %rdi
leaq (%r12,%rdi,8), %rcx
movslq %r15d, %rsi
movsd (%rcx,%rsi,8), %xmm1
movsd (%r12,%rsi,8), %xmm5
subsd %xmm5, %xmm1
mulsd %xmm4, %xmm1
movsd (%rcx,%r14,8), %xmm4
subsd %xmm4, %xmm0
subsd %xmm3, %xmm4
movsd (%rdx,%rsi,8), %xmm3
subsd %xmm5, %xmm3
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm4
subsd %xmm4, %xmm1
mulsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movslq %r13d, %r8
movabsq $-0x4020000000000000, %rdx # imm = 0xBFE0000000000000
movq %rdx, (%r12,%r8,8)
movsd (%rcx,%r14,8), %xmm0
subsd (%r12,%r14,8), %xmm0
movsd (%rcx,%rsi,8), %xmm2
movq %rsi, %rcx
subsd (%r12,%rsi,8), %xmm2
movapd 0xd4ae9(%rip), %xmm3    # 0xe6750
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 0x11cf1
leaq 0xd514d(%rip), %rbx     # 0xe6ddd
movq %r14, %r15
leaq 0xd5136(%rip), %r14     # 0xe6dd0
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x16a, %r8d            # imm = 0x16A
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x16a, %r8d            # imm = 0x16A
xorl %eax, %eax
callq 0x8580
jmp 0x12053
movl %r9d, 0x4(%rsp)
andq $0x0, (%rax)
movslq %r13d, %r8
andq $0x0, (%r12,%r8,8)
movslq %ebp, %r14
movslq %r15d, %rcx
movslq 0x8(%rsp), %rdi
xorpd %xmm0, %xmm0
movl 0x10(%rsp), %r10d
leaq (,%rcx,8), %r11
leaq (,%rdi,8), %rsi
movq %r8, 0x28(%rsp)
leaq (,%r8,8), %r15
leaq (,%r14,8), %r13
leaq (%r11,%rdi,8), %rbp
leaq (%r15,%rdi,8), %r9
leaq (,%rdi,8), %rdx
addq %r13, %rdx
movq %rdi, 0x30(%rsp)
shlq $0x4, %rdi
movq %rcx, 0x18(%rsp)
leaq (%rdi,%rcx,8), %rcx
movq %r14, 0x20(%rsp)
leaq (%rdi,%r14,8), %rdi
pushq $0x1
popq %r8
movsd 0xd3f8b(%rip), %xmm1    # 0xe5ce0
movsd 0xd3a8b(%rip), %xmm2    # 0xe57e8
movsd 0xd48eb(%rip), %xmm3    # 0xe6650
movq %r12, %r14
cmpq %r10, %r8
jae 0x11e2e
movsd (%r14,%rdx), %xmm4
movsd (%r14,%r13), %xmm5
subsd %xmm5, %xmm4
movsd (%r14,%rdi), %xmm6
subsd %xmm5, %xmm6
divsd %xmm6, %xmm4
movsd (%r14,%r15), %xmm5
mulsd %xmm4, %xmm5
addsd %xmm1, %xmm5
movapd %xmm4, %xmm6
addsd %xmm2, %xmm6
divsd %xmm5, %xmm6
movsd %xmm6, (%r14,%r9)
movsd (%r14,%rdi), %xmm6
movsd (%r14,%r13), %xmm7
movsd (%r14,%rbp), %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,%r8,8)
incq %r8
addq %rsi, %r14
jmp 0x11d68
movzwl 0x70(%rsp), %ecx
testw %cx, %cx
je 0x11f6e
cmpw $0x1, %cx
jne 0x12007
leal -0x3(%rbx), %ecx
movq 0x8(%rsp), %rdx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%r12,%rcx,8), %rdi
movq 0x20(%rsp), %r10
movsd (%rdi,%r10,8), %xmm2
movq 0x10(%rsp), %rcx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%r12,%rcx,8), %r8
movsd (%r8,%r10,8), %xmm1
movapd %xmm2, %xmm4
subsd %xmm1, %xmm4
movapd %xmm4, %xmm5
mulsd %xmm4, %xmm5
addl $-0x2, %ebx
imull %ebx, %edx
movslq %edx, %rdx
leaq (%r12,%rdx,8), %r9
movq 0x18(%rsp), %r11
movsd (%r9,%r11,8), %xmm3
movsd (%r8,%r11,8), %xmm0
movapd %xmm3, %xmm6
subsd %xmm0, %xmm6
mulsd %xmm5, %xmm6
movsd (%r9,%r10,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 0xd4850(%rip), %xmm4    # 0xe6750
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 0xd3d88(%rip), %xmm0    # 0xe5cb0
jmp 0x11f91
leaq 0xd4ec7(%rip), %rbx     # 0xe6df8
movq %r14, %r15
leaq 0xd4e95(%rip), %r14     # 0xe6dd0
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x187, %r8d            # imm = 0x187
movl %r9d, %ebp
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x187, %r8d            # imm = 0x187
jmp 0x12049
addl $-0x2, %ebx
movl %ebx, %ecx
movq 0x8(%rsp), %rdi
imull %edi, %ecx
movslq %ecx, %rdx
movq 0x10(%rsp), %rcx
imull %edi, %ecx
movslq %ecx, %rcx
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movl %ebx, %edi
movsd (%rax,%rdi,8), %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm1
movq 0x28(%rsp), %rdi
leaq (%r12,%rdi,8), %rdi
mulsd (%rdi,%rdx,8), %xmm0
addsd 0xd32aa(%rip), %xmm0    # 0xe5260
divsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%rcx,8)
movslq %ebx, %rcx
movq 0x30(%rsp), %r9
movq %r9, %rdx
imulq %rcx, %rdx
negq %rsi
leaq 0x1(%rcx), %r8
imulq %r9, %r8
testq %rcx, %rcx
js 0x11ffb
movsd (%rdi,%rdx,8), %xmm0
mulsd (%rdi,%r8,8), %xmm0
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rdi,%rdx,8)
decq %rcx
addq %rsi, %rdi
jmp 0x11fd9
movq %rax, %rdi
callq 0x8430
xorl %eax, %eax
jmp 0x12056
leaq 0xd4dea(%rip), %rbx     # 0xe6df8
leaq 0xd4dbb(%rip), %r14     # 0xe6dd0
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 0x8580
incl %eax
movslq %eax, %rsi
movq 0x78(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x1b5, %r8d            # imm = 0x1B5
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8580
pushq $0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq