// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_spline
int array_interpolate_spline(
                             double * __restrict__ x_array,
                             int n_lines,
                             double * __restrict__ array,
                             double * __restrict__ array_splined,
                             int n_columns,
                             double x,
                             int * __restrict__ last_index,
                             double * __restrict__ 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 = x_array[sup] - x_array[inf];
  b = (x-x_array[inf])/h;
  a = 1-b;

  for (i=0; i<result_size; i++)
    *(result+i) =
      a * *(array+inf*n_columns+i) +
      b * *(array+sup*n_columns+i) +
      ((a*a*a-a)* *(array_splined+inf*n_columns+i) +
       (b*b*b-b)* *(array_splined+sup*n_columns+i))*h*h/6.;

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq 0x40(%rsp), %rbx
leal -0x1(%rsi), %eax
movsd (%rdi), %xmm2
movslq %esi, %r10
movsd -0x8(%rdi,%r10,8), %xmm1
ucomisd %xmm2, %xmm1
jbe 0x17f62
ucomisd %xmm0, %xmm2
jbe 0x17fb5
leaq 0xdb1f3(%rip), %r14     # 0xf310f
leaq 0xdb258(%rip), %r15     # 0xf317b
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x720, %r8d            # imm = 0x720
movapd %xmm2, %xmm1
movsd %xmm2, (%rsp)
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x720, %r8d            # imm = 0x720
jmp 0x18057
ucomisd %xmm0, %xmm1
jbe 0x18005
leaq 0xdb19c(%rip), %r14     # 0xf310f
leaq 0xdb201(%rip), %r15     # 0xf317b
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x736, %r8d            # imm = 0x736
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x736, %r8d            # imm = 0x736
jmp 0x18057
ucomisd %xmm1, %xmm0
jbe 0x18078
leaq 0xdb176(%rip), %r14     # 0xf313c
leaq 0xdb1ae(%rip), %r15     # 0xf317b
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x725, %r8d            # imm = 0x725
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x725, %r8d            # imm = 0x725
jmp 0x18057
ucomisd %xmm2, %xmm0
jbe 0x180c6
leaq 0xdb126(%rip), %r14     # 0xf313c
leaq 0xdb15e(%rip), %r15     # 0xf317b
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x73b, %r8d            # imm = 0x73B
movapd %xmm2, %xmm1
movsd %xmm2, (%rsp)
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x73b, %r8d            # imm = 0x73B
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
cmpl $0x3, %esi
jl 0x1810c
xorl %esi, %esi
movsd 0xd9c45(%rip), %xmm2    # 0xf1cd0
leal (%rsi,%rax), %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r10d
movslq %r10d, %r10
movsd (%rdi,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %r10d, %eax
cmoval %esi, %r10d
movl %eax, %r11d
subl %r10d, %r11d
movl %r10d, %esi
cmpl $0x1, %r11d
jg 0x1808b
jmp 0x1810f
cmpl $0x3, %esi
jl 0x1810c
xorl %esi, %esi
movsd 0xd9bfb(%rip), %xmm2    # 0xf1cd0
leal (%rsi,%rax), %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r10d
movslq %r10d, %r10
ucomisd (%rdi,%r10,8), %xmm0
cmoval %r10d, %eax
cmoval %esi, %r10d
movl %eax, %r11d
subl %r10d, %r11d
movl %r10d, %esi
cmpl $0x1, %r11d
jg 0x180d5
jmp 0x1810f
xorl %r10d, %r10d
movl 0x38(%rsp), %r11d
movl %r10d, (%r9)
testl %r11d, %r11d
jle 0x181f2
movq 0x30(%rsp), %rsi
cltq
movsd (%rdi,%rax,8), %xmm8
movslq %r10d, %r9
movsd (%rdi,%r9,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xd9114(%rip), %xmm1    # 0xf1260
subsd %xmm0, %xmm1
imull %r8d, %r10d
movslq %r10d, %r9
leaq (%rdx,%r9,8), %rdi
imull %r8d, %eax
cltq
leaq (%rdx,%rax,8), %rdx
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm1, %xmm2
leaq (%rcx,%r9,8), %r8
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
subsd %xmm0, %xmm3
leaq (%rcx,%rax,8), %rcx
movl %r11d, %r9d
xorl %eax, %eax
movsd 0xda4d6(%rip), %xmm4    # 0xf2670
xorl %r10d, %r10d
movsd (%rdx,%r10,8), %xmm5
mulsd %xmm0, %xmm5
movsd (%rdi,%r10,8), %xmm6
mulsd %xmm1, %xmm6
addsd %xmm5, %xmm6
movsd (%rcx,%r10,8), %xmm5
mulsd %xmm3, %xmm5
movsd (%r8,%r10,8), %xmm7
mulsd %xmm2, %xmm7
addsd %xmm5, %xmm7
mulsd %xmm8, %xmm7
mulsd %xmm8, %xmm7
divsd %xmm4, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, (%rsi,%r10,8)
incq %r10
cmpq %r10, %r9
jne 0x1819d
jmp 0x1806e
xorl %eax, %eax
jmp 0x1806e