// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movq %r8, %r12
movl %ecx, %r14d
movq %rdx, 0x28(%rsp)
movq %rdi, %rbp
movq 0x90(%rsp), %r13
movq %rsi, 0x38(%rsp)
leal -0x1(%rsi), %eax
movl %eax, 0x10(%rsp)
imull %ecx, %eax
cltq
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %rdi
callq 0x8490
movq %rax, %rbx
movl %r14d, 0x4(%rsp)
movslq %r14d, %rax
movq %rax, 0x30(%rsp)
leaq (,%rax,8), %r14
movq %r14, %rdi
callq 0x8490
movq %rax, %r15
movq %r14, %rdi
callq 0x8490
testq %rbx, %rbx
je 0x1274c
testq %r15, %r15
je 0x12787
testq %rax, %rax
je 0x127c2
movq %r15, %r10
xorl %ecx, %ecx
cmpl $0x2, 0x38(%rsp)
movl 0x8(%rsp), %r15d
cmovel %ecx, %r15d
movswl %r15w, %r9d
testw %r9w, %r9w
je 0x12814
cmpw $0x1, %r15w
movq 0x28(%rsp), %r11
jne 0x12b08
movl %r15d, 0x8(%rsp)
movq 0x30(%rsp), %rdx
leal (%rdx,%rdx), %ecx
movslq %ecx, %rsi
xorl %ecx, %ecx
testl %edx, %edx
movl $0x0, %r8d
cmovgl 0x4(%rsp), %r8d
leaq (%r11,%rdx,8), %rdx
leaq (%r11,%rsi,8), %rsi
movabsq $-0x4020000000000000, %rdi # imm = 0xBFE0000000000000
movapd 0xd40ae(%rip), %xmm0    # 0xe6750
cmpq %rcx, %r8
je 0x12842
movsd 0x10(%rbp), %xmm2
movsd (%rbp), %xmm3
movsd 0x8(%rbp), %xmm4
movapd %xmm2, %xmm5
subsd %xmm3, %xmm5
movapd %xmm5, %xmm6
mulsd %xmm5, %xmm6
movsd (%rdx,%rcx,8), %xmm1
movsd (%r11,%rcx,8), %xmm7
subsd %xmm7, %xmm1
mulsd %xmm6, %xmm1
subsd %xmm4, %xmm2
subsd %xmm3, %xmm4
movsd (%rsi,%rcx,8), %xmm3
subsd %xmm7, %xmm3
mulsd %xmm4, %xmm5
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm4
subsd %xmm4, %xmm1
mulsd %xmm2, %xmm5
divsd %xmm5, %xmm1
movq %rdi, (%r12,%rcx,8)
movsd 0x8(%rbp), %xmm2
subsd (%rbp), %xmm2
movsd (%rdx,%rcx,8), %xmm3
subsd (%r11,%rcx,8), %xmm3
movapd %xmm0, %xmm4
unpcklpd %xmm3, %xmm4            # xmm4 = xmm4[0],xmm3[0]
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm4
movapd %xmm4, %xmm2
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
subsd %xmm1, %xmm2
mulsd %xmm4, %xmm2
movsd %xmm2, (%rbx,%rcx,8)
incq %rcx
jmp 0x126a2
leaq 0xd468a(%rip), %rbx     # 0xe6ddd
leaq 0xd471e(%rip), %r14     # 0xe6e78
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x246, %r8d            # imm = 0x246
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x246, %r8d            # imm = 0x246
jmp 0x127fb
leaq 0xd471e(%rip), %rbx     # 0xe6eac
leaq 0xd46e3(%rip), %r14     # 0xe6e78
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x24e, %r8d            # imm = 0x24E
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x24e, %r8d            # imm = 0x24E
jmp 0x127fb
leaq 0xd46ff(%rip), %rbx     # 0xe6ec8
leaq 0xd46a8(%rip), %r14     # 0xe6e78
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x252, %r8d            # imm = 0x252
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x252, %r8d            # imm = 0x252
xorl %eax, %eax
callq 0x8580
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, 0x8(%rsp)
movl 0x4(%rsp), %edx
testl %edx, %edx
movl $0x0, %r8d
cmovgl %edx, %r8d
movq 0x28(%rsp), %r11
cmpq %rcx, %r8
je 0x12842
andq $0x0, (%rbx,%rcx,8)
andq $0x0, (%r12,%rcx,8)
incq %rcx
jmp 0x1282e
movl %r9d, 0xc(%rsp)
movq %rax, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movslq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
movl %r8d, %eax
movq 0x30(%rsp), %r9
movq %r9, %rdx
shlq $0x4, %rdx
addq %r11, %rdx
leaq (,%rax,8), %rsi
leaq (%r12,%r9,8), %rdi
leaq (%r11,%r9,8), %r8
leaq (%rbx,%r9,8), %r9
movq %r12, %r15
pushq $0x1
popq %r12
movsd 0xd2f58(%rip), %xmm0    # 0xe57e8
movapd 0xd2998(%rip), %xmm1    # 0xe5230
movsd 0xd3440(%rip), %xmm2    # 0xe5ce0
movsd 0xd3da8(%rip), %xmm3    # 0xe6650
movq %rbx, 0x40(%rsp)
movq %rbx, %r10
movq %r15, 0x48(%rsp)
movq %r15, %rbx
cmpq 0x10(%rsp), %r12
jge 0x129c9
movq %r13, %rcx
movsd -0x8(%rbp,%r12,8), %xmm5
movsd (%rbp,%r12,8), %xmm4
subsd %xmm5, %xmm4
leaq 0x1(%r12), %r15
movsd 0x8(%rbp,%r12,8), %xmm6
subsd %xmm5, %xmm6
divsd %xmm6, %xmm4
movapd %xmm4, %xmm5
addsd %xmm0, %xmm5
movapd %xmm4, %xmm6
xorpd %xmm1, %xmm6
xorl %r13d, %r13d
cmpq %r13, %rsi
je 0x129a9
movsd (%rbx,%r13), %xmm7
mulsd %xmm4, %xmm7
addsd %xmm2, %xmm7
movapd %xmm5, %xmm8
divsd %xmm7, %xmm8
movsd %xmm8, (%rdi,%r13)
movsd (%rdx,%r13), %xmm8
movsd (%r8,%r13), %xmm9
subsd %xmm9, %xmm8
movsd (%rbp,%r15,8), %xmm10
movsd -0x8(%rbp,%r12,8), %xmm11
movsd (%rbp,%r12,8), %xmm12
movapd %xmm10, %xmm13
subsd %xmm12, %xmm13
divsd %xmm13, %xmm8
subsd (%r11,%r13), %xmm9
subsd %xmm11, %xmm12
divsd %xmm12, %xmm9
subsd %xmm9, %xmm8
movsd %xmm8, (%r9,%r13)
mulsd %xmm3, %xmm8
subsd %xmm11, %xmm10
divsd %xmm10, %xmm8
movsd (%r10,%r13), %xmm9
mulsd %xmm6, %xmm9
addsd %xmm8, %xmm9
divsd %xmm7, %xmm9
movsd %xmm9, (%r9,%r13)
addq $0x8, %r13
jmp 0x128ff
addq %r14, %rdx
addq %r14, %rbx
addq %r14, %r11
addq %r14, %r10
addq %r14, %rdi
addq %r14, %r8
addq %r14, %r9
movq %r15, %r12
movq %rcx, %r13
jmp 0x128b8
movl 0x8(%rsp), %ecx
testw %cx, %cx
je 0x12b46
cmpw $0x1, %cx
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r12
jne 0x12b82
movq 0x38(%rsp), %r8
leal -0x3(%r8), %edx
movslq %edx, %rsi
addl $-0x2, %r8d
movl %r8d, %edx
movl 0x4(%rsp), %ecx
imull %ecx, %edx
movq %r8, %r13
movslq %r8d, %r15
imull %esi, %ecx
movslq %ecx, %r10
movslq %edx, %rdx
movq 0x28(%rsp), %rcx
leaq (%rcx,%rdx,8), %r8
movq 0x50(%rsp), %r9
leaq (%rcx,%r9,8), %r9
leaq (%rcx,%r10,8), %r10
xorl %r11d, %r11d
movabsq $0x3fe0000000000000, %rbx # imm = 0x3FE0000000000000
movapd 0xd3d12(%rip), %xmm0    # 0xe6750
movq 0x10(%rsp), %rcx
cmpq %r11, %rax
je 0x12bd1
movsd (%rbp,%rsi,8), %xmm4
movsd (%rbp,%rcx,8), %xmm3
movapd %xmm4, %xmm5
subsd %xmm3, %xmm5
movapd %xmm5, %xmm6
mulsd %xmm5, %xmm6
movsd (%r8,%r11,8), %xmm2
movsd (%r9,%r11,8), %xmm1
movapd %xmm2, %xmm7
subsd %xmm1, %xmm7
mulsd %xmm6, %xmm7
movsd (%rbp,%r15,8), %xmm6
movapd %xmm6, %xmm8
subsd %xmm3, %xmm8
movsd (%r10,%r11,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 %rbx, (%rdi,%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, (%r12,%r11,8)
incq %r11
jmp 0x12a43
leaq 0xd42e9(%rip), %rbx     # 0xe6df8
leaq 0xd4362(%rip), %r14     # 0xe6e78
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x275, %r8d            # imm = 0x275
movl %r9d, %ebp
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x275, %r8d            # imm = 0x275
jmp 0x12bc2
xorl %ecx, %ecx
movq 0x40(%rsp), %rbx
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r12
cmpq %rcx, %rax
je 0x12b6b
andq $0x0, (%r12,%rcx,8)
andq $0x0, (%rdi,%rcx,8)
incq %rcx
jmp 0x12b57
movq 0x38(%rsp), %rcx
addl $-0x2, %ecx
movq %rcx, %r13
movl 0x4(%rsp), %edx
imull %ecx, %edx
movslq %edx, %rdx
jmp 0x12bd6
leaq 0xd426f(%rip), %rbx     # 0xe6df8
leaq 0xd42e8(%rip), %r14     # 0xe6e78
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x2af, %r8d            # imm = 0x2AF
movl 0xc(%rsp), %ebp
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x2af, %r8d            # imm = 0x2AF
movl %ebp, %r9d
xorl %eax, %eax
callq 0x8580
jmp 0x12802
movq 0x40(%rsp), %rbx
movq 0x48(%rsp), %r8
movq 0x50(%rsp), %rcx
leaq (%r8,%rcx,8), %rcx
leaq (%rbx,%rdx,8), %rsi
leaq (%r8,%rdx,8), %rdx
xorl %r8d, %r8d
movsd 0xd2669(%rip), %xmm0    # 0xe5260
cmpq %r8, %rax
je 0x12c2f
movsd (%r12,%r8,8), %xmm1
movsd (%rdi,%r8,8), %xmm2
movsd (%rsi,%r8,8), %xmm3
mulsd %xmm2, %xmm3
subsd %xmm3, %xmm1
mulsd (%rdx,%r8,8), %xmm2
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, (%rcx,%r8,8)
incq %r8
jmp 0x12bf7
movslq %r13d, %rcx
leaq 0x1(%rcx), %rdx
movq 0x30(%rsp), %r8
imulq %r8, %rdx
movq 0x48(%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
negq %r14
imulq %rcx, %r8
leaq (%rsi,%r8,8), %rsi
leaq (%rbx,%r8,8), %r9
testq %rcx, %rcx
js 0x12c8f
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x12c81
movsd (%rsi,%r8,8), %xmm0
mulsd (%rdx,%r8,8), %xmm0
addsd (%r9,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
incq %r8
jmp 0x12c5f
decq %rcx
addq %r14, %rdx
addq %r14, %rsi
addq %r14, %r9
jmp 0x12c57
callq 0x8430
movq %r12, %rdi
callq 0x8430
movq %rbx, %rdi
callq 0x8430
xorl %eax, %eax
jmp 0x12805