// File: /workspace/github_c_makefile_star2_O2/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
movslq %esi, %r13
decl %esi
movsd (%rdi), %xmm1
movsd -0x8(%rdi,%r13,8), %xmm2
decq %r13
ucomisd %xmm1, %xmm2
jbe 0x165b5
ucomisd %xmm0, %xmm1
jbe 0x1660d
leaq 0xd0b6b(%rip), %r15     # 0xe70df
leaq 0xd0c33(%rip), %r12     # 0xe71ae
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 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x7b4, %r8d            # imm = 0x7B4
jmp 0x166af
ucomisd %xmm0, %xmm2
jbe 0x16662
leaq 0xd0b19(%rip), %r15     # 0xe70df
leaq 0xd0be1(%rip), %r12     # 0xe71ae
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 0x8580
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 0x166af
ucomisd %xmm2, %xmm0
jbe 0x166cd
leaq 0xd0aee(%rip), %r15     # 0xe710c
leaq 0xd0b89(%rip), %r12     # 0xe71ae
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 0x8580
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 0x166af
ucomisd %xmm1, %xmm0
jbe 0x16705
leaq 0xd0a99(%rip), %r15     # 0xe710c
leaq 0xd0b34(%rip), %r12     # 0xe71ae
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 0x8580
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 0x8580
pushq $0x1
popq %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %eax, %eax
movsd 0xcf5d9(%rip), %xmm2    # 0xe5cb0
movl %esi, %edi
subl %eax, %edi
cmpl $0x2, %edi
jl 0x16739
leal (%rax,%rsi), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movslq %edi, %rdi
movsd (%rbx,%rdi,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %edi, %esi
cmoval %eax, %edi
movl %edi, %eax
jmp 0x166d7
xorl %eax, %eax
movsd 0xcf5a1(%rip), %xmm2    # 0xe5cb0
movl %esi, %edi
subl %eax, %edi
cmpl $0x2, %edi
jl 0x16739
leal (%rax,%rsi), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movslq %edi, %rdi
ucomisd (%rbx,%rdi,8), %xmm0
cmoval %edi, %esi
cmoval %eax, %edi
movl %edi, %eax
jmp 0x1670f
movl 0x40(%rsp), %edi
movl %eax, (%r8)
movslq %esi, %r8
movsd (%rbx,%r8,8), %xmm2
cltq
movsd (%rbx,%rax,8), %xmm1
subsd %xmm1, %xmm2
subsd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd 0xceafc(%rip), %xmm3    # 0xe5260
subsd %xmm0, %xmm3
imull %ecx, %eax
cltq
leaq (%rdx,%rax,8), %rsi
imull %ecx, %r8d
movslq %r8d, %rax
leaq (%rdx,%rax,8), %rcx
xorl %eax, %eax
testl %edi, %edi
cmovlel %eax, %edi
xorl %edx, %edx
cmpq %rdx, %rdi
je 0x166bf
movsd (%rcx,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
movsd (%rsi,%rdx,8), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%r9,%rdx,8)
incq %rdx
jmp 0x16785