// File: /workspace/github_c_makefile_star2_O3/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 0xd4ff5(%rip), %xmm3    # 0xef688
ucomisd %xmm1, %xmm2
jbe 0x1a6f9
addsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x1a75d
leaq 0xd5a7c(%rip), %rsi     # 0xf012a
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x30af0
leaq 0xd39bb(%rip), %rsi     # 0xee082
leaq 0xd5d1c(%rip), %rdx     # 0xf03ea
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xd394f(%rip), %rsi     # 0xee034
leaq 0xd5d17(%rip), %rdx     # 0xf0403
movq %rbx, %rdi
movl $0xb79, %ecx            # imm = 0xB79
jmp 0x1a829
addsd %xmm2, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x1a7c6
leaq 0xd5a1c(%rip), %rsi     # 0xf012a
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x30af0
leaq 0xd3957(%rip), %rsi     # 0xee082
leaq 0xd5d12(%rip), %rdx     # 0xf0444
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xd38eb(%rip), %rsi     # 0xee034
leaq 0xd5cb3(%rip), %rdx     # 0xf0403
movq %rbx, %rdi
movl $0xb8d, %ecx            # imm = 0xB8D
jmp 0x1a829
movsd 0xd4f2b(%rip), %xmm1    # 0xef690
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1a83d
leaq 0xd59dd(%rip), %rsi     # 0xf0157
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x30af0
leaq 0xd38eb(%rip), %rsi     # 0xee082
leaq 0xd5c8d(%rip), %rdx     # 0xf042b
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xd387f(%rip), %rsi     # 0xee034
leaq 0xd5c47(%rip), %rdx     # 0xf0403
movq %rbx, %rdi
movl $0xb7d, %ecx            # imm = 0xB7D
jmp 0x1a829
movsd 0xd4ec2(%rip), %xmm2    # 0xef690
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x1a889
leaq 0xd5974(%rip), %rsi     # 0xf0157
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x30af0
leaq 0xd3886(%rip), %rsi     # 0xee082
leaq 0xd5c5a(%rip), %rdx     # 0xf045d
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xd381a(%rip), %rsi     # 0xee034
leaq 0xd5be2(%rip), %rdx     # 0xf0403
movq %rbx, %rdi
movl $0xb91, %ecx            # imm = 0xB91
movq %r15, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
jmp 0x1a91a
cmpl $0x3, %r8d
jl 0x1a8cd
xorl %r10d, %r10d
movsd 0xd447e(%rip), %xmm1    # 0xeecd0
leal (%r10,%rax), %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %edx
movslq %edx, %rdx
movsd (%rdi,%rdx,8), %xmm2
ucomisd %xmm0, %xmm2
cmoval %edx, %eax
cmoval %r10d, %edx
movl %eax, %r11d
subl %edx, %r11d
movl %edx, %r10d
cmpl $0x1, %r11d
jg 0x1a852
jmp 0x1a8cf
cmpl $0x3, %r8d
jl 0x1a8cd
xorl %r10d, %r10d
movsd 0xd4436(%rip), %xmm1    # 0xeecd0
leal (%r10,%rax), %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %edx
movslq %edx, %rdx
ucomisd (%rdi,%rdx,8), %xmm0
cmoval %edx, %eax
cmoval %r10d, %edx
movl %eax, %r11d
subl %edx, %r11d
movl %edx, %r10d
cmpl $0x1, %r11d
jg 0x1a89a
jmp 0x1a8cf
xorl %edx, %edx
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 0xd3964(%rip), %xmm1    # 0xee260
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