// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate
int array_interpolate(
		   double * array,
		   int n_columns,
		   int n_lines,
		   int index_x,   /** from 0 to (n_columns-1) */
		   double x,
		   int * last_index,
		   double * result,
		   int result_size, /** from 1 to n_columns */
		   ErrorMsg errmsg) {

  int inf,sup,mid,i;
  double weight;

  inf=0;
  sup=n_lines-1;

  if (*(array+inf*n_columns+index_x) < *(array+sup*n_columns+index_x)){

    if (x < *(array+inf*n_columns+index_x)) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,x,*(array+inf*n_columns+index_x));
      return _FAILURE_;
    }

    if (x > *(array+sup*n_columns+index_x)) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,x,*(array+sup*n_columns+index_x));
      return _FAILURE_;
    }

    while (sup-inf > 1) {

      mid=(int)(0.5*(inf+sup));
      if (x < *(array+mid*n_columns+index_x)) {sup=mid;}
      else {inf=mid;}

    }

  }

  else {

    if (x < *(array+sup*n_columns+index_x)) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,x,*(array+sup*n_columns+index_x));
      return _FAILURE_;
    }

    if (x > *(array+inf*n_columns+index_x)) {
      class_sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,x,*(array+inf*n_columns+index_x));
      return _FAILURE_;
    }

    while (sup-inf > 1) {

      mid=(int)(0.5*(inf+sup));
      if (x > *(array+mid*n_columns+index_x)) {sup=mid;}
      else {inf=mid;}

    }

  }

  *last_index = inf;

  weight=(x-*(array+inf*n_columns+index_x))/(*(array+sup*n_columns+index_x)-*(array+inf*n_columns+index_x));

  for (i=0; i<result_size; i++)
    *(result+i) = *(array+inf*n_columns+i) * (1.-weight)
      + weight * *(array+sup*n_columns+i);

  *(result+index_x) = x;

  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(%rdx), %eax
movslq %ecx, %r13
movsd (%rdi,%r13,8), %xmm1
movl %eax, %ecx
imull %esi, %ecx
movslq %ecx, %rcx
leaq (%rdi,%rcx,8), %r12
movsd (%r12,%r13,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x179b8
ucomisd %xmm0, %xmm1
jbe 0x17a10
leaq 0xdb79a(%rip), %r15     # 0xf310f
leaq 0xdb7ae(%rip), %r12     # 0xf312a
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x681, %r8d            # imm = 0x681
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 $0x681, %r8d            # imm = 0x681
jmp 0x17ab4
ucomisd %xmm0, %xmm2
jbe 0x17a65
leaq 0xdb746(%rip), %rbx     # 0xf310f
leaq 0xdb75a(%rip), %r15     # 0xf312a
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
movl $0x697, %r8d            # imm = 0x697
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r12,%r13,8), %xmm1
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movl $0x697, %r8d            # imm = 0x697
jmp 0x17ab4
ucomisd %xmm2, %xmm0
jbe 0x17acb
leaq 0xdb71b(%rip), %rbx     # 0xf313c
leaq 0xdb702(%rip), %r15     # 0xf312a
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
movl $0x686, %r8d            # imm = 0x686
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, 0x8(%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r12,%r13,8), %xmm1
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movl $0x686, %r8d            # imm = 0x686
jmp 0x17ab4
ucomisd %xmm1, %xmm0
jbe 0x17b1e
leaq 0xdb6c6(%rip), %r15     # 0xf313c
leaq 0xdb6ad(%rip), %r12     # 0xf312a
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x69c, %r8d            # imm = 0x69C
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 $0x69c, %r8d            # imm = 0x69C
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
jmp 0x17be1
cmpl $0x3, %edx
jl 0x17b69
leaq (%rbx,%r13,8), %rdx
xorl %edi, %edi
movsd 0xda1ee(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, %r10d
imull %esi, %r10d
movslq %r10d, %r10
movsd (%rdx,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %eax
cmoval %edi, %ecx
movl %eax, %r10d
subl %ecx, %r10d
movl %ecx, %edi
cmpl $0x1, %r10d
jg 0x17ae2
jmp 0x17b6b
cmpl $0x3, %edx
jl 0x17b69
leaq (%rbx,%r13,8), %rdx
xorl %edi, %edi
movsd 0xda19f(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, %r10d
imull %esi, %r10d
movslq %r10d, %r10
ucomisd (%rdx,%r10,8), %xmm0
cmoval %ecx, %eax
cmoval %edi, %ecx
movl %eax, %r10d
subl %ecx, %r10d
movl %ecx, %edi
cmpl $0x1, %r10d
jg 0x17b31
jmp 0x17b6b
xorl %ecx, %ecx
movl 0x40(%rsp), %edx
movl %ecx, (%r8)
testl %edx, %edx
jle 0x17bd9
imull %esi, %ecx
movslq %ecx, %rcx
leaq (%rbx,%rcx,8), %rcx
movsd (%rcx,%r13,8), %xmm1
movapd %xmm0, %xmm4
subsd %xmm1, %xmm4
imull %esi, %eax
cltq
leaq (%rbx,%rax,8), %rax
movsd (%rax,%r13,8), %xmm2
subsd %xmm1, %xmm2
divsd %xmm2, %xmm4
movsd 0xd96b3(%rip), %xmm1    # 0xf1260
subsd %xmm4, %xmm1
movl %edx, %edx
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm2
mulsd %xmm4, %xmm2
movsd (%rcx,%rsi,8), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, (%r9,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x17bb5
movsd %xmm0, (%r9,%r13,8)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq