// File: /workspace/github_c_makefile_star2_O1/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
movapd %xmm0, %xmm3
movl %r8d, %ebp
movq %rdx, %r15
movq %rdi, %rbx
movq 0x80(%rsp), %rax
leal -0x1(%rsi), %r13d
movslq %esi, %r12
movsd (%rdi), %xmm1
movsd -0x8(%rdi,%r12,8), %xmm2
decq %r12
ucomisd %xmm1, %xmm2
movsd %xmm0, (%rsp)
jbe 0x18746
ucomisd %xmm3, %xmm1
jbe 0x1879f
leaq 0xdaa0b(%rip), %r14     # 0xf310f
leaq 0xdaaec(%rip), %r15     # 0xf31f7
movq %rax, %r12
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x806, %r8d            # imm = 0x806
movapd %xmm3, %xmm0
movb $0x2, %al
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x806, %r8d            # imm = 0x806
jmp 0x18843
ucomisd %xmm3, %xmm2
jbe 0x187f5
leaq 0xda9b8(%rip), %r14     # 0xf310f
leaq 0xdaa99(%rip), %r15     # 0xf31f7
movq %rax, %r13
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x81c, %r8d            # imm = 0x81C
movapd %xmm3, %xmm0
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r12,8), %xmm1
movq %r13, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x81c, %r8d            # imm = 0x81C
jmp 0x18843
ucomisd %xmm2, %xmm3
jbe 0x18859
leaq 0xda98c(%rip), %r14     # 0xf313c
leaq 0xdaa40(%rip), %r15     # 0xf31f7
movq %rax, %r13
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x80b, %r8d            # imm = 0x80B
movapd %xmm3, %xmm0
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r12,8), %xmm1
movq %r13, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x80b, %r8d            # imm = 0x80B
jmp 0x18843
ucomisd %xmm1, %xmm3
jbe 0x188a9
leaq 0xda936(%rip), %r14     # 0xf313c
leaq 0xda9ea(%rip), %r15     # 0xf31f7
movq %rax, %r12
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x821, %r8d            # imm = 0x821
movapd %xmm3, %xmm0
movb $0x2, %al
callq 0x8550
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 0x8550
movl $0x1, %eax
jmp 0x18a54
cmpl $0x3, %esi
movq %rcx, 0x20(%rsp)
jl 0x188f1
xorl %eax, %eax
movsd 0xd945f(%rip), %xmm0    # 0xf1cd0
leal (%rax,%r13), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %r12
movsd (%rbx,%r12,8), %xmm1
ucomisd %xmm3, %xmm1
cmoval %r12d, %r13d
cmoval %eax, %r12d
movl %r13d, %ecx
subl %r12d, %ecx
movl %r12d, %eax
cmpl $0x1, %ecx
jg 0x18871
jmp 0x188f4
movq %rcx, 0x20(%rsp)
cmpl $0x3, %esi
jl 0x188f1
xorl %eax, %eax
movsd 0xd9413(%rip), %xmm0    # 0xf1cd0
leal (%rax,%r13), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
movslq %ecx, %r12
ucomisd (%rbx,%r12,8), %xmm3
cmoval %r12d, %r13d
cmoval %eax, %r12d
movl %r13d, %ecx
subl %r12d, %ecx
movl %r12d, %eax
cmpl $0x1, %ecx
jg 0x188bd
jmp 0x188f4
xorl %r12d, %r12d
movl %r12d, (%r9)
movslq %r13d, %rax
movsd (%rbx,%rax,8), %xmm0
callq 0x82c0
movsd %xmm0, 0x18(%rsp)
movslq %r12d, %r14
movsd (%rbx,%r14,8), %xmm0
callq 0x82c0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x82c0
movsd %xmm0, 0x10(%rsp)
movsd (%rbx,%r14,8), %xmm0
callq 0x82c0
movl 0x78(%rsp), %edx
testl %edx, %edx
jle 0x18a52
movsd 0x18(%rsp), %xmm1
subsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
movsd %xmm1, 0x18(%rsp)
divsd %xmm1, %xmm2
movsd 0xd88f3(%rip), %xmm0    # 0xf1260
subsd %xmm2, %xmm0
imull %ebp, %r12d
imull %ebp, %r13d
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm0, 0x8(%rsp)
subsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm2, 0x10(%rsp)
subsd %xmm2, %xmm0
movsd %xmm0, 0x28(%rsp)
movslq %r12d, %rax
movslq %r13d, %rcx
movl %edx, %r12d
leaq (%r15,%rcx,8), %r13
movq 0x20(%rsp), %rdx
leaq (%rdx,%rcx,8), %rbp
leaq (%r15,%rax,8), %r15
leaq (%rdx,%rax,8), %rbx
xorl %r14d, %r14d
movsd (%r15,%r14,8), %xmm0
callq 0x82c0
movsd %xmm0, (%rsp)
movsd (%r13,%r14,8), %xmm0
callq 0x82c0
mulsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd 0x8(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd (%rbp,%r14,8), %xmm1
mulsd 0x28(%rsp), %xmm1
movsd (%rbx,%r14,8), %xmm2
mulsd 0x30(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0x18(%rsp), %xmm1
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd 0xd9c3a(%rip), %xmm2    # 0xf2670
addsd %xmm2, %xmm0
callq 0x8670
movq 0x70(%rsp), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0x189d2
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq