// File: /workspace/github_c_makefile_star2_O2/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 0x16e01
movsd (%rbx), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x16e5d
leal -0x2(%r13), %eax
movsd -0x8(%rbx,%r13,8), %xmm1
subsd %xmm3, %xmm1
subsd %xmm3, %xmm0
divsd %xmm1, %xmm0
movsd 0xce440(%rip), %xmm1    # 0xe5260
subsd %xmm0, %xmm1
imull %esi, %r8d
addl %r8d, %eax
leal (%r8,%r13), %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 0x16eca
ucomisd %xmm1, %xmm0
jbe 0x16f1e
leaq 0xd0285(%rip), %r15     # 0xe710c
leaq 0xd0379(%rip), %r12     # 0xe7207
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 0x8580
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 0x16fa7
ucomisd %xmm0, %xmm1
jbe 0x16f5a
leaq 0xd0204(%rip), %r15     # 0xe70df
leaq 0xd0325(%rip), %r12     # 0xe7207
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 0x8580
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 0x16fa7
xorl %ecx, %ecx
movsd 0xced88(%rip), %xmm2    # 0xe5cb0
movl %eax, %edi
subl %ecx, %edi
cmpl $0x2, %edi
jl 0x16ff0
leal (%rcx,%rax), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movslq %edi, %rdi
movsd (%rbx,%rdi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %edi, %eax
cmoval %ecx, %edi
movl %edi, %ecx
jmp 0x16f28
ucomisd %xmm2, %xmm0
jbe 0x16fbc
leaq 0xd01a5(%rip), %r15     # 0xe710c
leaq 0xd0299(%rip), %r12     # 0xe7207
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 0x8580
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 0x8580
pushq $0x1
popq %rax
jmp 0x16e4f
xorl %ecx, %ecx
movsd 0xcecea(%rip), %xmm2    # 0xe5cb0
movl %eax, %edi
subl %ecx, %edi
cmpl $0x2, %edi
jl 0x16ff0
leal (%rcx,%rax), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movslq %edi, %rdi
ucomisd (%rbx,%rdi,8), %xmm0
cmoval %edi, %eax
cmoval %ecx, %edi
movl %edi, %ecx
jmp 0x16fc6
cltq
movsd (%rbx,%rax,8), %xmm4
movslq %ecx, %rcx
movsd (%rbx,%rcx,8), %xmm1
subsd %xmm1, %xmm4
subsd %xmm1, %xmm0
divsd %xmm4, %xmm0
movsd 0xce24d(%rip), %xmm2    # 0xe5260
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 0xcf5d4(%rip), %xmm1    # 0xe6650
addsd %xmm3, %xmm1
jmp 0x16e44