// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_two_arrays_one_column
int array_interpolate_two_arrays_one_column(
					    double * array_x, /* assumed to be a vector (i.e. one column array) */
					    double * array_y,
					    int n_columns_y,
					    int index_y, /* between 0 and (n_columns_y-1) */
					    int n_lines,  /** must be the same for array_x and array_y */
					    double x,
					    double * result,
					    ErrorMsg errmsg) {

  int inf,sup,mid;
  double weight;
  double epsilon=1e-9;

  inf=0;
  sup=n_lines-1;

  if (array_x[inf] < array_x[sup]){

    class_test(x < array_x[inf]-epsilon,
	       errmsg,
	       "x=%e < x_min=%e",x,array_x[inf]);

    class_test(x > array_x[sup]+epsilon,
	       errmsg,
	       "x=%e > x_max=%e",x,array_x[sup]);

    while (sup-inf > 1) {

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

    }

  }

  else {

    class_test(x < array_x[sup]-epsilon,
	       errmsg,
	       "x=%e < x_min=%e",x,array_x[sup]);

    class_test(x > array_x[inf]+epsilon,
	       errmsg,
	       "x=%e > x_max=%e",x,array_x[inf]);

    while (sup-inf > 1) {

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

    }

  }

  weight=(x-array_x[inf])/(array_x[sup]-array_x[inf]);

  *result = array_y[index_y*n_lines+inf] * (1.-weight)
    + weight * array_y[index_y*n_lines+sup];

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
movq 0x1020(%rsp), %rbx
leal -0x1(%r8), %eax
movsd (%rdi), %xmm1
movslq %r8d, %rdx
movsd -0x8(%rdi,%rdx,8), %xmm2
movsd 0xce174(%rip), %xmm3    # 0xe6660
ucomisd %xmm1, %xmm2
jbe 0x18552
addsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x185b6
leaq 0xcebe3(%rip), %rsi     # 0xe70ea
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x2e014
leaq 0xccb62(%rip), %rsi     # 0xe5082
leaq 0xcee83(%rip), %rdx     # 0xe73aa
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xccaf6(%rip), %rsi     # 0xe5034
leaq 0xcee7e(%rip), %rdx     # 0xe73c3
movq %rbx, %rdi
movl $0xb79, %ecx            # imm = 0xB79
jmp 0x18682
addsd %xmm2, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x1861f
leaq 0xceb83(%rip), %rsi     # 0xe70ea
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x2e014
leaq 0xccafe(%rip), %rsi     # 0xe5082
leaq 0xcee79(%rip), %rdx     # 0xe7404
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xcca92(%rip), %rsi     # 0xe5034
leaq 0xcee1a(%rip), %rdx     # 0xe73c3
movq %rbx, %rdi
movl $0xb8d, %ecx            # imm = 0xB8D
jmp 0x18682
movsd 0xce0aa(%rip), %xmm1    # 0xe6668
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x18694
leaq 0xceb44(%rip), %rsi     # 0xe7117
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x2e014
leaq 0xcca92(%rip), %rsi     # 0xe5082
leaq 0xcedf4(%rip), %rdx     # 0xe73eb
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xcca26(%rip), %rsi     # 0xe5034
leaq 0xcedae(%rip), %rdx     # 0xe73c3
movq %rbx, %rdi
movl $0xb7d, %ecx            # imm = 0xB7D
jmp 0x18682
movsd 0xce041(%rip), %xmm2    # 0xe6668
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x186d6
leaq 0xceadb(%rip), %rsi     # 0xe7117
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x2e014
leaq 0xcca2d(%rip), %rsi     # 0xe5082
leaq 0xcedc1(%rip), %rdx     # 0xe741d
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xcc9c1(%rip), %rsi     # 0xe5034
leaq 0xced49(%rip), %rdx     # 0xe73c3
movq %rbx, %rdi
movl $0xb91, %ecx            # imm = 0xB91
movq %r15, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rax
jmp 0x1875f
xorl %edx, %edx
movsd 0xcd612(%rip), %xmm1    # 0xe5cb0
movl %eax, %r10d
subl %edx, %r10d
cmpl $0x2, %r10d
jl 0x18714
leal (%rdx,%rax), %r10d
cvtsi2sd %r10d, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %r10d
movslq %r10d, %r10
movsd (%rdi,%r10,8), %xmm2
ucomisd %xmm0, %xmm2
cmoval %r10d, %eax
cmoval %edx, %r10d
movl %r10d, %edx
jmp 0x1869e
xorl %edx, %edx
movsd 0xcd5d0(%rip), %xmm1    # 0xe5cb0
movl %eax, %r10d
subl %edx, %r10d
cmpl $0x2, %r10d
jl 0x18714
leal (%rdx,%rax), %r10d
cvtsi2sd %r10d, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %r10d
movslq %r10d, %r10
ucomisd (%rdi,%r10,8), %xmm0
cmoval %r10d, %eax
cmoval %edx, %r10d
movl %r10d, %edx
jmp 0x186e0
movslq %edx, %rdx
movsd (%rdi,%rdx,8), %xmm1
subsd %xmm1, %xmm0
cltq
movsd (%rdi,%rax,8), %xmm2
subsd %xmm1, %xmm2
divsd %xmm2, %xmm0
imull %ecx, %r8d
addl %r8d, %edx
movslq %edx, %rcx
movsd 0xccb1f(%rip), %xmm1    # 0xe5260
subsd %xmm0, %xmm1
addl %r8d, %eax
cltq
mulsd (%rsi,%rax,8), %xmm0
mulsd (%rsi,%rcx,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r9)
xorl %eax, %eax
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq