// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_interpolate_spline_transposed
int array_interpolate_spline_transposed(double * array,
                                        int x_size,
                                        int y_size,
                                        int index_x,
                                        int index_y,
                                        int index_ddy,
                                        double x,
                                        int * last_index,
                                        double * result,
                                        ErrorMsg errmsg) {

  int inf,sup,mid;
  double h,a,b;

  inf=0;
  sup=x_size-1;

  if (array[inf*y_size+index_x] < array[sup*y_size+index_x]){

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

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

    while (sup-inf > 1) {

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

    }

  }

  else {

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

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

    while (sup-inf > 1) {

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

    }

  }

  *last_index = inf;

  h = array[sup*y_size+index_x]-array[inf*y_size+index_x];
  b = (x - array[inf*y_size+index_x])/h;
  a = 1.0 - b;

  *result= (a*array[inf*y_size+index_y]+b*array[sup*y_size+index_y]
            + ((a*a*a-a)* array[inf*y_size+index_ddy] + (b*b*b-b)* array[sup*y_size+index_ddy])*h*h/6.);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x50(%rsp), %r14
decl %esi
movslq %ecx, %r13
movsd (%rdi,%r13,8), %xmm1
movl %esi, %eax
imull %edx, %eax
addl %r13d, %eax
movslq %eax, %rbp
movsd (%rdi,%rbp,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x15dfa
ucomisd %xmm0, %xmm1
jbe 0x15e50
leaq 0xd1327(%rip), %r15     # 0xe70df
leaq 0xd1368(%rip), %r12     # 0xe7127
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6d1, %r8d            # imm = 0x6D1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6d1, %r8d            # imm = 0x6D1
jmp 0x15ef1
ucomisd %xmm0, %xmm2
jbe 0x15ea3
leaq 0xd12d4(%rip), %r15     # 0xe70df
leaq 0xd1315(%rip), %r12     # 0xe7127
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6e7, %r8d            # imm = 0x6E7
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%rbp,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6e7, %r8d            # imm = 0x6E7
jmp 0x15ef1
ucomisd %xmm2, %xmm0
jbe 0x15f05
leaq 0xd12ab(%rip), %r15     # 0xe710c
leaq 0xd12bf(%rip), %r12     # 0xe7127
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6d6, %r8d            # imm = 0x6D6
movapd %xmm2, %xmm1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%rbp,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6d6, %r8d            # imm = 0x6D6
jmp 0x15ef1
ucomisd %xmm1, %xmm0
jbe 0x15f48
leaq 0xd1258(%rip), %r15     # 0xe710c
leaq 0xd126c(%rip), %r12     # 0xe7127
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6ec, %r8d            # imm = 0x6EC
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8580
incl %eax
movslq %eax, %rsi
movsd (%rbx,%r13,8), %xmm1
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6ec, %r8d            # imm = 0x6EC
movsd (%rsp), %xmm0
movb $0x2, %al
callq 0x8580
pushq $0x1
popq %rax
jmp 0x1603c
xorl %eax, %eax
movsd 0xcfda1(%rip), %xmm2    # 0xe5cb0
movl %esi, %edi
subl %eax, %edi
cmpl $0x2, %edi
jl 0x15f87
leal (%rax,%rsi), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movl %edi, %r10d
imull %edx, %r10d
addl %ecx, %r10d
movslq %r10d, %r10
movsd (%rbx,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %edi, %esi
cmoval %eax, %edi
movl %edi, %eax
jmp 0x15f0f
xorl %eax, %eax
movsd 0xcfd5e(%rip), %xmm2    # 0xe5cb0
movl %esi, %edi
subl %eax, %edi
cmpl $0x2, %edi
jl 0x15f87
leal (%rax,%rsi), %edi
cvtsi2sd %edi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edi
movl %edi, %r10d
imull %edx, %r10d
addl %ecx, %r10d
movslq %r10d, %r10
ucomisd (%rbx,%r10,8), %xmm0
cmoval %edi, %esi
cmoval %eax, %edi
movl %edi, %eax
jmp 0x15f52
movq 0x40(%rsp), %rdi
movl %eax, (%rdi)
imull %edx, %esi
leal (%rsi,%rcx), %edi
movslq %edi, %rdi
movsd (%rbx,%rdi,8), %xmm5
imull %edx, %eax
addl %eax, %ecx
movslq %ecx, %rcx
movsd (%rbx,%rcx,8), %xmm1
subsd %xmm1, %xmm5
subsd %xmm1, %xmm0
divsd %xmm5, %xmm0
movsd 0xcf2a3(%rip), %xmm4    # 0xe5260
subsd %xmm0, %xmm4
leal (%rax,%r8), %ecx
movslq %ecx, %rcx
addl %esi, %r8d
movslq %r8d, %rdx
movsd (%rbx,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
movsd (%rbx,%rcx,8), %xmm2
mulsd %xmm4, %xmm2
movapd %xmm4, %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
subsd %xmm4, %xmm3
movapd %xmm0, %xmm4
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm4
subsd %xmm0, %xmm4
movq 0x48(%rsp), %rcx
addl %r9d, %eax
addl %r9d, %esi
movslq %esi, %rdx
mulsd (%rbx,%rdx,8), %xmm4
cltq
mulsd (%rbx,%rax,8), %xmm3
addsd %xmm4, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
divsd 0xd0622(%rip), %xmm3    # 0xe6650
addsd %xmm1, %xmm2
addsd %xmm2, %xmm3
movsd %xmm3, (%rcx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq