// File: /workspace/github_c_makefile_star2_O1/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 0xd8116(%rip), %xmm3    # 0xf2688
ucomisd %xmm1, %xmm2
jbe 0x1a5d8
addsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x1a63c
leaq 0xd8b8d(%rip), %rsi     # 0xf311a
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x30c2c
leaq 0xd6adc(%rip), %rsi     # 0xf1082
leaq 0xd8e2d(%rip), %rdx     # 0xf33da
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd6a70(%rip), %rsi     # 0xf1034
leaq 0xd8e28(%rip), %rdx     # 0xf33f3
movq %rbx, %rdi
movl $0xb79, %ecx            # imm = 0xB79
jmp 0x1a708
addsd %xmm2, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x1a6a5
leaq 0xd8b2d(%rip), %rsi     # 0xf311a
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x30c2c
leaq 0xd6a78(%rip), %rsi     # 0xf1082
leaq 0xd8e23(%rip), %rdx     # 0xf3434
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd6a0c(%rip), %rsi     # 0xf1034
leaq 0xd8dc4(%rip), %rdx     # 0xf33f3
movq %rbx, %rdi
movl $0xb8d, %ecx            # imm = 0xB8D
jmp 0x1a708
movsd 0xd804c(%rip), %xmm1    # 0xf2690
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1a71c
leaq 0xd8aee(%rip), %rsi     # 0xf3147
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movapd %xmm2, %xmm1
movb $0x2, %al
callq 0x30c2c
leaq 0xd6a0c(%rip), %rsi     # 0xf1082
leaq 0xd8d9e(%rip), %rdx     # 0xf341b
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd69a0(%rip), %rsi     # 0xf1034
leaq 0xd8d58(%rip), %rdx     # 0xf33f3
movq %rbx, %rdi
movl $0xb7d, %ecx            # imm = 0xB7D
jmp 0x1a708
movsd 0xd7fe3(%rip), %xmm2    # 0xf2690
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x1a768
leaq 0xd8a85(%rip), %rsi     # 0xf3147
leaq 0x800(%rsp), %r14
movq %r14, %rdi
movb $0x2, %al
callq 0x30c2c
leaq 0xd69a7(%rip), %rsi     # 0xf1082
leaq 0xd8d6b(%rip), %rdx     # 0xf344d
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0xd693b(%rip), %rsi     # 0xf1034
leaq 0xd8cf3(%rip), %rdx     # 0xf33f3
movq %rbx, %rdi
movl $0xb91, %ecx            # imm = 0xB91
movq %r15, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
jmp 0x1a7f9
cmpl $0x3, %r8d
jl 0x1a7ac
xorl %r10d, %r10d
movsd 0xd759f(%rip), %xmm1    # 0xf1cd0
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 0x1a731
jmp 0x1a7ae
cmpl $0x3, %r8d
jl 0x1a7ac
xorl %r10d, %r10d
movsd 0xd7557(%rip), %xmm1    # 0xf1cd0
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 0x1a779
jmp 0x1a7ae
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 0xd6a85(%rip), %xmm1    # 0xf1260
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