// File: /workspace/github_c_makefile_star2_O3/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 0x18621
ucomisd %xmm0, %xmm1
jbe 0x18679
leaq 0xd7b3f(%rip), %r15     # 0xf011f
leaq 0xd7c07(%rip), %r12     # 0xf01ee
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 0x1871b
ucomisd %xmm0, %xmm2
jbe 0x186ce
leaq 0xd7aed(%rip), %r15     # 0xf011f
leaq 0xd7bb5(%rip), %r12     # 0xf01ee
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 0x1871b
ucomisd %xmm2, %xmm0
jbe 0x1873b
leaq 0xd7ac2(%rip), %r15     # 0xf014c
leaq 0xd7b5d(%rip), %r12     # 0xf01ee
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 0x1871b
ucomisd %xmm1, %xmm0
jbe 0x1877e
leaq 0xd7a6d(%rip), %r15     # 0xf014c
leaq 0xd7b08(%rip), %r12     # 0xf01ee
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 0x187bd
xorl %edi, %edi
movsd 0xd6586(%rip), %xmm2    # 0xeecd0
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 0x1874a
jmp 0x187bf
cmpl $0x3, %esi
jl 0x187bd
xorl %edi, %edi
movsd 0xd6543(%rip), %xmm2    # 0xeecd0
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 0x1878d
jmp 0x187bf
xorl %esi, %esi
movl 0x40(%rsp), %edi
movl %esi, (%r8)
testl %edi, %edi
jle 0x18834
cltq
movsd (%rbx,%rax,8), %xmm2
movslq %esi, %r8
movsd (%rbx,%r8,8), %xmm1
subsd %xmm1, %xmm2
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd 0xd5a72(%rip), %xmm3    # 0xee260
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 0x1880b
jmp 0x1872d
xorl %eax, %eax
jmp 0x1872d