// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_extrapolate_spline_one_column
int array_interpolate_extrapolate_spline_one_column(
						    double * x_array,
						    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 */
						    double x,   /* input */
						    double * y, /* output */
						    ErrorMsg errmsg
						    ) {


  int inf,sup,mid;
  double h,a,b;

  if (x > x_array[x_size-2] || x < x_array[0]) {

    /*interpolate/extrapolate linearly y as a function of x*/

    h = x_array[x_size-1] - x_array[x_size-2];
    b = (x-x_array[x_size-2])/h;
    a = 1-b;

    *y = a * y_array[index_y * x_size + (x_size-2)] +
	     b * y_array[index_y * x_size + (x_size-1)];


  }

  else {

    /*interpolate y as a function of x with a spline*/

    inf=0;
    sup=x_size-1;

    if (x_array[inf] < x_array[sup]){

      if (x < x_array[inf]) {
	class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,x,x_array[inf]);
	return _FAILURE_;
      }

      if (x > x_array[sup]) {
	class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,x,x_array[sup]);
	return _FAILURE_;
      }

      while (sup-inf > 1) {

	mid=(int)(0.5*(inf+sup));
	if (x < x_array[mid]) {sup=mid;}
	else {inf=mid;}

      }

    }

    else {

      if (x < x_array[sup]) {
	class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,x,x_array[sup]);
	return _FAILURE_;
      }

      if (x > x_array[inf]) {
	class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,x,x_array[inf]);
	return _FAILURE_;
      }

      while (sup-inf > 1) {

	mid=(int)(0.5*(inf+sup));
	if (x > x_array[mid]) {sup=mid;}
	else {inf=mid;}

      }

    }

    h = x_array[sup] - x_array[inf];
    b = (x-x_array[inf])/h;
    a = 1-b;

    *y =
      a * y_array[index_y * x_size + inf] +
      b * y_array[index_y * x_size + sup] +
      ((a*a*a-a)* ddy_array[index_y * x_size + inf] +
       (b*b*b-b)* ddy_array[index_y * x_size + sup])*h*h/6.;

  }

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movslq %esi, %r13
movsd -0x10(%rdi,%r13,8), %xmm3
ucomisd %xmm3, %xmm0
ja 0x18d4c
movsd (%rbx), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x18da8
leal -0x2(%r13), %eax
movsd -0x8(%rbx,%r13,8), %xmm1
subsd %xmm3, %xmm1
subsd %xmm3, %xmm0
divsd %xmm1, %xmm0
movsd 0xd84f5(%rip), %xmm1    # 0xf1260
subsd %xmm0, %xmm1
imull %esi, %r8d
addl %r8d, %eax
leal (%rsi,%r8), %ecx
decl %ecx
movslq %ecx, %rcx
mulsd (%rdx,%rcx,8), %xmm0
cltq
mulsd (%rdx,%rax,8), %xmm1
addsd %xmm0, %xmm1
movq 0x40(%rsp), %rax
movsd %xmm1, (%rax)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x48(%rsp), %r14
leal -0x1(%r13), %eax
movsd -0x8(%rbx,%r13,8), %xmm1
decq %r13
ucomisd %xmm2, %xmm1
jbe 0x18e15
ucomisd %xmm1, %xmm0
jbe 0x18e69
leaq 0xda36a(%rip), %r15     # 0xf313c
leaq 0xda45e(%rip), %r12     # 0xf3237
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x8c4, %r8d            # imm = 0x8C4
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x8c4, %r8d            # imm = 0x8C4
jmp 0x18f00
ucomisd %xmm0, %xmm1
jbe 0x18eb3
leaq 0xda2e9(%rip), %r15     # 0xf310f
leaq 0xda40a(%rip), %r12     # 0xf3237
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x8d5, %r8d            # imm = 0x8D5
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x8d5, %r8d            # imm = 0x8D5
jmp 0x18f00
cmpl $0x3, %esi
jl 0x18f56
xorl %edi, %edi
movsd 0xd8e54(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
movsd (%rbx,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %eax
cmoval %edi, %ecx
movl %eax, %r10d
subl %ecx, %r10d
movl %ecx, %edi
cmpl $0x1, %r10d
jg 0x18e7c
jmp 0x18f58
ucomisd %xmm2, %xmm0
jbe 0x18f17
leaq 0xda27c(%rip), %r15     # 0xf313c
leaq 0xda370(%rip), %r12     # 0xf3237
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x8da, %r8d            # imm = 0x8DA
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x8da, %r8d            # imm = 0x8DA
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
jmp 0x18d9a
cmpl $0x3, %esi
jl 0x18f56
xorl %edi, %edi
movsd 0xd8daa(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
ucomisd (%rbx,%rcx,8), %xmm0
cmoval %ecx, %eax
cmoval %edi, %ecx
movl %eax, %r10d
subl %ecx, %r10d
movl %ecx, %edi
cmpl $0x1, %r10d
jg 0x18f26
jmp 0x18f58
xorl %ecx, %ecx
cltq
movsd (%rbx,%rax,8), %xmm4
movslq %ecx, %rcx
movsd (%rbx,%rcx,8), %xmm1
subsd %xmm1, %xmm4
subsd %xmm1, %xmm0
divsd %xmm4, %xmm0
movsd 0xd82e5(%rip), %xmm2    # 0xf1260
subsd %xmm0, %xmm2
imull %esi, %r8d
addl %r8d, %ecx
movslq %ecx, %rcx
addl %r8d, %eax
cltq
movsd (%rdx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd (%rdx,%rcx,8), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm1, %xmm3
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
subsd %xmm2, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
subsd %xmm0, %xmm2
mulsd (%r9,%rax,8), %xmm2
mulsd (%r9,%rcx,8), %xmm1
addsd %xmm2, %xmm1
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm1
divsd 0xd968c(%rip), %xmm1    # 0xf2670
addsd %xmm3, %xmm1
jmp 0x18d8f