// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_logspline(double*, int, double*, double*, int, double, int*, double*, int, char*)
int array_interpolate_logspline(
							 double * x_array,
							 int n_lines,
							 double * array,
							 double * array_logsplined,
							 int n_columns,
							 double x,
							 int * last_index,
							 double * result,
							 int result_size, /** from 1 to n_columns */
							 ErrorMsg errmsg) {

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

	inf=0;
	sup=n_lines-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;}

		}

	}

	*last_index = inf;

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

	for (i=0; i<result_size; i++)
		*(result+i) = exp(
		a * log(array[inf*n_columns+i]) +
		b * log(array[sup*n_columns+i]) +
		((a*a*a-a)* array_logsplined[inf*n_columns+i] +
		 (b*b*b-b)* array_logsplined[sup*n_columns+i])*h*h/6.);

	return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebp
movq %rdi, %rbx
movq 0x80(%rsp), %r12
movslq %esi, %r13
decl %esi
movsd (%rdi), %xmm1
movsd -0x8(%rdi,%r13,8), %xmm2
decq %r13
ucomisd %xmm1, %xmm2
movsd %xmm0, (%rsp)
jbe 0x16835
ucomisd %xmm0, %xmm1
jbe 0x16887
leaq 0xd08e5(%rip), %r14     # 0xe70df
leaq 0xd09c6(%rip), %r15     # 0xe71c7
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x806, %r8d            # imm = 0x806
movb $0x2, %al
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x806, %r8d            # imm = 0x806
jmp 0x1691d
ucomisd %xmm0, %xmm2
jbe 0x168d6
leaq 0xd0899(%rip), %r14     # 0xe70df
leaq 0xd097a(%rip), %r15     # 0xe71c7
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x81c, %r8d            # imm = 0x81C
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x81c, %r8d            # imm = 0x81C
jmp 0x1691d
ucomisd %xmm2, %xmm0
jbe 0x16931
leaq 0xd0874(%rip), %r14     # 0xe710c
leaq 0xd0928(%rip), %r15     # 0xe71c7
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x80b, %r8d            # imm = 0x80B
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x80b, %r8d            # imm = 0x80B
jmp 0x1691d
ucomisd %xmm1, %xmm0
jbe 0x1696d
leaq 0xd0825(%rip), %r14     # 0xe710c
leaq 0xd08d9(%rip), %r15     # 0xe71c7
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x821, %r8d            # imm = 0x821
movb $0x2, %al
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x821, %r8d            # imm = 0x821
movsd (%rsp), %xmm0
movb $0x2, %al
callq 0x8580
pushq $0x1
popq %rax
jmp 0x16b23
xorl %r14d, %r14d
movsd 0xcf374(%rip), %xmm2    # 0xe5cb0
movl %esi, %eax
subl %r14d, %eax
cmpl $0x2, %eax
jl 0x169a5
leal (%r14,%rsi), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
cltq
movsd (%rbx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %eax, %esi
cmoval %r14d, %eax
movl %eax, %r14d
jmp 0x1693c
xorl %r14d, %r14d
movsd 0xcf338(%rip), %xmm2    # 0xe5cb0
movl %esi, %eax
subl %r14d, %eax
cmpl $0x2, %eax
jl 0x169a5
leal (%r14,%rsi), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
cltq
ucomisd (%rbx,%rax,8), %xmm0
cmoval %eax, %esi
cmoval %r14d, %eax
movl %eax, %r14d
jmp 0x16978
movq %rdx, %r13
movq %rcx, 0x18(%rsp)
movl 0x78(%rsp), %r12d
movl %r14d, (%r9)
movslq %esi, %r15
movsd (%rbx,%r15,8), %xmm0
callq 0x82e0
movsd %xmm0, 0x8(%rsp)
movslq %r14d, %r14
movsd (%rbx,%r14,8), %xmm0
callq 0x82e0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x82e0
movsd %xmm0, 0x10(%rsp)
movsd (%rbx,%r14,8), %xmm0
callq 0x82e0
movsd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
divsd 0x8(%rsp), %xmm2
movsd 0xce846(%rip), %xmm0    # 0xe5260
subsd %xmm2, %xmm0
imull %ebp, %r14d
imull %ebp, %r15d
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm0, 0x30(%rsp)
subsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm2, 0x10(%rsp)
subsd %xmm2, %xmm0
movsd %xmm0, 0x20(%rsp)
movslq %r15d, %rax
movslq %r14d, %rcx
xorl %edx, %edx
testl %r12d, %r12d
cmovlel %edx, %r12d
movq %r13, %rdx
leaq (,%rcx,8), %r14
addq %r13, %r14
movq 0x18(%rsp), %r13
leaq (,%rcx,8), %rbp
addq %r13, %rbp
leaq (%rdx,%rax,8), %r15
leaq (,%rax,8), %rbx
addq %r13, %rbx
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x16b21
movsd (%r14,%r13,8), %xmm0
callq 0x82e0
movsd %xmm0, (%rsp)
movsd (%r15,%r13,8), %xmm0
callq 0x82e0
mulsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd 0x30(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd (%rbx,%r13,8), %xmm1
mulsd 0x20(%rsp), %xmm1
movsd (%rbp,%r13,8), %xmm2
mulsd 0x28(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0x8(%rsp), %xmm1
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd 0xcfb4b(%rip), %xmm2    # 0xe6650
addsd %xmm2, %xmm0
callq 0x86a0
movq 0x70(%rsp), %rax
movsd %xmm0, (%rax,%r13,8)
incq %r13
jmp 0x16a9d
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq