// File: /workspace/github_c_makefile_star2_O2/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
movsd (%rdi), %xmm2
movslq %esi, %rax
decl %esi
movsd -0x8(%rdi,%rax,8), %xmm1
ucomisd %xmm2, %xmm1
jbe 0x160c5
ucomisd %xmm0, %xmm2
jbe 0x16118
leaq 0xd1060(%rip), %r14     # 0xe70df
leaq 0xd10c5(%rip), %r15     # 0xe714b
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 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x720, %r8d            # imm = 0x720
jmp 0x161ba
ucomisd %xmm0, %xmm1
jbe 0x16168
leaq 0xd1009(%rip), %r14     # 0xe70df
leaq 0xd106e(%rip), %r15     # 0xe714b
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 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x736, %r8d            # imm = 0x736
jmp 0x161ba
ucomisd %xmm1, %xmm0
jbe 0x161d9
leaq 0xd0fe3(%rip), %r14     # 0xe710c
leaq 0xd101b(%rip), %r15     # 0xe714b
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 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x725, %r8d            # imm = 0x725
jmp 0x161ba
ucomisd %xmm2, %xmm0
jbe 0x1621b
leaq 0xd0f93(%rip), %r14     # 0xe710c
leaq 0xd0fcb(%rip), %r15     # 0xe714b
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 0x8580
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 0x8580
pushq $0x1
popq %rax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorl %eax, %eax
movsd 0xcfacd(%rip), %xmm2    # 0xe5cb0
movl %esi, %r10d
subl %eax, %r10d
cmpl $0x2, %r10d
jl 0x16259
leal (%rax,%rsi), %r10d
cvtsi2sd %r10d, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r10d
movslq %r10d, %r10
movsd (%rdi,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %r10d, %esi
cmoval %eax, %r10d
movl %r10d, %eax
jmp 0x161e3
xorl %eax, %eax
movsd 0xcfa8b(%rip), %xmm2    # 0xe5cb0
movl %esi, %r10d
subl %eax, %r10d
cmpl $0x2, %r10d
jl 0x16259
leal (%rax,%rsi), %r10d
cvtsi2sd %r10d, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r10d
movslq %r10d, %r10
ucomisd (%rdi,%r10,8), %xmm0
cmoval %r10d, %esi
cmoval %eax, %r10d
movl %r10d, %eax
jmp 0x16225
movl 0x38(%rsp), %r10d
movq 0x30(%rsp), %r11
movl %eax, (%r9)
movslq %esi, %r9
movsd (%rdi,%r9,8), %xmm8
cltq
movsd (%rdi,%rax,8), %xmm1
subsd %xmm1, %xmm8
subsd %xmm1, %xmm0
divsd %xmm8, %xmm0
movsd 0xcefd4(%rip), %xmm1    # 0xe5260
subsd %xmm0, %xmm1
imull %r8d, %eax
cltq
leaq (%rdx,%rax,8), %rsi
imull %r8d, %r9d
movslq %r9d, %r8
leaq (%rdx,%r8,8), %rdx
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
subsd %xmm1, %xmm2
leaq (%rcx,%rax,8), %rdi
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
subsd %xmm0, %xmm3
leaq (%rcx,%r8,8), %rcx
xorl %eax, %eax
testl %r10d, %r10d
cmovlel %eax, %r10d
movsd 0xd0372(%rip), %xmm4    # 0xe6650
xorl %r8d, %r8d
cmpq %r8, %r10
je 0x161cf
movsd (%rdx,%r8,8), %xmm5
mulsd %xmm0, %xmm5
movsd (%rsi,%r8,8), %xmm6
mulsd %xmm1, %xmm6
addsd %xmm5, %xmm6
movsd (%rcx,%r8,8), %xmm5
mulsd %xmm3, %xmm5
movsd (%rdi,%r8,8), %xmm7
mulsd %xmm2, %xmm7
addsd %xmm5, %xmm7
mulsd %xmm8, %xmm7
mulsd %xmm8, %xmm7
divsd %xmm4, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, (%r11,%r8,8)
incq %r8
jmp 0x162e1