// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_spline_table_lines
int array_spline_table_lines(
			     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_x*y_size+index_y] */
			     int y_size,
			     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;
  int index_y;
  double dy_first;
  double dy_last;

  u = (double*)malloc((x_size-1) * y_size * sizeof(double));
  p = (double*)malloc(y_size * sizeof(double));
  qn = (double*)malloc(y_size * sizeof(double));
  un = (double*)malloc(y_size * sizeof(double));

  if (u == NULL) {
    class_sprintf(errmsg,"%s(L:%d) Cannot allocate u",__func__,__LINE__);
    return _FAILURE_;
  }
  if (p == NULL) {
    class_sprintf(errmsg,"%s(L:%d) Cannot allocate p",__func__,__LINE__);
    return _FAILURE_;
  }
  if (qn == NULL) {
    class_sprintf(errmsg,"%s(L:%d) Cannot allocate qn",__func__,__LINE__);
    return _FAILURE_;
  }
  if (un == NULL) {
    class_sprintf(errmsg,"%s(L:%d) Cannot allocate un",__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_) {
    for (index_y=0; index_y < y_size; index_y++) {
      ddy_array[index_x*y_size+index_y] = u[index_x*y_size+index_y] = 0.0;
    }
  }
  else {
    if (spline_mode == _SPLINE_EST_DERIV_) {

      for (index_y=0; index_y < y_size; index_y++) {

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

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

	u[index_x*y_size+index_y] =
	  (3./(x[1] -  x[0]))*
	  ((y_array[1*y_size+index_y]-y_array[0*y_size+index_y])/
	   (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]);

    for (index_y=0; index_y < y_size; index_y++) {

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

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

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

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

  }

  if (spline_mode == _SPLINE_NATURAL_) {

    for (index_y=0; index_y < y_size; index_y++) {
      qn[index_y]=un[index_y]=0.0;
    }

  }
  else {
    if (spline_mode == _SPLINE_EST_DERIV_) {

      for (index_y=0; index_y < y_size; index_y++) {

	dy_last =
	  ((x[x_size-3]-x[x_size-1])*(x[x_size-3]-x[x_size-1])*
	   (y_array[(x_size-2)*y_size+index_y]-y_array[(x_size-1)*y_size+index_y])-
	   (x[x_size-2]-x[x_size-1])*(x[x_size-2]-x[x_size-1])*
	   (y_array[(x_size-3)*y_size+index_y]-y_array[(x_size-1)*y_size+index_y]))/
	  ((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[index_y]=0.5;

	un[index_y]=
	  (3./(x[x_size-1] - x[x_size-2]))*
	  (dy_last-(y_array[(x_size-1)*y_size+index_y] - y_array[(x_size-2)*y_size+index_y])/
	   (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;

  for (index_y=0; index_y < y_size; index_y++) {
    ddy_array[index_x*y_size+index_y] =
      (un[index_y] - qn[index_y] * u[(index_x-1)*y_size+index_y]) /
      (qn[index_y] * ddy_array[(index_x-1)*y_size+index_y] + 1.0);
  }

  for (index_x=x_size-2; index_x >= 0; index_x--) {
    for (index_y=0; index_y < y_size; index_y++) {

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

    }
  }

  free(qn);
  free(un);
  free(p);
  free(u);

  return _SUCCESS_;
 }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, %ebp
movq %r8, 0x8(%rsp)
movl %ecx, %ebx
movq %rdx, 0x38(%rsp)
movq %rdi, %r14
movq %rsi, 0x20(%rsp)
leal -0x1(%rsi), %eax
movl %eax, 0x1c(%rsp)
imull %ecx, %eax
cltq
movq %rax, 0x48(%rsp)
leaq (,%rax,8), %rdi
callq 0x8460
movq %rax, %r12
movslq %ebx, %rax
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %r15
movq %r15, %rdi
callq 0x8460
movq %rax, %r13
movq %r15, %rdi
callq 0x8460
testq %r12, %r12
je 0x1432f
testq %r13, %r13
je 0x1436f
testq %rax, %rax
je 0x143af
xorl %ecx, %ecx
movq 0x20(%rsp), %r8
cmpl $0x2, %r8d
cmovel %ecx, %ebp
movl %ebp, %ecx
movswl %cx, %ebp
testw %bp, %bp
je 0x14408
cmpw $0x1, %cx
jne 0x146e4
movl %ecx, 0x18(%rsp)
movl %ebp, 0x14(%rsp)
movq %rax, 0x28(%rsp)
movq %r13, 0x30(%rsp)
testl %ebx, %ebx
movq 0x38(%rsp), %r9
movq 0x8(%rsp), %r13
jle 0x14448
leal (%rbx,%rbx), %edx
movl %ebx, %eax
leaq (%r9,%rax,8), %rcx
leaq (%r9,%rdx,8), %rdx
xorl %esi, %esi
movabsq $-0x4020000000000000, %rdi # imm = 0xBFE0000000000000
movapd 0xde4f0(%rip), %xmm0    # 0xf2770
movsd 0x10(%r14), %xmm3
movsd (%r14), %xmm4
movsd 0x8(%r14), %xmm5
movapd %xmm3, %xmm2
subsd %xmm4, %xmm2
movapd %xmm2, %xmm6
mulsd %xmm2, %xmm6
movsd (%rcx,%rsi,8), %xmm1
movsd (%r9,%rsi,8), %xmm7
subsd %xmm7, %xmm1
mulsd %xmm6, %xmm1
subsd %xmm5, %xmm3
subsd %xmm4, %xmm5
movsd (%rdx,%rsi,8), %xmm4
subsd %xmm7, %xmm4
mulsd %xmm5, %xmm2
mulsd %xmm5, %xmm5
mulsd %xmm4, %xmm5
subsd %xmm5, %xmm1
movq %rdi, (%r13,%rsi,8)
movsd 0x8(%r14), %xmm4
subsd (%r14), %xmm4
mulsd %xmm3, %xmm2
movsd (%rcx,%rsi,8), %xmm3
subsd (%r9,%rsi,8), %xmm3
divsd %xmm2, %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
divpd %xmm4, %xmm2
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
subsd %xmm1, %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, (%r12,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x14280
jmp 0x14448
leaq 0xdead7(%rip), %rbx     # 0xf2e0d
leaq 0xdeb6b(%rip), %r14     # 0xf2ea8
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x246, %r8d            # imm = 0x246
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x90(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x246, %r8d            # imm = 0x246
jmp 0x143ed
leaq 0xdeb66(%rip), %rbx     # 0xf2edc
leaq 0xdeb2b(%rip), %r14     # 0xf2ea8
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x24e, %r8d            # imm = 0x24E
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x90(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x24e, %r8d            # imm = 0x24E
jmp 0x143ed
leaq 0xdeb42(%rip), %rbx     # 0xf2ef8
leaq 0xdeaeb(%rip), %r14     # 0xf2ea8
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x252, %r8d            # imm = 0x252
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x90(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x252, %r8d            # imm = 0x252
xorl %eax, %eax
callq 0x8550
movl $0x1, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, 0x18(%rsp)
movl %ebp, 0x14(%rsp)
movq %rax, 0x28(%rsp)
movq %r13, 0x30(%rsp)
testl %ebx, %ebx
movq 0x8(%rsp), %r13
jle 0x14448
movl %ebx, %ebp
shlq $0x3, %rbp
movq %r12, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x8200
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x8200
movq 0x20(%rsp), %r8
movq %r12, 0x40(%rsp)
cmpl $0x3, %r8d
jl 0x145b2
movl 0x1c(%rsp), %eax
movl %ebx, %ecx
movq 0x50(%rsp), %r8
movq %r8, %rdx
shlq $0x4, %rdx
movq 0x38(%rsp), %r10
addq %r10, %rdx
movq 0x40(%rsp), %r9
leaq (%r9,%r8,8), %rsi
leaq (%r10,%r8,8), %rdi
movq 0x8(%rsp), %r11
leaq (%r11,%r8,8), %r8
shlq $0x3, %rcx
movl $0x1, %r12d
movsd 0xdd34f(%rip), %xmm0    # 0xf17e8
movapd 0xdcd8f(%rip), %xmm1    # 0xf1230
movsd 0xdd857(%rip), %xmm2    # 0xf1d00
movsd 0xde1bf(%rip), %xmm3    # 0xf2670
movq %r12, %r13
incq %r12
testl %ebx, %ebx
jle 0x14594
movsd -0x8(%r14,%r13,8), %xmm5
movsd (%r14,%r13,8), %xmm4
subsd %xmm5, %xmm4
movsd 0x8(%r14,%r13,8), %xmm6
subsd %xmm5, %xmm6
divsd %xmm6, %xmm4
movapd %xmm4, %xmm5
addsd %xmm0, %xmm5
movapd %xmm4, %xmm6
xorpd %xmm1, %xmm6
xorl %ebp, %ebp
movsd (%r11,%rbp), %xmm7
mulsd %xmm4, %xmm7
addsd %xmm2, %xmm7
movapd %xmm5, %xmm8
divsd %xmm7, %xmm8
movsd %xmm8, (%r8,%rbp)
movsd (%rdx,%rbp), %xmm8
movsd (%rdi,%rbp), %xmm9
subsd %xmm9, %xmm8
movsd (%r14,%r12,8), %xmm10
movsd -0x8(%r14,%r13,8), %xmm11
movsd (%r14,%r13,8), %xmm12
movapd %xmm10, %xmm13
subsd %xmm12, %xmm13
divsd %xmm13, %xmm8
subsd (%r10,%rbp), %xmm9
subsd %xmm11, %xmm12
divsd %xmm12, %xmm9
subsd %xmm9, %xmm8
movsd %xmm8, (%rsi,%rbp)
mulsd %xmm3, %xmm8
subsd %xmm11, %xmm10
divsd %xmm10, %xmm8
movsd (%r9,%rbp), %xmm9
mulsd %xmm6, %xmm9
addsd %xmm8, %xmm9
divsd %xmm7, %xmm9
movsd %xmm9, (%rsi,%rbp)
addq $0x8, %rbp
cmpq %rbp, %rcx
jne 0x144f1
addq %r15, %rdx
addq %r15, %rsi
addq %r15, %rdi
addq %r15, %r8
addq %r15, %r11
addq %r15, %r10
addq %r15, %r9
cmpq %rax, %r12
jne 0x144b1
movl 0x18(%rsp), %eax
testw %ax, %ax
je 0x1472a
cmpw $0x1, %ax
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %rbp
jne 0x1486c
testl %ebx, %ebx
jle 0x1475e
movq 0x20(%rsp), %rdx
leal -0x3(%rdx), %eax
movslq 0x1c(%rsp), %rcx
movsd (%r14,%rcx,8), %xmm3
movslq %edx, %rcx
movsd -0x18(%r14,%rcx,8), %xmm0
movsd -0x10(%r14,%rcx,8), %xmm4
movapd %xmm0, %xmm2
subsd %xmm3, %xmm2
movapd %xmm4, %xmm5
subsd %xmm3, %xmm5
movapd 0xdcc14(%rip), %xmm1    # 0xf1230
xorpd %xmm5, %xmm1
mulsd %xmm5, %xmm1
mulsd %xmm2, %xmm5
mulsd %xmm2, %xmm2
leal -0x2(%rdx), %ecx
imull %ebx, %ecx
imull %ebx, %eax
subsd %xmm4, %xmm0
movapd %xmm0, %xmm6
unpcklpd %xmm3, %xmm6            # xmm6 = xmm6[0],xmm3[0]
mulsd %xmm5, %xmm0
unpcklpd %xmm4, %xmm5            # xmm5 = xmm5[0],xmm4[0]
subpd %xmm5, %xmm6
shufpd $0x2, %xmm6, %xmm0      # xmm0 = xmm0[0],xmm6[1]
unpckhpd %xmm6, %xmm6            # xmm6 = xmm6[1,1]
movsd 0xde022(%rip), %xmm3    # 0xf2680
divsd %xmm6, %xmm3
movslq %ecx, %rcx
movslq %eax, %rsi
movl %ebx, %eax
movq 0x38(%rsp), %rdi
leaq (%rdi,%rcx,8), %rcx
movq 0x48(%rsp), %rdx
leaq (%rdi,%rdx,8), %rdx
leaq (%rdi,%rsi,8), %rsi
xorl %edi, %edi
movabsq $0x3fe0000000000000, %r8 # imm = 0x3FE0000000000000
movsd (%rcx,%rdi,8), %xmm4
movsd (%rdx,%rdi,8), %xmm5
movapd %xmm4, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm6
movsd (%rsi,%rdi,8), %xmm7
subsd %xmm5, %xmm7
mulsd %xmm1, %xmm7
addsd %xmm6, %xmm7
movq %r8, (%r12,%rdi,8)
subsd %xmm4, %xmm5
unpcklpd %xmm5, %xmm7            # xmm7 = xmm7[0],xmm5[0]
divpd %xmm0, %xmm7
movapd %xmm7, %xmm4
unpckhpd %xmm7, %xmm4            # xmm4 = xmm4[1],xmm7[1]
subsd %xmm4, %xmm7
mulsd %xmm3, %xmm7
movsd %xmm7, (%r13,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x1468c
jmp 0x1475e
leaq 0xde73d(%rip), %rbx     # 0xf2e28
leaq 0xde7b6(%rip), %r14     # 0xf2ea8
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x275, %r8d            # imm = 0x275
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x90(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x275, %r8d            # imm = 0x275
jmp 0x148b1
testl %ebx, %ebx
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %rbp
jle 0x1475e
movl %ebx, %r14d
shlq $0x3, %r14
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x8200
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x8200
testl %ebx, %ebx
movq 0x40(%rsp), %r14
movq 0x20(%rsp), %r8
jle 0x147d5
leal -0x2(%r8), %eax
imull %ebx, %eax
movslq %eax, %rsi
movl %ebx, %eax
movq 0x48(%rsp), %rcx
leaq (,%rcx,8), %rcx
addq %rbp, %rcx
leaq (%r14,%rsi,8), %rdx
leaq (,%rsi,8), %rsi
addq %rbp, %rsi
xorl %edi, %edi
movsd 0xdcabf(%rip), %xmm0    # 0xf1260
movsd (%r13,%rdi,8), %xmm1
movsd (%r12,%rdi,8), %xmm2
movsd (%rdx,%rdi,8), %xmm3
mulsd %xmm2, %xmm3
subsd %xmm3, %xmm1
mulsd (%rsi,%rdi,8), %xmm2
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, (%rcx,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x147a1
cmpl $0x2, %r8d
jl 0x1484d
movslq %r8d, %rdx
leaq -0x2(%rdx), %rcx
movl %ebx, %eax
decq %rdx
movq 0x50(%rsp), %rdi
imulq %rdi, %rdx
leaq (,%rdx,8), %rdx
addq %rbp, %rdx
negq %r15
imulq %rcx, %rdi
leaq (,%rdi,8), %rsi
addq %rbp, %rsi
leaq (%r14,%rdi,8), %rdi
testl %ebx, %ebx
jle 0x14838
xorl %r8d, %r8d
movsd (%rsi,%r8,8), %xmm0
mulsd (%rdx,%r8,8), %xmm0
addsd (%rdi,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
incq %r8
cmpq %r8, %rax
jne 0x14818
leaq -0x1(%rcx), %r8
addq %r15, %rdx
addq %r15, %rsi
addq %r15, %rdi
testq %rcx, %rcx
movq %r8, %rcx
jg 0x14811
movq %r12, %rdi
callq 0x8410
movq %r13, %rdi
callq 0x8410
movq %r14, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x143f9
leaq 0xde5b5(%rip), %rbx     # 0xf2e28
leaq 0xde62e(%rip), %r14     # 0xf2ea8
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x2af, %r8d            # imm = 0x2AF
movl 0x14(%rsp), %ebp
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x90(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x2af, %r8d            # imm = 0x2AF
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8550
jmp 0x143f4