// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_two
int array_interpolate_two(
		   double * array_x,
		   int n_columns_x,
		   int index_x,   /** from 0 to (n_columns_x-1) */
		   double * array_y,
		   int n_columns_y,
		   int n_lines,  /** must be the same for array_x and array_y */
		   double x,
		   double * result,
		   int result_size, /** from 1 to n_columns_y */
		   ErrorMsg errmsg) {

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

  inf=0;
  sup=n_lines-1;

  if (array_x[inf*n_columns_x+index_x] < array_x[sup*n_columns_x+index_x]){

    if (x < array_x[inf*n_columns_x+index_x]) {

      class_sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,x,array_x[inf*n_columns_x+index_x]);
      return _FAILURE_;
    }

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

    while (sup-inf > 1) {

      mid=(int)(0.5*(inf+sup));
      if (x < array_x[mid*n_columns_x+index_x]) {sup=mid;}
      else {inf=mid;}

    }

  }

  else {

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

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

    while (sup-inf > 1) {

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

    }

  }

  weight=(x-*(array_x+inf*n_columns_x+index_x))/(*(array_x+sup*n_columns_x+index_x)-*(array_x+inf*n_columns_x+index_x));

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

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x50(%rsp), %r14
leal -0x1(%r9), %eax
movslq %edx, %r12
leaq (%rdi,%r12,8), %r13
movsd (%r13), %xmm1
movl %eax, %edi
imull %esi, %edi
leal (%r12,%rdi), %r8d
movslq %r8d, %rbp
movsd (%rbx,%rbp,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x1a118
ucomisd %xmm0, %xmm1
jbe 0x1a17e
leaq 0xd6049(%rip), %rbx     # 0xf011f
leaq 0xd62dd(%rip), %r15     # 0xf03ba
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xae1, %r8d            # imm = 0xAE1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r13), %xmm1
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xae1, %r8d            # imm = 0xAE1
jmp 0x1a21f
movslq %edi, %rdx
leaq (%rbx,%rdx,8), %rbp
movsd (%rbp,%r12,8), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x1a1d1
leaq 0xd5fe8(%rip), %rbx     # 0xf011f
leaq 0xd627c(%rip), %r15     # 0xf03ba
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xaf7, %r8d            # imm = 0xAF7
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbp,%r12,8), %xmm1
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xaf7, %r8d            # imm = 0xAF7
jmp 0x1a21f
ucomisd %xmm2, %xmm0
jbe 0x1a23f
leaq 0xd5fbd(%rip), %r15     # 0xf014c
leaq 0xd6224(%rip), %r12     # 0xf03ba
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0xae6, %r8d            # imm = 0xAE6
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%rbx,%rbp,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0xae6, %r8d            # imm = 0xAE6
jmp 0x1a21f
ucomisd %xmm1, %xmm0
jbe 0x1a296
leaq 0xd5f6a(%rip), %rbx     # 0xf014c
leaq 0xd61d1(%rip), %r15     # 0xf03ba
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xafc, %r8d            # imm = 0xAFC
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
incl %eax
movslq %eax, %rsi
movsd (%r13), %xmm1
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movl $0xafc, %r8d            # imm = 0xAFC
movsd (%rsp), %xmm0
movb $0x2, %al
callq 0x8550
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %r9d
jl 0x1a2df
xorl %r8d, %r8d
movsd 0xd4a7c(%rip), %xmm2    # 0xeecd0
leal (%r8,%rax), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movl %edi, %r10d
imull %esi, %r10d
addl %edx, %r10d
movslq %r10d, %r10
movsd (%rbx,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %edi, %eax
cmoval %r8d, %edi
movl %eax, %r10d
subl %edi, %r10d
movl %edi, %r8d
cmpl $0x1, %r10d
jg 0x1a254
jmp 0x1a2e1
cmpl $0x3, %r9d
jl 0x1a2df
xorl %edx, %edx
movsd 0xd4a2a(%rip), %xmm2    # 0xeecd0
leal (%rdx,%rax), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movl %edi, %r8d
imull %esi, %r8d
movslq %r8d, %r8
ucomisd (%r13,%r8,8), %xmm0
cmoval %edi, %eax
cmoval %edx, %edi
movl %eax, %r8d
subl %edi, %r8d
movl %edi, %edx
cmpl $0x1, %r8d
jg 0x1a2a6
jmp 0x1a2e1
xorl %edi, %edi
movl 0x48(%rsp), %r10d
testl %r10d, %r10d
jle 0x1a36a
movq 0x40(%rsp), %rdx
movslq %edi, %r8
imull %esi, %edi
movslq %edi, %rdi
leaq (%rbx,%rdi,8), %rdi
movsd (%rdi,%r12,8), %xmm2
subsd %xmm2, %xmm0
imull %eax, %esi
movslq %esi, %rsi
leaq (%rbx,%rsi,8), %rsi
movsd (%rsi,%r12,8), %xmm1
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0xd3f39(%rip), %xmm3    # 0xee260
subsd %xmm0, %xmm3
movslq %eax, %rsi
movslq %r9d, %rdi
movl %r10d, %r9d
shlq $0x3, %rdi
xorl %eax, %eax
xorl %r10d, %r10d
movsd (%rcx,%rsi,8), %xmm1
mulsd %xmm0, %xmm1
movsd (%rcx,%r8,8), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%rdx,%r10,8)
incq %r10
addq %rdi, %rcx
cmpq %r10, %r9
jne 0x1a33d
jmp 0x1a230
xorl %eax, %eax
jmp 0x1a230