// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_linear
int array_interpolate_linear(
			     double * x_array,
			     int n_lines,
			     double * array,
			     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 = 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);

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x48(%rsp), %r14
leal -0x1(%rsi), %eax
movslq %esi, %r13
movsd (%rdi), %xmm1
movsd -0x8(%rdi,%r13,8), %xmm2
decq %r13
ucomisd %xmm1, %xmm2
jbe 0x18496
ucomisd %xmm0, %xmm1
jbe 0x184ee
leaq 0xdacba(%rip), %r15     # 0xf310f
leaq 0xdad82(%rip), %r12     # 0xf31de
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7b4, %r8d            # imm = 0x7B4
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7b4, %r8d            # imm = 0x7B4
jmp 0x18590
ucomisd %xmm0, %xmm2
jbe 0x18543
leaq 0xdac68(%rip), %r15     # 0xf310f
leaq 0xdad30(%rip), %r12     # 0xf31de
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7ca, %r8d            # imm = 0x7CA
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7ca, %r8d            # imm = 0x7CA
jmp 0x18590
ucomisd %xmm2, %xmm0
jbe 0x185b0
leaq 0xdac3d(%rip), %r15     # 0xf313c
leaq 0xdacd8(%rip), %r12     # 0xf31de
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7b9, %r8d            # imm = 0x7B9
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7b9, %r8d            # imm = 0x7B9
jmp 0x18590
ucomisd %xmm1, %xmm0
jbe 0x185f3
leaq 0xdabe8(%rip), %r15     # 0xf313c
leaq 0xdac83(%rip), %r12     # 0xf31de
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7cf, %r8d            # imm = 0x7CF
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7cf, %r8d            # imm = 0x7CF
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
cmpl $0x3, %esi
jl 0x18632
xorl %edi, %edi
movsd 0xd9711(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
movsd (%rbx,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %esi, %eax
cmoval %edi, %esi
movl %eax, %r10d
subl %esi, %r10d
movl %esi, %edi
cmpl $0x1, %r10d
jg 0x185bf
jmp 0x18634
cmpl $0x3, %esi
jl 0x18632
xorl %edi, %edi
movsd 0xd96ce(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
ucomisd (%rbx,%rsi,8), %xmm0
cmoval %esi, %eax
cmoval %edi, %esi
movl %eax, %r10d
subl %esi, %r10d
movl %esi, %edi
cmpl $0x1, %r10d
jg 0x18602
jmp 0x18634
xorl %esi, %esi
movl 0x40(%rsp), %edi
movl %esi, (%r8)
testl %edi, %edi
jle 0x186a9
cltq
movsd (%rbx,%rax,8), %xmm2
movslq %esi, %r8
movsd (%rbx,%r8,8), %xmm1
subsd %xmm1, %xmm2
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd 0xd8bfd(%rip), %xmm3    # 0xf1260
subsd %xmm0, %xmm3
imull %ecx, %esi
movslq %esi, %rsi
leaq (%rdx,%rsi,8), %rsi
imull %ecx, %eax
cltq
leaq (%rdx,%rax,8), %rcx
movl %edi, %edx
xorl %eax, %eax
xorl %edi, %edi
movsd (%rcx,%rdi,8), %xmm1
mulsd %xmm0, %xmm1
movsd (%rsi,%rdi,8), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%r9,%rdi,8)
incq %rdi
cmpq %rdi, %rdx
jne 0x18680
jmp 0x185a2
xorl %eax, %eax
jmp 0x185a2