// File: /workspace/github_c_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x48(%rsp), %rbx
leal -0x1(%rdx), %eax
movslq %ecx, %r12
leaq (%rdi,%r12,8), %r13
movsd (%r13), %xmm1
movl %eax, %ecx
imull %esi, %ecx
movslq %ecx, %rcx
leaq (%rdi,%rcx,8), %rbp
movsd (%rbp,%r12,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x17b4a
ucomisd %xmm0, %xmm1
jbe 0x17ba2
leaq 0xd8617(%rip), %r14     # 0xf011f
leaq 0xd862b(%rip), %r15     # 0xf013a
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x681, %r8d            # imm = 0x681
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r13), %xmm1
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x681, %r8d            # imm = 0x681
jmp 0x17c45
ucomisd %xmm0, %xmm2
jbe 0x17bf7
leaq 0xd85c4(%rip), %r14     # 0xf011f
leaq 0xd85d8(%rip), %r15     # 0xf013a
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x697, %r8d            # imm = 0x697
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbp,%r12,8), %xmm1
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x697, %r8d            # imm = 0x697
jmp 0x17c45
ucomisd %xmm2, %xmm0
jbe 0x17c5b
leaq 0xd8599(%rip), %r14     # 0xf014c
leaq 0xd8580(%rip), %r15     # 0xf013a
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x686, %r8d            # imm = 0x686
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbp,%r12,8), %xmm1
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x686, %r8d            # imm = 0x686
jmp 0x17c45
ucomisd %xmm1, %xmm0
jbe 0x17cab
leaq 0xd8544(%rip), %r14     # 0xf014c
leaq 0xd852b(%rip), %r15     # 0xf013a
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x69c, %r8d            # imm = 0x69C
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r13), %xmm1
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x69c, %r8d            # imm = 0x69C
movsd (%rsp), %xmm0
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
jmp 0x17d6b
cmpl $0x3, %edx
jl 0x17cf3
xorl %edx, %edx
movsd 0xd7062(%rip), %xmm2    # 0xeecd0
leal (%rdx,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, %r10d
imull %esi, %r10d
movslq %r10d, %r10
movsd (%r13,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %eax
cmoval %edx, %ecx
movl %eax, %r10d
subl %ecx, %r10d
movl %ecx, %edx
cmpl $0x1, %r10d
jg 0x17c6e
jmp 0x17cf5
cmpl $0x3, %edx
jl 0x17cf3
xorl %edx, %edx
movsd 0xd7016(%rip), %xmm2    # 0xeecd0
leal (%rdx,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, %r10d
imull %esi, %r10d
movslq %r10d, %r10
ucomisd (%r13,%r10,8), %xmm0
cmoval %ecx, %eax
cmoval %edx, %ecx
movl %eax, %r10d
subl %ecx, %r10d
movl %ecx, %edx
cmpl $0x1, %r10d
jg 0x17cba
jmp 0x17cf5
xorl %ecx, %ecx
movl 0x40(%rsp), %edx
movl %ecx, (%r8)
testl %edx, %edx
jle 0x17d63
imull %esi, %ecx
movslq %ecx, %rcx
leaq (%rdi,%rcx,8), %rcx
movsd (%rcx,%r12,8), %xmm1
movapd %xmm0, %xmm4
subsd %xmm1, %xmm4
imull %esi, %eax
cltq
leaq (%rdi,%rax,8), %rax
movsd (%rax,%r12,8), %xmm2
subsd %xmm1, %xmm2
divsd %xmm2, %xmm4
movsd 0xd6529(%rip), %xmm1    # 0xee260
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 0x17d3f
movsd %xmm0, (%r9,%r12,8)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq