// File: /workspace/github_c_makefile_star2_O1/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, %r15
movl %esi, %ebp
movq %rdi, %r12
movslq %esi, %rax
movq %rax, %r13
leaq -0x8(,%rax,8), %rdi
callq 0x8460
testq %rax, %rax
je 0x1664b
movzwl 0x40(%rsp), %edx
xorl %ecx, %ecx
cmpl $0x2, %ebp
cmovel %ecx, %edx
movswl %dx, %r9d
testw %r9w, %r9w
je 0x16692
cmpw $0x1, %dx
jne 0x16894
movl %r9d, 0x4(%rsp)
movsd 0x10(%r12), %xmm2
movsd (%r12), %xmm3
movsd 0x8(%r12), %xmm4
movapd %xmm2, %xmm1
subsd %xmm3, %xmm1
movapd %xmm1, %xmm5
mulsd %xmm1, %xmm5
movl %r14d, %ecx
imull %ebp, %ecx
movslq %ecx, %rcx
movsd (%r15,%rcx,8), %xmm6
movsd 0x8(%r15,%rcx,8), %xmm0
subsd %xmm6, %xmm0
mulsd %xmm5, %xmm0
subsd %xmm4, %xmm2
subsd %xmm3, %xmm4
movsd 0x10(%r15,%rcx,8), %xmm3
subsd %xmm6, %xmm3
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm4
subsd %xmm4, %xmm0
mulsd %xmm2, %xmm1
movabsq $-0x4020000000000000, %rsi # imm = 0xBFE0000000000000
movq %rsi, (%rbx,%rcx,8)
movsd 0x8(%r12), %xmm2
subsd (%r12), %xmm2
divsd %xmm1, %xmm0
movsd 0x8(%r15,%rcx,8), %xmm1
subsd (%r15,%rcx,8), %xmm1
movapd 0xdc143(%rip), %xmm3    # 0xf2770
unpcklpd %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0]
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
subsd %xmm0, %xmm1
mulsd %xmm3, %xmm1
jmp 0x166ac
leaq 0xdc7bb(%rip), %rbx     # 0xf2e0d
leaq 0xdc9b6(%rip), %r14     # 0xf300f
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 0x48(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4be, %r8d            # imm = 0x4BE
xorl %eax, %eax
callq 0x8550
jmp 0x169b2
movl %r9d, 0x4(%rsp)
movl %r14d, %ecx
imull %ebp, %ecx
movslq %ecx, %rcx
movq $0x0, (%rbx,%rcx,8)
xorpd %xmm1, %xmm1
leaq -0x1(%r13), %rcx
movsd %xmm1, (%rax)
cmpl $0x3, %ebp
jl 0x167b6
movl %r14d, %esi
imull %ebp, %esi
movslq %esi, %r8
movl %ecx, %esi
movsd (%rax), %xmm4
leaq (%rbx,%r8,8), %rdi
movsd (%rdi), %xmm2
leaq (%r15,%r8,8), %r8
movl $0x1, %r9d
movsd 0xdb61a(%rip), %xmm0    # 0xf1d00
movsd 0xdb0fa(%rip), %xmm1    # 0xf17e8
movsd 0xdbf7a(%rip), %xmm3    # 0xf2670
movupd (%r12,%r9,8), %xmm5
movsd -0x8(%r12,%r9,8), %xmm6
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
subpd %xmm6, %xmm5
movapd %xmm5, %xmm6
unpckhpd %xmm5, %xmm6            # xmm6 = xmm6[1],xmm5[1]
divsd %xmm6, %xmm5
mulsd %xmm5, %xmm2
addsd %xmm0, %xmm2
movapd %xmm5, %xmm6
addsd %xmm1, %xmm6
divsd %xmm2, %xmm6
movsd %xmm6, (%rdi,%r9,8)
movsd -0x8(%r12,%r9,8), %xmm7
movupd (%r8,%r9,8), %xmm8
movupd (%r12,%r9,8), %xmm9
movsd -0x8(%r8,%r9,8), %xmm10
unpcklpd %xmm8, %xmm10           # xmm10 = xmm10[0],xmm8[0]
subpd %xmm10, %xmm8
movapd %xmm7, %xmm10
unpcklpd %xmm9, %xmm10           # xmm10 = xmm10[0],xmm9[0]
movapd %xmm9, %xmm11
subpd %xmm10, %xmm11
divpd %xmm11, %xmm8
mulsd %xmm4, %xmm5
movapd %xmm8, %xmm4
unpckhpd %xmm8, %xmm4            # xmm4 = xmm4[1],xmm8[1]
subsd %xmm8, %xmm4
mulsd %xmm3, %xmm4
unpckhpd %xmm9, %xmm9            # xmm9 = xmm9[1,1]
subsd %xmm7, %xmm9
divsd %xmm9, %xmm4
subsd %xmm5, %xmm4
divsd %xmm2, %xmm4
movsd %xmm4, (%rax,%r9,8)
leaq 0x1(%r9), %r10
movapd %xmm6, %xmm2
movq %r10, %r9
cmpq %r10, %rsi
jne 0x166f6
testw %dx, %dx
je 0x168d7
cmpw $0x1, %dx
jne 0x16966
movsd (%r12,%rcx,8), %xmm1
movsd -0x18(%r12,%r13,8), %xmm4
movsd -0x10(%r12,%r13,8), %xmm0
movapd %xmm4, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm6
mulsd %xmm3, %xmm6
movl %r14d, %edx
imull %ebp, %edx
leal (%rdx,%rbp), %esi
addl $-0x2, %esi
movslq %esi, %rsi
movsd (%r15,%rsi,8), %xmm2
leal (%rdx,%rbp), %esi
addl $-0x3, %esi
addl %ecx, %edx
movslq %edx, %rdx
movsd (%r15,%rdx,8), %xmm5
movapd %xmm2, %xmm7
subsd %xmm5, %xmm7
mulsd %xmm6, %xmm7
movapd %xmm0, %xmm6
subsd %xmm1, %xmm6
movslq %esi, %rdx
movsd (%r15,%rdx,8), %xmm8
subsd %xmm5, %xmm8
mulsd %xmm6, %xmm3
mulsd %xmm6, %xmm6
mulsd %xmm8, %xmm6
subsd %xmm6, %xmm7
subsd %xmm0, %xmm4
unpcklpd %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
unpcklpd %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
movapd %xmm1, %xmm3
subpd %xmm0, %xmm3
mulpd %xmm1, %xmm0
movsd %xmm3, %xmm0            # xmm0 = xmm3[0],xmm0[1]
movapd 0xdbf06(%rip), %xmm1    # 0xf2770
unpcklpd %xmm7, %xmm1            # xmm1 = xmm1[0],xmm7[0]
divpd %xmm0, %xmm1
subsd %xmm2, %xmm5
divsd %xmm3, %xmm5
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
subsd %xmm5, %xmm0
mulsd %xmm1, %xmm0
movsd 0xdb43e(%rip), %xmm1    # 0xf1cd0
jmp 0x168df
leaq 0xdc58d(%rip), %rbx     # 0xf2e28
leaq 0xdc76d(%rip), %r14     # 0xf300f
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4df, %r8d            # imm = 0x4DF
movl %r9d, %ebp
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 0x169a8
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movsd -0x10(%rax,%r13,8), %xmm2
mulsd %xmm1, %xmm2
movl %r14d, %edx
imull %ebp, %edx
leal (%rdx,%rbp), %esi
addl $-0x2, %esi
movslq %esi, %rsi
mulsd (%rbx,%rsi,8), %xmm1
subsd %xmm2, %xmm0
addsd 0xda956(%rip), %xmm1    # 0xf1260
divsd %xmm1, %xmm0
addl %edx, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rbx,%rcx,8)
cmpl $0x2, %ebp
jl 0x1695a
leal -0x2(%rbp), %ecx
movslq %ecx, %rcx
movslq %edx, %rdx
leaq (%rbx,%rdx,8), %rdx
incq %rcx
incl %r14d
imull %ebp, %r14d
decl %r14d
movsd -0x8(%rdx,%rcx,8), %xmm0
movslq %r14d, %r14
mulsd (%rbx,%r14,8), %xmm0
addsd -0x8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x8(%rdx,%rcx,8)
decl %r14d
decq %rcx
jg 0x16937
movq %rax, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x169b7
leaq 0xdc4bb(%rip), %rbx     # 0xf2e28
leaq 0xdc69b(%rip), %r14     # 0xf300f
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x514, %r8d            # imm = 0x514
movl 0x4(%rsp), %ebp
movl %ebp, %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 %ebp, %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