// File: /workspace/github_c_makefile_star2_O2/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
movq %rcx, %r14
movl %edx, %r12d
movq %rdi, %rbx
movslq %edx, %rbp
decl %r12d
leaq -0x1(%rbp), %rcx
movsd -0x8(%rdi,%rbp,8), %xmm2
ucomisd %xmm2, %xmm0
movsd %xmm0, 0x8(%rsp)
jbe 0x171c9
movapd %xmm2, %xmm0
movl %esi, %r13d
movq %rcx, 0x18(%rsp)
callq 0x82e0
movsd %xmm0, 0x10(%rsp)
movsd -0x10(%rbx,%rbp,8), %xmm0
callq 0x82e0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x82e0
movsd -0x10(%rbx,%rbp,8), %xmm0
callq 0x82e0
imull %r13d, %r15d
addl %r15d, %r12d
movslq %r12d, %r12
movsd (%r14,%r12,8), %xmm0
callq 0x82e0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x82e0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rax
movsd (%rbx,%rax,8), %xmm0
callq 0x82e0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd (%r14,%r12,8), %xmm0
callq 0x82e0
movsd %xmm0, 0x18(%rsp)
leal (%r15,%rbp), %eax
addl $-0x2, %eax
movslq %eax, %rbx
movsd (%r14,%rbx,8), %xmm0
callq 0x82e0
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm0, %xmm1
movapd %xmm1, %xmm2
divsd 0xcf4b8(%rip), %xmm0    # 0xe6650
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 0x17473
movapd %xmm0, %xmm3
movq 0x70(%rsp), %r13
movsd (%rbx), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x1722c
ucomisd %xmm3, %xmm1
jbe 0x17285
leaq 0xcfef2(%rip), %r14     # 0xe70df
leaq 0xd0043(%rip), %r15     # 0xe7237
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x92b, %r8d            # imm = 0x92B
movapd %xmm3, %xmm0
movb $0x2, %al
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r13, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x92b, %r8d            # imm = 0x92B
jmp 0x1730e
ucomisd %xmm3, %xmm2
jbe 0x172c7
leaq 0xcfea2(%rip), %r14     # 0xe70df
leaq 0xcfff3(%rip), %r15     # 0xe7237
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %rcx, %r12
movq %r15, %rcx
movl $0x941, %r8d            # imm = 0x941
movapd %xmm3, %xmm0
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r12,8), %xmm1
movq %r13, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x941, %r8d            # imm = 0x941
jmp 0x1730e
xorl %r13d, %r13d
movsd 0xcea20(%rip), %xmm0    # 0xe5cb0
movl %r12d, %eax
subl %r13d, %eax
cmpl $0x2, %eax
jl 0x1735d
leal (%r12,%r13), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cltq
movsd (%rbx,%rax,8), %xmm1
ucomisd %xmm3, %xmm1
cmoval %eax, %r12d
cmoval %r13d, %eax
movl %eax, %r13d
jmp 0x17290
ucomisd %xmm1, %xmm3
jbe 0x17323
leaq 0xcfe38(%rip), %r14     # 0xe710c
leaq 0xcff5c(%rip), %r15     # 0xe7237
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x946, %r8d            # imm = 0x946
movapd %xmm3, %xmm0
movb $0x2, %al
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r13, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x946, %r8d            # imm = 0x946
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8580
pushq $0x1
popq %rax
jmp 0x17483
xorl %r13d, %r13d
movsd 0xce982(%rip), %xmm0    # 0xe5cb0
movl %r12d, %eax
subl %r13d, %eax
cmpl $0x2, %eax
jl 0x1735d
leal (%r12,%r13), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cltq
ucomisd (%rbx,%rax,8), %xmm3
cmoval %eax, %r12d
cmoval %r13d, %eax
movl %eax, %r13d
jmp 0x1732e
movl %esi, %ebp
movslq %r12d, %r12
movsd (%rbx,%r12,8), %xmm0
callq 0x82e0
movsd %xmm0, 0x10(%rsp)
movslq %r13d, %r13
movsd (%rbx,%r13,8), %xmm0
callq 0x82e0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x82e0
movsd %xmm0, 0x8(%rsp)
movsd (%rbx,%r13,8), %xmm0
callq 0x82e0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
divsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0xcde95(%rip), %xmm0    # 0xe5260
subsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
imull %ebp, %r15d
addl %r15d, %r13d
movslq %r13d, %rbx
movsd (%r14,%rbx,8), %xmm0
callq 0x82e0
movsd %xmm0, 0x18(%rsp)
addl %r15d, %r12d
movslq %r12d, %r15
movsd (%r14,%r15,8), %xmm0
callq 0x82e0
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,%r15,8), %xmm1
mulsd (%rbp,%rbx,8), %xmm0
addsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
divsd 0xcf1e1(%rip), %xmm0    # 0xe6650
addsd %xmm2, %xmm0
movq 0x68(%rsp), %rbx
callq 0x86a0
movsd %xmm0, (%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq