// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movl %ecx, %r15d
movq %rdx, 0x40(%rsp)
movl %esi, %r14d
movq %rdi, %r13
leal -0x1(%r14), %eax
movl %eax, 0x2c(%rsp)
imull %ecx, %eax
cltq
movq %rax, 0x48(%rsp)
leaq (,%rax,8), %rdi
callq 0x8460
movq %rax, %rbx
movq %r15, 0x8(%rsp)
movslq %r15d, %rax
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %r15
movq %r15, %rdi
callq 0x8460
movq %rax, %r12
movq %r15, %rdi
callq 0x8460
testq %rbx, %rbx
je 0x14456
testq %r12, %r12
je 0x14496
testq %rax, %rax
je 0x144d6
xorl %ecx, %ecx
cmpl $0x2, %r14d
cmovel %ecx, %ebp
movl %ebp, %ecx
movswl %cx, %ebp
testw %bp, %bp
je 0x1452f
cmpw $0x1, %cx
jne 0x14827
movl %ecx, 0x28(%rsp)
movl %ebp, 0x24(%rsp)
movq %rax, 0x30(%rsp)
movq %r12, 0x38(%rsp)
cmpl $0x0, 0x8(%rsp)
movq 0x40(%rsp), %r8
movq 0x18(%rsp), %r12
jle 0x1456f
movq 0x8(%rsp), %rax
leal (%rax,%rax), %edx
movl %eax, %eax
movsd (%r13), %xmm2
movsd 0x8(%r13), %xmm1
leaq (%r8,%rax,8), %rcx
leaq (%r8,%rdx,8), %rdx
xorl %esi, %esi
movabsq $-0x4020000000000000, %rdi # imm = 0xBFE0000000000000
movapd 0xdb3d5(%rip), %xmm0    # 0xef780
movsd 0x10(%r13), %xmm4
movapd %xmm4, %xmm5
subsd %xmm2, %xmm5
movapd %xmm5, %xmm6
mulsd %xmm5, %xmm6
movsd (%rcx,%rsi,8), %xmm3
movsd (%r8,%rsi,8), %xmm7
subsd %xmm7, %xmm3
mulsd %xmm6, %xmm3
subsd %xmm1, %xmm4
subsd %xmm2, %xmm1
movsd (%rdx,%rsi,8), %xmm2
subsd %xmm7, %xmm2
mulsd %xmm1, %xmm5
mulsd %xmm1, %xmm1
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm3
mulsd %xmm4, %xmm5
divsd %xmm5, %xmm3
movq %rdi, (%r12,%rsi,8)
movsd (%r13), %xmm2
movsd 0x8(%r13), %xmm1
movapd %xmm1, %xmm4
movsd (%rcx,%rsi,8), %xmm5
subsd (%r8,%rsi,8), %xmm5
subsd %xmm2, %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, (%rbx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x143ab
jmp 0x1456f
leaq 0xdb9c0(%rip), %rbx     # 0xefe1d
leaq 0xdba54(%rip), %r14     # 0xefeb8
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 0x14514
leaq 0xdba4f(%rip), %rbx     # 0xefeec
leaq 0xdba14(%rip), %r14     # 0xefeb8
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 0x14514
leaq 0xdba2b(%rip), %rbx     # 0xeff08
leaq 0xdb9d4(%rip), %r14     # 0xefeb8
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, 0x28(%rsp)
movl %ebp, 0x24(%rsp)
movq %rax, 0x30(%rsp)
movq %r12, 0x38(%rsp)
cmpl $0x0, 0x8(%rsp)
movq 0x18(%rsp), %r12
jle 0x1456f
movl 0x8(%rsp), %ebp
shlq $0x3, %rbp
movq %rbx, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x8200
movq %r12, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x8200
movq %rbx, 0x10(%rsp)
cmpl $0x3, %r14d
jl 0x146e9
movl 0x2c(%rsp), %eax
movsd 0x8(%r13), %xmm4
movl 0x8(%rsp), %ecx
movq 0x50(%rsp), %r8
movq %r8, %rdx
shlq $0x4, %rdx
movq 0x40(%rsp), %r10
addq %r10, %rdx
movq 0x10(%rsp), %r9
leaq (%r9,%r8,8), %rsi
leaq (%r10,%r8,8), %rdi
movq 0x18(%rsp), %r11
leaq (%r11,%r8,8), %r8
shlq $0x3, %rcx
movl $0x1, %ebx
movsd 0xda221(%rip), %xmm0    # 0xee7e8
movapd 0xd9c61(%rip), %xmm1    # 0xee230
movsd 0xda729(%rip), %xmm2    # 0xeed00
movsd 0xdb091(%rip), %xmm3    # 0xef670
movq %rbx, %r12
incq %rbx
movsd 0x8(%r13,%r12,8), %xmm5
cmpl $0x0, 0x8(%rsp)
jle 0x146c7
movsd -0x8(%r13,%r12,8), %xmm6
subsd %xmm6, %xmm4
subsd %xmm6, %xmm5
divsd %xmm5, %xmm4
movapd %xmm4, %xmm6
addsd %xmm0, %xmm6
movapd %xmm4, %xmm7
xorpd %xmm1, %xmm7
xorl %ebp, %ebp
movsd (%r11,%rbp), %xmm8
mulsd %xmm4, %xmm8
addsd %xmm2, %xmm8
movapd %xmm6, %xmm5
divsd %xmm8, %xmm5
movsd %xmm5, (%r8,%rbp)
movsd (%rdx,%rbp), %xmm9
movsd (%rdi,%rbp), %xmm10
subsd %xmm10, %xmm9
movsd (%r13,%rbx,8), %xmm5
movsd -0x8(%r13,%r12,8), %xmm11
movsd (%r13,%r12,8), %xmm12
movapd %xmm5, %xmm13
subsd %xmm12, %xmm13
subsd (%r10,%rbp), %xmm10
divsd %xmm13, %xmm9
subsd %xmm11, %xmm12
divsd %xmm12, %xmm10
subsd %xmm10, %xmm9
movsd %xmm9, (%rsi,%rbp)
mulsd %xmm3, %xmm9
movapd %xmm5, %xmm10
subsd %xmm11, %xmm10
divsd %xmm10, %xmm9
movsd (%r9,%rbp), %xmm10
mulsd %xmm7, %xmm10
addsd %xmm9, %xmm10
divsd %xmm8, %xmm10
movsd %xmm10, (%rsi,%rbp)
addq $0x8, %rbp
cmpq %rbp, %rcx
jne 0x1461c
addq %r15, %rdx
addq %r15, %rsi
addq %r15, %rdi
addq %r15, %r8
addq %r15, %r11
addq %r15, %r10
addq %r15, %r9
movapd %xmm5, %xmm4
cmpq %rax, %rbx
jne 0x145df
movl 0x28(%rsp), %eax
testw %ax, %ax
je 0x1486d
cmpw $0x1, %ax
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %rbp
jne 0x14910
movq 0x8(%rsp), %r9
testl %r9d, %r9d
jle 0x1496d
leal -0x3(%r14), %eax
movslq 0x2c(%rsp), %rcx
movsd (%r13,%rcx,8), %xmm3
movslq %r14d, %rcx
movsd -0x18(%r13,%rcx,8), %xmm0
movsd -0x10(%r13,%rcx,8), %xmm4
movapd %xmm0, %xmm2
subsd %xmm3, %xmm2
movapd %xmm4, %xmm5
subsd %xmm3, %xmm5
movapd 0xd9adf(%rip), %xmm1    # 0xee230
xorpd %xmm5, %xmm1
mulsd %xmm5, %xmm1
mulsd %xmm2, %xmm5
mulsd %xmm2, %xmm2
leal -0x2(%r14), %ecx
imull %r9d, %ecx
imull %r9d, %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 0xdaeea(%rip), %xmm3    # 0xef680
divsd %xmm6, %xmm3
movslq %ecx, %rcx
movslq %eax, %rsi
movl %r9d, %eax
movq 0x40(%rsp), %rdi
leaq (%rdi,%rcx,8), %rcx
movq 0x48(%rsp), %r10
leaq (%rdi,%r10,8), %rdx
leaq (%rdi,%rsi,8), %rsi
xorl %edi, %edi
movabsq $0x3fe0000000000000, %r8 # imm = 0x3FE0000000000000
movq 0x10(%rsp), %rbx
movq %r9, %r13
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, (%rbp,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x147cd
jmp 0x148b0
leaq 0xdb60a(%rip), %rbx     # 0xefe38
leaq 0xdb683(%rip), %r14     # 0xefeb8
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 0x14955
movq 0x8(%rsp), %r13
testl %r13d, %r13d
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %rbp
jle 0x14964
movl %r13d, %ebx
shlq $0x3, %rbx
movq %rbp, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x8200
movq %r12, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x8200
movq 0x10(%rsp), %rbx
movq 0x48(%rsp), %r10
leal -0x2(%r14), %eax
imull %r13d, %eax
movslq %eax, %rsi
movl %r13d, %eax
movq 0x18(%rsp), %rdi
leaq (%rdi,%r10,8), %rcx
leaq (%rbx,%rsi,8), %rdx
leaq (%rdi,%rsi,8), %rsi
xorl %edi, %edi
movsd 0xd9987(%rip), %xmm0    # 0xee260
movsd (%rbp,%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 0x148d9
movb $0x1, %al
jmp 0x14977
leaq 0xdb521(%rip), %rbx     # 0xefe38
leaq 0xdb59a(%rip), %r14     # 0xefeb8
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x2af, %r8d            # imm = 0x2AF
movl 0x24(%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 0x1451b
xorl %eax, %eax
movq 0x10(%rsp), %rbx
jmp 0x14977
xorl %eax, %eax
movq 0x10(%rsp), %rbx
movq %r9, %r13
cmpl $0x2, %r14d
jl 0x149e5
addl $-0x2, %r14d
movl %r13d, %ecx
leaq 0x1(%r14), %rdx
movq 0x50(%rsp), %rdi
imulq %rdi, %rdx
movq 0x18(%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
negq %r15
imulq %r14, %rdi
leaq (%rsi,%rdi,8), %rsi
leaq (%rbx,%rdi,8), %rdi
testb %al, %al
je 0x149d0
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, %rcx
jne 0x149b0
leaq -0x1(%r14), %r8
addq %r15, %rdx
addq %r15, %rsi
addq %r15, %rdi
testq %r14, %r14
movq %r8, %r14
jg 0x149a9
movq %r12, %rdi
callq 0x8410
movq %rbp, %rdi
callq 0x8410
movq %rbx, %rdi
callq 0x8410
xorl %eax, %eax
jmp 0x14520