// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_spline_table_columns
int array_spline_table_columns(
		       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,
		       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_y*x_size+index_x] = 0.0;
      u[index_x*y_size+index_y] = 0.0;
    }
  }
  else {
    if (spline_mode == _SPLINE_EST_DERIV_) {

      class_test(x[2]-x[0]==0.,
		 errmsg,
		 "x[2]=%g, x[0]=%g, stop to avoid seg fault",x[2],x[0]);
      class_test(x[1]-x[0]==0.,
		 errmsg,
		 "x[1]=%g, x[0]=%g, stop to avoid seg fault",x[1],x[0]);
      class_test(x[2]-x[1]==0.,
		 errmsg,
		 "x[2]=%g, x[1]=%g, stop to avoid seg fault",x[2],x[1]);

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

	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*y_size+index_y] =
	  (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]);

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

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

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

      u[index_x*y_size+index_y] =
	(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*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[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[index_y]=0.5;

	un[index_y]=
	  (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;

  for (index_y=0; index_y < y_size; index_y++) {
    ddy_array[index_y*x_size+index_x] =
      (un[index_y] - qn[index_y] * u[(index_x-1)*y_size+index_y]) /
      (qn[index_y] * ddy_array[index_y*x_size+(index_x-1)] + 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_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*y_size+index_y];

    }
  }

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

  return _SUCCESS_;
 }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1048, %rsp           # imm = 0x1048
movl %r9d, %r13d
movq %r8, 0x10(%rsp)
movl %ecx, %ebx
movq %rdx, %r12
movq %rdi, %rbp
movq %rsi, 0x30(%rsp)
leal -0x1(%rsi), %eax
movl %eax, 0x28(%rsp)
imull %ecx, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x8490
movq %rax, %r14
movl %ebx, 0xc(%rsp)
movslq %ebx, %rax
movq %rax, 0x38(%rsp)
leaq (,%rax,8), %r15
movq %r15, %rdi
callq 0x8490
movq %rax, %rbx
movq %r15, %rdi
callq 0x8490
testq %r14, %r14
je 0x13aff
testq %rbx, %rbx
je 0x13b3f
testq %rax, %rax
je 0x13b7f
xorl %edx, %edx
movq 0x30(%rsp), %rsi
cmpl $0x2, %esi
cmovel %edx, %r13d
movswl %r13w, %r9d
testw %r9w, %r9w
je 0x13bd9
cmpw $0x1, %r13w
jne 0x13c16
movsd (%rbp), %xmm1
movsd 0x10(%rbp), %xmm0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm2
jne 0x13c5c
jp 0x13c5c
leaq 0xd346e(%rip), %rsi     # 0xe6f1b
leaq 0x840(%rsp), %rbx
movq %rbx, %rdi
movb $0x2, %al
callq 0x2e014
leaq 0xd15bc(%rip), %rsi     # 0xe5082
leaq 0xd3478(%rip), %rdx     # 0xe6f45
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xd154e(%rip), %rsi     # 0xe5034
leaq 0xd3413(%rip), %rdx     # 0xe6f00
movq 0x1080(%rsp), %rdi
movl $0x3a8, %ecx            # imm = 0x3A8
jmp 0x13d37
leaq 0xd32d7(%rip), %rbx     # 0xe6ddd
leaq 0xd33f3(%rip), %r14     # 0xe6f00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x389, %r8d            # imm = 0x389
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x1080(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x389, %r8d            # imm = 0x389
jmp 0x13bbd
leaq 0xd3366(%rip), %rbx     # 0xe6eac
leaq 0xd33b3(%rip), %r14     # 0xe6f00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x391, %r8d            # imm = 0x391
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x1080(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x391, %r8d            # imm = 0x391
jmp 0x13bbd
leaq 0xd3342(%rip), %rbx     # 0xe6ec8
leaq 0xd3373(%rip), %r14     # 0xe6f00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x395, %r8d            # imm = 0x395
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x1080(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x395, %r8d            # imm = 0x395
xorl %eax, %eax
callq 0x8580
pushq $0x1
popq %rax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, 0x8(%rsp)
movslq %esi, %r13
movl 0xc(%rsp), %esi
testl %esi, %esi
movl $0x0, %ecx
cmovgl %esi, %ecx
leaq (,%r13,8), %rsi
movq 0x10(%rsp), %rdi
cmpq %rdx, %rcx
je 0x13e29
andq $0x0, (%rdi)
andq $0x0, (%r14,%rdx,8)
incq %rdx
addq %rsi, %rdi
jmp 0x13bfc
leaq 0xd31db(%rip), %rbx     # 0xe6df8
leaq 0xd32dc(%rip), %r14     # 0xe6f00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x3c3, %r8d            # imm = 0x3C3
movl %r9d, %ebp
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x1080(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x3c3, %r8d            # imm = 0x3C3
jmp 0x1410c
movsd 0x8(%rbp), %xmm2
movapd %xmm2, %xmm4
subsd %xmm1, %xmm4
ucomisd %xmm3, %xmm4
jne 0x13ccb
jp 0x13ccb
leaq 0xd32db(%rip), %rsi     # 0xe6f53
leaq 0x840(%rsp), %rbx
movq %rbx, %rdi
movapd %xmm2, %xmm0
movb $0x2, %al
callq 0x2e014
leaq 0xd13ed(%rip), %rsi     # 0xe5082
leaq 0xd32e1(%rip), %rdx     # 0xe6f7d
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xd137f(%rip), %rsi     # 0xe5034
leaq 0xd3244(%rip), %rdx     # 0xe6f00
movq 0x1080(%rsp), %rdi
movl $0x3ab, %ecx            # imm = 0x3AB
jmp 0x13d37
movapd %xmm0, %xmm3
subsd %xmm2, %xmm3
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm3
jne 0x13d46
jp 0x13d46
leaq 0xd32a5(%rip), %rsi     # 0xe6f8b
leaq 0x840(%rsp), %rbx
movq %rbx, %rdi
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x2e014
leaq 0xd137f(%rip), %rsi     # 0xe5082
leaq 0xd32ab(%rip), %rdx     # 0xe6fb5
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xd1311(%rip), %rsi     # 0xe5034
leaq 0xd31d6(%rip), %rdx     # 0xe6f00
movq 0x1080(%rsp), %rdi
movl $0x3ae, %ecx            # imm = 0x3AE
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
jmp 0x13bc4
movl %r13d, 0x8(%rsp)
xorl %edx, %edx
movl 0xc(%rsp), %edi
testl %edi, %edi
movl $0x0, %ecx
cmovgl %edi, %ecx
movslq %esi, %r13
movabsq $-0x4020000000000000, %rsi # imm = 0xBFE0000000000000
movapd 0xd29e0(%rip), %xmm0    # 0xe6750
xorl %edi, %edi
movq 0x10(%rsp), %r8
cmpq %rdi, %rcx
je 0x13e29
movsd 0x10(%rbp), %xmm4
movapd %xmm4, %xmm5
subsd %xmm1, %xmm5
movapd %xmm5, %xmm6
mulsd %xmm5, %xmm6
movsd (%r12,%rdx,8), %xmm7
movsd 0x8(%r12,%rdx,8), %xmm3
subsd %xmm7, %xmm3
mulsd %xmm6, %xmm3
subsd %xmm2, %xmm4
subsd %xmm1, %xmm2
movsd 0x10(%r12,%rdx,8), %xmm1
subsd %xmm7, %xmm1
mulsd %xmm2, %xmm5
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm2, %xmm3
mulsd %xmm4, %xmm5
divsd %xmm5, %xmm3
movq %rsi, (%r8,%rdx,8)
movsd (%rbp), %xmm1
movsd 0x8(%rbp), %xmm2
movapd %xmm2, %xmm4
movsd 0x8(%r12,%rdx,8), %xmm5
subsd (%r12,%rdx,8), %xmm5
subsd %xmm1, %xmm4
movapd %xmm0, %xmm6
unpcklpd %xmm5, %xmm6            # xmm6 = xmm6[0],xmm5[0]
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
divpd %xmm4, %xmm6
movapd %xmm6, %xmm4
unpckhpd %xmm6, %xmm4            # xmm4 = xmm4[1],xmm6[1]
subsd %xmm3, %xmm4
mulsd %xmm6, %xmm4
movsd %xmm4, (%r14,%rdi,8)
incq %rdi
addq %r13, %rdx
jmp 0x13d77
movl %r9d, 0x1c(%rsp)
movq %rbx, 0x20(%rsp)
movslq 0x28(%rsp), %rdx
movl %ecx, %ebx
leaq 0x10(%r12), %rsi
movq 0x10(%rsp), %rcx
leaq 0x8(%rcx), %rdi
pushq $0x1
popq %r9
movsd 0xd1994(%rip), %xmm0    # 0xe57e8
movapd 0xd13d4(%rip), %xmm1    # 0xe5230
movsd 0xd1e7c(%rip), %xmm2    # 0xe5ce0
movsd 0xd27e4(%rip), %xmm3    # 0xe6650
movq %r14, 0x28(%rsp)
cmpq %rdx, %r9
jge 0x13f7b
movsd -0x8(%rbp,%r9,8), %xmm5
movsd (%rbp,%r9,8), %xmm4
subsd %xmm5, %xmm4
leaq 0x1(%r9), %r10
movsd 0x8(%rbp,%r9,8), %xmm6
subsd %xmm5, %xmm6
divsd %xmm6, %xmm4
movapd %xmm4, %xmm5
addsd %xmm0, %xmm5
movapd %xmm4, %xmm6
xorpd %xmm1, %xmm6
xorl %r11d, %r11d
movq %rbx, %rcx
movq %r14, %r8
subq $0x1, %rcx
jb 0x13f68
movsd -0x8(%rdi,%r11,8), %xmm7
mulsd %xmm4, %xmm7
addsd %xmm2, %xmm7
movapd %xmm5, %xmm8
divsd %xmm7, %xmm8
movsd %xmm8, (%rdi,%r11,8)
movsd -0x8(%rsi,%r11,8), %xmm8
movsd (%rsi,%r11,8), %xmm9
subsd %xmm8, %xmm9
movsd (%rbp,%r10,8), %xmm10
movsd -0x8(%rbp,%r9,8), %xmm11
movsd (%rbp,%r9,8), %xmm12
movapd %xmm10, %xmm13
subsd %xmm12, %xmm13
divsd %xmm13, %xmm9
subsd -0x10(%rsi,%r11,8), %xmm8
subsd %xmm11, %xmm12
divsd %xmm12, %xmm8
subsd %xmm8, %xmm9
movsd %xmm9, (%r8,%r15)
mulsd %xmm3, %xmm9
subsd %xmm11, %xmm10
divsd %xmm10, %xmm9
movsd (%r8), %xmm8
mulsd %xmm6, %xmm8
addsd %xmm9, %xmm8
divsd %xmm7, %xmm8
movsd %xmm8, (%r8,%r15)
addq $0x8, %r8
addq %r13, %r11
jmp 0x13eb8
addq %r15, %r14
addq $0x8, %rsi
addq $0x8, %rdi
movq %r10, %r9
jmp 0x13e71
movl 0x8(%rsp), %ecx
testw %cx, %cx
je 0x1409a
cmpw $0x1, %cx
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %rdi
jne 0x140c7
leal -0x3(%rdi), %ecx
movslq %ecx, %r8
leal -0x2(%rdi), %ecx
movl %ecx, 0x8(%rsp)
movslq %ecx, %rsi
leaq (,%r13,8), %r9
movslq %edi, %r10
xorl %r11d, %r11d
movabsq $0x3fe0000000000000, %rdi # imm = 0x3FE0000000000000
movapd 0xd2784(%rip), %xmm0    # 0xe6750
movq 0x20(%rsp), %rcx
cmpq %r11, %rbx
je 0x1411b
movsd (%rbp,%r8,8), %xmm4
movsd (%rbp,%rdx,8), %xmm3
movapd %xmm4, %xmm5
subsd %xmm3, %xmm5
movapd %xmm5, %xmm6
mulsd %xmm5, %xmm6
movsd (%r12,%rsi,8), %xmm2
movsd -0x8(%r12,%r10,8), %xmm1
movapd %xmm2, %xmm7
subsd %xmm1, %xmm7
mulsd %xmm6, %xmm7
movsd (%rbp,%rsi,8), %xmm6
movapd %xmm6, %xmm8
subsd %xmm3, %xmm8
movsd (%r12,%r8,8), %xmm9
subsd %xmm1, %xmm9
mulsd %xmm8, %xmm5
mulsd %xmm8, %xmm8
mulsd %xmm9, %xmm8
subsd %xmm8, %xmm7
movapd %xmm0, %xmm8
unpcklpd %xmm7, %xmm8            # xmm8 = xmm8[0],xmm7[0]
subsd %xmm6, %xmm4
movq %rdi, (%rcx,%r11,8)
unpcklpd %xmm4, %xmm3            # xmm3 = xmm3[0],xmm4[0]
unpcklpd %xmm5, %xmm6            # xmm6 = xmm6[0],xmm5[0]
movapd %xmm3, %xmm4
subpd %xmm6, %xmm4
mulpd %xmm3, %xmm6
movsd %xmm4, %xmm6            # xmm6 = xmm4[0],xmm6[1]
divpd %xmm6, %xmm8
subsd %xmm2, %xmm1
divsd %xmm4, %xmm1
movapd %xmm8, %xmm2
unpckhpd %xmm8, %xmm2            # xmm2 = xmm2[1],xmm8[1]
subsd %xmm1, %xmm2
mulsd %xmm8, %xmm2
movsd %xmm2, (%rax,%r11,8)
incq %r11
addq %r9, %r12
jmp 0x13fd1
xorl %ecx, %ecx
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rdx
cmpq %rcx, %rbx
je 0x140bf
andq $0x0, (%rax,%rcx,8)
andq $0x0, (%rdi,%rcx,8)
incq %rcx
jmp 0x140ab
leal -0x2(%rdx), %ecx
movslq %ecx, %rsi
jmp 0x14129
leaq 0xd2d2a(%rip), %rbx     # 0xe6df8
leaq 0xd2e2b(%rip), %r14     # 0xe6f00
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x3fc, %r8d            # imm = 0x3FC
movl 0x1c(%rsp), %ebp
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x1080(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x3fc, %r8d            # imm = 0x3FC
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8580
jmp 0x13bc4
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rdx
movl 0x8(%rsp), %ecx
imull 0xc(%rsp), %ecx
movslq %ecx, %rcx
leaq (%r14,%rcx,8), %rcx
movslq %edx, %rdx
shlq $0x3, %r13
xorl %r9d, %r9d
movsd 0xd1119(%rip), %xmm0    # 0xe5260
movq 0x10(%rsp), %r8
cmpq %r9, %rbx
je 0x14188
movsd (%rax,%r9,8), %xmm1
movsd (%rdi,%r9,8), %xmm2
movsd (%rcx,%r9,8), %xmm3
mulsd %xmm2, %xmm3
subsd %xmm3, %xmm1
mulsd (%r8,%rsi,8), %xmm2
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, -0x8(%r8,%rdx,8)
incq %r9
addq %r13, %r8
jmp 0x1414c
movq 0x38(%rsp), %rcx
imulq %rsi, %rcx
leaq (%r14,%rcx,8), %rcx
negq %r15
movq 0x10(%rsp), %rdx
leaq (%rdx,%rsi,8), %rdx
testq %rsi, %rsi
js 0x141db
movq %rdx, %r9
xorl %r8d, %r8d
cmpq %r8, %rbx
je 0x141cf
movsd (%r9), %xmm0
mulsd 0x8(%r9), %xmm0
addsd (%rcx,%r8,8), %xmm0
movsd %xmm0, (%r9)
incq %r8
addq %r13, %r9
jmp 0x141ac
decq %rsi
addq %r15, %rcx
addq $-0x8, %rdx
jmp 0x141a1
movq %rax, %rbx
callq 0x8430
movq %r14, %rdi
callq 0x8430
movq %rbx, %rdi
callq 0x8430
xorl %eax, %eax
jmp 0x13bc7