// File: /workspace/github_c_makefile_star2_O2/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, %r12
movl %esi, %r13d
movq %rdi, %r15
movslq %esi, %rbp
leaq -0x8(,%rbp,8), %rdi
callq 0x8490
testq %rax, %rax
je 0x148e6
movzwl 0x40(%rsp), %edx
xorl %ecx, %ecx
cmpl $0x2, %r13d
cmovel %ecx, %edx
movswl %dx, %r9d
testw %r9w, %r9w
je 0x1492d
cmpw $0x1, %dx
jne 0x14b08
movsd 0x10(%r15), %xmm2
movsd (%r15), %xmm3
movsd 0x8(%r15), %xmm4
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
movapd %xmm0, %xmm5
mulsd %xmm0, %xmm5
imull %r13d, %r14d
movslq %r14d, %rdi
movsd (%r12,%rdi,8), %xmm6
movsd 0x8(%r12,%rdi,8), %xmm1
subsd %xmm6, %xmm1
mulsd %xmm5, %xmm1
subsd %xmm4, %xmm2
subsd %xmm3, %xmm4
movsd 0x10(%r12,%rdi,8), %xmm3
subsd %xmm6, %xmm3
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm4
subsd %xmm4, %xmm1
mulsd %xmm2, %xmm0
movabsq $-0x4020000000000000, %rcx # imm = 0xBFE0000000000000
movq %rcx, (%rbx,%rdi,8)
movsd 0x8(%r15), %xmm2
subsd (%r15), %xmm2
divsd %xmm0, %xmm1
movsd 0x8(%r12,%rdi,8), %xmm0
subsd (%r12,%rdi,8), %xmm0
movapd 0xd1e88(%rip), %xmm3    # 0xe6750
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 0x1493d
leaq 0xd24f0(%rip), %rbx     # 0xe6ddd
leaq 0xd26eb(%rip), %r14     # 0xe6fdf
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4be, %r8d            # imm = 0x4BE
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x48(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4be, %r8d            # imm = 0x4BE
xorl %eax, %eax
callq 0x8580
jmp 0x14c09
imull %r13d, %r14d
movslq %r14d, %rdi
andq $0x0, (%rbx,%rdi,8)
xorpd %xmm0, %xmm0
leaq -0x1(%rbp), %rsi
movsd %xmm0, (%rax)
leaq (%rbx,%rdi,8), %rcx
leaq (%r12,%rdi,8), %rdi
pushq $0x1
popq %r8
movsd 0xd1387(%rip), %xmm1    # 0xe5ce0
movsd 0xd0e87(%rip), %xmm2    # 0xe57e8
movsd 0xd1ce7(%rip), %xmm3    # 0xe6650
cmpq %rsi, %r8
jge 0x14a2a
movupd (%r15,%r8,8), %xmm4
movsd -0x8(%r15,%r8,8), %xmm5
unpcklpd %xmm5, %xmm5            # xmm5 = xmm5[0,0]
subpd %xmm5, %xmm4
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
divsd %xmm5, %xmm4
movsd -0x8(%rcx,%r8,8), %xmm5
mulsd %xmm4, %xmm5
addsd %xmm1, %xmm5
movapd %xmm4, %xmm6
addsd %xmm2, %xmm6
divsd %xmm5, %xmm6
movsd %xmm6, (%rcx,%r8,8)
movsd -0x8(%r15,%r8,8), %xmm6
movupd (%rdi,%r8,8), %xmm7
movupd (%r15,%r8,8), %xmm8
movsd -0x8(%rdi,%r8,8), %xmm9
unpcklpd %xmm7, %xmm9            # xmm9 = xmm9[0],xmm7[0]
subpd %xmm9, %xmm7
movapd %xmm6, %xmm9
unpcklpd %xmm8, %xmm9            # xmm9 = xmm9[0],xmm8[0]
movapd %xmm8, %xmm10
subpd %xmm9, %xmm10
divpd %xmm10, %xmm7
mulsd %xmm0, %xmm4
movapd %xmm7, %xmm0
unpckhpd %xmm7, %xmm0            # xmm0 = xmm0[1],xmm7[1]
subsd %xmm7, %xmm0
mulsd %xmm3, %xmm0
unpckhpd %xmm8, %xmm8            # xmm8 = xmm8[1,1]
subsd %xmm6, %xmm8
divsd %xmm8, %xmm0
subsd %xmm4, %xmm0
divsd %xmm5, %xmm0
movsd %xmm0, (%rax,%r8,8)
incq %r8
jmp 0x14969
testw %dx, %dx
je 0x14b4b
cmpw $0x1, %dx
jne 0x14bc1
movsd (%r15,%rsi,8), %xmm1
movsd -0x18(%r15,%rbp,8), %xmm5
movsd -0x10(%r15,%rbp,8), %xmm0
movapd %xmm5, %xmm4
subsd %xmm1, %xmm4
movapd %xmm4, %xmm7
mulsd %xmm4, %xmm7
addq $-0x2, %rbp
leal (%r14,%r13), %edx
addl $-0x2, %edx
movslq %edx, %rdx
movsd (%r12,%rdx,8), %xmm3
leal (%rsi,%r14), %esi
movslq %esi, %rsi
movsd (%r12,%rsi,8), %xmm2
movapd %xmm3, %xmm6
subsd %xmm2, %xmm6
mulsd %xmm7, %xmm6
movapd %xmm0, %xmm7
subsd %xmm1, %xmm7
leal -0x3(%r13,%r14), %edi
movslq %edi, %rdi
movsd (%r12,%rdi,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 0xd1c72(%rip), %xmm1    # 0xe6750
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 0xd11aa(%rip), %xmm1    # 0xe5cb0
jmp 0x14b6a
leaq 0xd22e9(%rip), %rbx     # 0xe6df8
leaq 0xd24c9(%rip), %r14     # 0xe6fdf
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4df, %r8d            # imm = 0x4DF
movl %r9d, %ebp
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x48(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x4df, %r8d            # imm = 0x4DF
jmp 0x14bff
leal -0x2(%r13), %edx
movslq %edx, %rbp
leal (%r14,%r13), %edx
addl $-0x2, %edx
movslq %edx, %rdx
addl %r14d, %esi
movslq %esi, %rsi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movsd (%rax,%rbp,8), %xmm2
mulsd %xmm1, %xmm2
mulsd (%rbx,%rdx,8), %xmm1
addsd 0xd06e0(%rip), %xmm1    # 0xe5260
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rbx,%rsi,8)
incl %r14d
testq %rbp, %rbp
js 0x14bb5
movsd (%rcx,%rbp,8), %xmm0
leal (%r14,%rbp), %edx
movslq %edx, %rdx
mulsd (%rbx,%rdx,8), %xmm0
addsd (%rax,%rbp,8), %xmm0
movsd %xmm0, (%rcx,%rbp,8)
decq %rbp
jmp 0x14b90
movq %rax, %rdi
callq 0x8430
xorl %eax, %eax
jmp 0x14c0c
leaq 0xd2230(%rip), %rbx     # 0xe6df8
leaq 0xd2410(%rip), %r14     # 0xe6fdf
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x514, %r8d            # imm = 0x514
movl %r9d, %ebp
xorl %eax, %eax
callq 0x8580
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 0x8580
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq