// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_extrapolate_logspline_loglinear_one_column
int array_interpolate_extrapolate_logspline_loglinear_one_column(
								 double * x_array,
								 int x_size,
								 int x_stop,
								 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 * ddlogy_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_stop-1]) {

    /*interpolate/extrapolate linearly ln(y) as a function of ln(x)*/

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

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

    *y = exp(log(y_array[index_y * x_size + (x_stop-1)])
	     +(log(x)-log(x_array[x_stop-1]))
	     *((log(y_array[index_y * x_size + (x_stop-1)])-log(y_array[index_y * x_size + (x_stop-2)]))/h
	       +h/6.*(ddlogy_array[index_y * x_size + (x_stop-2)]+2.*ddlogy_array[index_y * x_size + (x_stop-1)])));


  }

  else {

    /*interpolate ln(y) as a function of ln(x) with a spline*/

    inf=0;
    sup=x_stop-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 = log(x_array[sup]) - log(x_array[inf]);
    b = (log(x)-log(x_array[inf]))/h;
    a = 1-b;

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

  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r15d
movl %edx, %r13d
movq %rdi, %rbx
leal -0x1(%r13), %r12d
movslq %edx, %r14
leaq -0x1(%r14), %rdx
movsd -0x8(%rdi,%r14,8), %xmm2
ucomisd %xmm2, %xmm0
movsd %xmm0, 0x8(%rsp)
jbe 0x1913a
movapd %xmm2, %xmm0
movq %rcx, %rbp
movl %esi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
callq 0x82c0
movsd %xmm0, 0x10(%rsp)
movsd -0x10(%rbx,%r14,8), %xmm0
callq 0x82c0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x82c0
movsd -0x10(%rbx,%r14,8), %xmm0
callq 0x82c0
imull 0x20(%rsp), %r15d
addl %r15d, %r12d
movslq %r12d, %r12
movsd (%rbp,%r12,8), %xmm0
callq 0x82c0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x82c0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rax
movsd (%rbx,%rax,8), %xmm0
callq 0x82c0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd (%rbp,%r12,8), %xmm0
callq 0x82c0
movsd %xmm0, 0x18(%rsp)
leal (%r15,%r13), %eax
addl $-0x2, %eax
movslq %eax, %rbx
movsd (%rbp,%rbx,8), %xmm0
callq 0x82c0
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, %xmm2
divsd 0xd9567(%rip), %xmm0    # 0xf2670
movapd %xmm0, %xmm1
movq 0x60(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
addsd %xmm0, %xmm0
addsd (%rax,%rbx,8), %xmm0
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
mulsd 0x8(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
jmp 0x1940e
movapd %xmm0, %xmm3
movq 0x70(%rsp), %rbp
movsd (%rbx), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x1919d
ucomisd %xmm3, %xmm1
jbe 0x191f6
leaq 0xd9fb1(%rip), %r14     # 0xf310f
leaq 0xda102(%rip), %r15     # 0xf3267
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x92b, %r8d            # imm = 0x92B
movapd %xmm3, %xmm0
movb $0x2, %al
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %rbp, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x92b, %r8d            # imm = 0x92B
jmp 0x19291
ucomisd %xmm3, %xmm2
jbe 0x1924a
leaq 0xd9f61(%rip), %r14     # 0xf310f
leaq 0xda0b2(%rip), %r15     # 0xf3267
xorl %edi, %edi
xorl %esi, %esi
movq %rdx, %r12
movq %r14, %rdx
movq %r15, %rcx
movl $0x941, %r8d            # imm = 0x941
movapd %xmm3, %xmm0
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r12,8), %xmm1
movq %rbp, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x941, %r8d            # imm = 0x941
jmp 0x19291
movl %esi, %ebp
movq %rcx, %r14
cmpl $0x3, %r13d
jl 0x192f1
xorl %eax, %eax
movsd 0xd8ac1(%rip), %xmm0    # 0xf1cd0
leal (%rax,%r12), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %r13
movsd (%rbx,%r13,8), %xmm1
ucomisd %xmm3, %xmm1
cmoval %r13d, %r12d
cmoval %eax, %r13d
movl %r12d, %ecx
subl %r13d, %ecx
movl %r13d, %eax
cmpl $0x1, %ecx
jg 0x1920f
jmp 0x192f4
ucomisd %xmm1, %xmm3
jbe 0x192a8
leaq 0xd9ee5(%rip), %r14     # 0xf313c
leaq 0xda009(%rip), %r15     # 0xf3267
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x946, %r8d            # imm = 0x946
movapd %xmm3, %xmm0
movb $0x2, %al
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %rbp, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x946, %r8d            # imm = 0x946
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
jmp 0x1941e
movl %esi, %ebp
movq %rcx, %r14
cmpl $0x3, %r13d
jl 0x192f1
xorl %eax, %eax
movsd 0xd8a13(%rip), %xmm0    # 0xf1cd0
leal (%rax,%r12), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %r13
ucomisd (%rbx,%r13,8), %xmm3
cmoval %r13d, %r12d
cmoval %eax, %r13d
movl %r12d, %ecx
subl %r13d, %ecx
movl %r13d, %eax
cmpl $0x1, %ecx
jg 0x192bd
jmp 0x192f4
xorl %r13d, %r13d
movslq %r12d, %r12
movsd (%rbx,%r12,8), %xmm0
callq 0x82c0
movsd %xmm0, 0x10(%rsp)
movslq %r13d, %r13
movsd (%rbx,%r13,8), %xmm0
callq 0x82c0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x82c0
movsd %xmm0, 0x8(%rsp)
movsd (%rbx,%r13,8), %xmm0
callq 0x82c0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
divsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0xd7f00(%rip), %xmm0    # 0xf1260
subsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
imull %ebp, %r15d
addl %r15d, %r13d
movslq %r13d, %rbx
movq %r15, %r13
movq %r14, %r15
movsd (%r14,%rbx,8), %xmm0
callq 0x82c0
movsd %xmm0, 0x18(%rsp)
addl %r13d, %r12d
movslq %r12d, %r14
movsd (%r15,%r14,8), %xmm0
callq 0x82c0
movsd 0x8(%rsp), %xmm3
mulsd %xmm3, %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm4
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm2
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
subsd %xmm4, %xmm0
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
subsd %xmm3, %xmm1
movq 0x60(%rsp), %rbp
mulsd (%rbp,%r14,8), %xmm1
mulsd (%rbp,%rbx,8), %xmm0
addsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd 0xd9266(%rip), %xmm0    # 0xf2670
addsd %xmm2, %xmm0
movq 0x68(%rsp), %rbx
callq 0x8670
movsd %xmm0, (%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq