// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_spline_table_one_column
int array_spline_table_one_column(
		       double * x, /* vector of size x_size */
		       int x_size,
		       double * y_array, /* array of size x_size*y_size with elements
					  y_array[index_y*x_size+index_x] */
		       int y_size,
		       int index_y,
		       double * ddy_array, /* array of size x_size*y_size */
		       short spline_mode,
		       ErrorMsg errmsg
		       ) {

  double p;
  double qn;
  double un;
  double * u;
  double sig;
  int index_x;
  double dy_first;
  double dy_last;

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

  if (x_size==2) spline_mode = _SPLINE_NATURAL_; // in the case of only 2 x-values, only the natural spline method is appropriate, for _SPLINE_EST_DERIV_ at least 3 x-values are needed.

  /************************************************/

  index_x=0;

  if (spline_mode == _SPLINE_NATURAL_) {
    ddy_array[index_y*x_size+index_x] = 0.0;
    u[index_x] = 0.0;
  }
  else {
    if (spline_mode == _SPLINE_EST_DERIV_) {

      dy_first =
	((x[2]-x[0])*(x[2]-x[0])*
	 (y_array[index_y*x_size+1]-y_array[index_y*x_size+0])-
	 (x[1]-x[0])*(x[1]-x[0])*
	 (y_array[index_y*x_size+2]-y_array[index_y*x_size+0]))/
	((x[2]-x[0])*(x[1]-x[0])*(x[2]-x[1]));

      ddy_array[index_y*x_size+index_x] = -0.5;

      u[index_x] =
	(3./(x[1] -  x[0]))*
	((y_array[index_y*x_size+1]-y_array[index_y*x_size+0])/
	 (x[1] - x[0])-dy_first);

    }
    else {
      class_sprintf(errmsg,"%s(L:%d) Spline mode not identified: %d",__func__,__LINE__,spline_mode);
      return _FAILURE_;
    }
  }

  /************************************************/

  for (index_x=1; index_x < x_size-1; index_x++) {

    sig = (x[index_x] - x[index_x-1])/(x[index_x+1] - x[index_x-1]);

    p = sig * ddy_array[index_y*x_size+(index_x-1)] + 2.0;

    ddy_array[index_y*x_size+index_x] = (sig-1.0)/p;

    u[index_x] =
      (y_array[index_y*x_size+(index_x+1)] - y_array[index_y*x_size+index_x])
      / (x[index_x+1] - x[index_x])
      - (y_array[index_y*x_size+index_x] - y_array[index_y*x_size+(index_x-1)])
      / (x[index_x] - x[index_x-1]);

    u[index_x] = (6.0 * u[index_x] /
		  (x[index_x+1] - x[index_x-1])
		  - sig * u[index_x-1]) / p;

  }

  /************************************************/

  if (spline_mode == _SPLINE_NATURAL_) {

      qn=un=0.0;

  }
  else {
    if (spline_mode == _SPLINE_EST_DERIV_) {

      dy_last =
	((x[x_size-3]-x[x_size-1])*(x[x_size-3]-x[x_size-1])*
	 (y_array[index_y*x_size+(x_size-2)]-y_array[index_y*x_size+(x_size-1)])-
	 (x[x_size-2]-x[x_size-1])*(x[x_size-2]-x[x_size-1])*
	 (y_array[index_y*x_size+(x_size-3)]-y_array[index_y*x_size+(x_size-1)]))/
	((x[x_size-3]-x[x_size-1])*(x[x_size-2]-x[x_size-1])*(x[x_size-3]-x[x_size-2]));

      qn=0.5;

      un=
	(3./(x[x_size-1] - x[x_size-2]))*
	(dy_last-(y_array[index_y*x_size+(x_size-1)] - y_array[index_y*x_size+(x_size-2)])/
	 (x[x_size-1] - x[x_size-2]));

    }
    else {
      class_sprintf(errmsg,"%s(L:%d) Spline mode not identified: %d",__func__,__LINE__,spline_mode);
      return _FAILURE_;
    }
  }

  /************************************************/

  index_x=x_size-1;

  ddy_array[index_y*x_size+index_x] =
    (un - qn * u[index_x-1]) /
    (qn * ddy_array[index_y*x_size+(index_x-1)] + 1.0);

  for (index_x=x_size-2; index_x >= 0; index_x--) {

    ddy_array[index_y*x_size+index_x] = ddy_array[index_y*x_size+index_x] *
      ddy_array[index_y*x_size+(index_x+1)] + u[index_x];

  }

  free(u);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movl %r8d, %r14d
movq %rdx, (%rsp)
movl %esi, %r15d
movq %rdi, %r12
movq 0x48(%rsp), %r13
movslq %esi, %rbp
leaq -0x8(,%rbp,8), %rdi
callq 0x8460
testq %rax, %rax
je 0x1679a
movzwl 0x40(%rsp), %ecx
xorl %edx, %edx
cmpl $0x2, %r15d
cmovel %edx, %ecx
movswl %cx, %r13d
testw %r13w, %r13w
je 0x167df
cmpw $0x1, %cx
jne 0x169ee
movsd 0x10(%r12), %xmm2
movsd (%r12), %xmm3
movsd 0x8(%r12), %xmm4
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
movapd %xmm0, %xmm5
mulsd %xmm0, %xmm5
movl %r14d, %edx
imull %r15d, %edx
movslq %edx, %rdx
movq (%rsp), %rdi
movsd (%rdi,%rdx,8), %xmm6
movsd 0x8(%rdi,%rdx,8), %xmm1
subsd %xmm6, %xmm1
mulsd %xmm5, %xmm1
subsd %xmm4, %xmm2
subsd %xmm3, %xmm4
movsd 0x10(%rdi,%rdx,8), %xmm3
subsd %xmm6, %xmm3
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm4
subsd %xmm4, %xmm1
mulsd %xmm2, %xmm0
movabsq $-0x4020000000000000, %rsi # imm = 0xBFE0000000000000
movq %rsi, (%rbx,%rdx,8)
movsd 0x8(%r12), %xmm2
subsd (%r12), %xmm2
divsd %xmm0, %xmm1
movsd 0x8(%rdi,%rdx,8), %xmm0
subsd (%rdi,%rdx,8), %xmm0
movapd 0xd9004(%rip), %xmm3    # 0xef780
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
subsd %xmm1, %xmm0
mulsd %xmm3, %xmm0
jmp 0x167f5
leaq 0xd967c(%rip), %rbx     # 0xefe1d
leaq 0xd9877(%rip), %r14     # 0xf001f
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4be, %r8d            # imm = 0x4BE
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4be, %r8d            # imm = 0x4BE
xorl %eax, %eax
callq 0x8550
jmp 0x16aff
movl %r14d, %edx
imull %r15d, %edx
movslq %edx, %rdx
movq $0x0, (%rbx,%rdx,8)
xorpd %xmm0, %xmm0
leaq -0x1(%rbp), %rdx
movsd %xmm0, (%rax)
cmpl $0x3, %r15d
jl 0x1690a
movl %r14d, %esi
imull %r15d, %esi
movslq %esi, %r8
movl %edx, %esi
movsd (%r12), %xmm6
movsd 0x8(%r12), %xmm5
leaq (%rbx,%r8,8), %rdi
movsd (%rdi), %xmm4
movq (%rsp), %r9
leaq (%r9,%r8,8), %r8
movl $0x1, %r9d
movsd 0xd84c2(%rip), %xmm1    # 0xeed00
movsd 0xd7fa2(%rip), %xmm2    # 0xee7e8
movsd 0xd8e22(%rip), %xmm3    # 0xef670
subsd %xmm6, %xmm5
movsd 0x8(%r12,%r9,8), %xmm7
subsd %xmm6, %xmm7
divsd %xmm7, %xmm5
mulsd %xmm5, %xmm4
addsd %xmm1, %xmm4
movapd %xmm5, %xmm7
addsd %xmm2, %xmm7
divsd %xmm4, %xmm7
movsd %xmm7, (%rdi,%r9,8)
movsd -0x8(%r12,%r9,8), %xmm9
movupd (%r8,%r9,8), %xmm8
movupd (%r12,%r9,8), %xmm6
movsd -0x8(%r8,%r9,8), %xmm10
unpcklpd %xmm8, %xmm10           # xmm10 = xmm10[0],xmm8[0]
subpd %xmm10, %xmm8
movapd %xmm6, %xmm10
unpckhpd %xmm6, %xmm10           # xmm10 = xmm10[1],xmm6[1]
movapd %xmm10, %xmm11
subsd %xmm9, %xmm11
unpcklpd %xmm6, %xmm9            # xmm9 = xmm9[0],xmm6[0]
movapd %xmm6, %xmm12
subpd %xmm9, %xmm12
divpd %xmm12, %xmm8
mulsd %xmm0, %xmm5
movapd %xmm8, %xmm0
unpckhpd %xmm8, %xmm0            # xmm0 = xmm0[1],xmm8[1]
subsd %xmm8, %xmm0
mulsd %xmm3, %xmm0
divsd %xmm11, %xmm0
subsd %xmm5, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, (%rax,%r9,8)
leaq 0x1(%r9), %r10
movapd %xmm7, %xmm4
movapd %xmm10, %xmm5
movq %r10, %r9
cmpq %r10, %rsi
jne 0x1684e
testw %cx, %cx
je 0x16a31
cmpw $0x1, %cx
jne 0x16ab7
movsd (%r12,%rdx,8), %xmm1
movsd -0x18(%r12,%rbp,8), %xmm5
movsd -0x10(%r12,%rbp,8), %xmm0
movapd %xmm5, %xmm4
subsd %xmm1, %xmm4
movapd %xmm4, %xmm7
mulsd %xmm4, %xmm7
imull %r15d, %r14d
addq $-0x2, %rbp
leal (%r15,%r14), %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
movq (%rsp), %rdi
movsd (%rdi,%rcx,8), %xmm3
leal (%r14,%rdx), %edx
movslq %edx, %rdx
movsd (%rdi,%rdx,8), %xmm2
movapd %xmm3, %xmm6
subsd %xmm2, %xmm6
mulsd %xmm7, %xmm6
movapd %xmm0, %xmm7
subsd %xmm1, %xmm7
leal -0x3(%r15,%r14), %esi
movslq %esi, %rsi
movsd (%rdi,%rsi,8), %xmm8
subsd %xmm2, %xmm8
mulsd %xmm7, %xmm4
mulsd %xmm7, %xmm7
mulsd %xmm8, %xmm7
subsd %xmm7, %xmm6
subsd %xmm0, %xmm5
unpcklpd %xmm5, %xmm1            # xmm1 = xmm1[0],xmm5[0]
unpcklpd %xmm4, %xmm0            # xmm0 = xmm0[0],xmm4[0]
movapd %xmm1, %xmm4
subpd %xmm0, %xmm4
mulpd %xmm1, %xmm0
movsd %xmm4, %xmm0            # xmm0 = xmm4[0],xmm0[1]
movapd 0xd8dbc(%rip), %xmm1    # 0xef780
unpcklpd %xmm6, %xmm1            # xmm1 = xmm1[0],xmm6[0]
divpd %xmm0, %xmm1
subsd %xmm3, %xmm2
divsd %xmm4, %xmm2
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
subsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
movsd 0xd82e4(%rip), %xmm1    # 0xeecd0
jmp 0x16a54
leaq 0xd9443(%rip), %rbx     # 0xefe38
leaq 0xd9623(%rip), %r14     # 0xf001f
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4df, %r8d            # imm = 0x4DF
movl %r13d, %r9d
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x48(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4df, %r8d            # imm = 0x4DF
jmp 0x16af5
leal -0x2(%r15), %ecx
movslq %ecx, %rbp
imull %r15d, %r14d
leal (%r14,%r15), %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
addl %r14d, %edx
movslq %edx, %rdx
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movsd (%rax,%rbp,8), %xmm2
mulsd %xmm1, %xmm2
mulsd (%rbx,%rcx,8), %xmm1
addsd 0xd77f6(%rip), %xmm1    # 0xee260
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rbx,%rdx,8)
cmpl $0x2, %r15d
jl 0x16aab
movslq %r14d, %rdx
leaq (%rbx,%rdx,8), %rcx
incq %rbp
movl %edx, %edx
movsd -0x8(%rcx,%rbp,8), %xmm0
leal (%rdx,%rbp), %esi
movslq %esi, %rsi
mulsd (%rbx,%rsi,8), %xmm0
addsd -0x8(%rax,%rbp,8), %xmm0
movsd %xmm0, -0x8(%rcx,%rbp,8)
decq %rbp
jg 0x16a89
movq %rax, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x16b04
leaq 0xd937a(%rip), %rbx     # 0xefe38
leaq 0xd955a(%rip), %r14     # 0xf001f
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x514, %r8d            # imm = 0x514
movl %r13d, %r9d
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x48(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x514, %r8d            # imm = 0x514
movl %r13d, %r9d
xorl %eax, %eax
callq 0x8550
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq