// File: /workspace/github_c_makefile_star2_O3/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 0x180ed
ucomisd %xmm0, %xmm2
jbe 0x18140
leaq 0xd8078(%rip), %r14     # 0xf011f
leaq 0xd80dd(%rip), %r15     # 0xf018b
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 0x181e2
ucomisd %xmm0, %xmm1
jbe 0x18190
leaq 0xd8021(%rip), %r14     # 0xf011f
leaq 0xd8086(%rip), %r15     # 0xf018b
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 0x181e2
ucomisd %xmm1, %xmm0
jbe 0x18203
leaq 0xd7ffb(%rip), %r14     # 0xf014c
leaq 0xd8033(%rip), %r15     # 0xf018b
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 0x181e2
ucomisd %xmm2, %xmm0
jbe 0x18251
leaq 0xd7fab(%rip), %r14     # 0xf014c
leaq 0xd7fe3(%rip), %r15     # 0xf018b
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 0x18297
xorl %esi, %esi
movsd 0xd6aba(%rip), %xmm2    # 0xeecd0
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 0x18216
jmp 0x1829a
cmpl $0x3, %esi
jl 0x18297
xorl %esi, %esi
movsd 0xd6a70(%rip), %xmm2    # 0xeecd0
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 0x18260
jmp 0x1829a
xorl %r10d, %r10d
movl 0x38(%rsp), %r11d
movl %r10d, (%r9)
testl %r11d, %r11d
jle 0x1837d
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 0xd5f89(%rip), %xmm1    # 0xee260
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 0xd734b(%rip), %xmm4    # 0xef670
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 0x18328
jmp 0x181f9
xorl %eax, %eax
jmp 0x181f9