// File: /workspace/github_c_makefile_star2_O1/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
leal -0x1(%rsi), %eax
movslq %ecx, %r13
movsd (%rdi,%r13,8), %xmm1
movl %eax, %edi
imull %edx, %edi
addl %r13d, %edi
movslq %edi, %rbp
movsd (%rbx,%rbp,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x17c77
ucomisd %xmm0, %xmm1
jbe 0x17ccd
leaq 0xdb4da(%rip), %r15     # 0xf310f
leaq 0xdb51b(%rip), %r12     # 0xf3157
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6d1, %r8d            # imm = 0x6D1
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
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 0x17d6e
ucomisd %xmm0, %xmm2
jbe 0x17d20
leaq 0xdb487(%rip), %r15     # 0xf310f
leaq 0xdb4c8(%rip), %r12     # 0xf3157
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 0x8550
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 0x17d6e
ucomisd %xmm2, %xmm0
jbe 0x17d84
leaq 0xdb45e(%rip), %r15     # 0xf313c
leaq 0xdb472(%rip), %r12     # 0xf3157
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 0x8550
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 0x17d6e
ucomisd %xmm1, %xmm0
jbe 0x17dd6
leaq 0xdb40b(%rip), %r15     # 0xf313c
leaq 0xdb41f(%rip), %r12     # 0xf3157
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movl $0x6ec, %r8d            # imm = 0x6EC
movb $0x2, %al
movsd %xmm0, (%rsp)
callq 0x8550
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 0x8550
movl $0x1, %eax
jmp 0x17ed7
cmpl $0x3, %esi
jl 0x17e20
xorl %edi, %edi
movsd 0xd9f39(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movl %esi, %r10d
imull %edx, %r10d
addl %ecx, %r10d
movslq %r10d, %r10
movsd (%rbx,%r10,8), %xmm1
ucomisd %xmm0, %xmm1
cmoval %esi, %eax
cmoval %edi, %esi
movl %eax, %r10d
subl %esi, %r10d
movl %esi, %edi
cmpl $0x1, %r10d
jg 0x17d97
jmp 0x17e22
cmpl $0x3, %esi
jl 0x17e20
xorl %edi, %edi
movsd 0xd9eeb(%rip), %xmm2    # 0xf1cd0
leal (%rdi,%rax), %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %esi
movl %esi, %r10d
imull %edx, %r10d
addl %ecx, %r10d
movslq %r10d, %r10
ucomisd (%rbx,%r10,8), %xmm0
cmoval %esi, %eax
cmoval %edi, %esi
movl %eax, %r10d
subl %esi, %r10d
movl %esi, %edi
cmpl $0x1, %r10d
jg 0x17de5
jmp 0x17e22
xorl %esi, %esi
movq 0x40(%rsp), %rdi
movl %esi, (%rdi)
imull %edx, %eax
leal (%rax,%rcx), %edi
movslq %edi, %rdi
movsd (%rbx,%rdi,8), %xmm5
imull %edx, %esi
addl %esi, %ecx
movslq %ecx, %rcx
movsd (%rbx,%rcx,8), %xmm1
subsd %xmm1, %xmm5
subsd %xmm1, %xmm0
divsd %xmm5, %xmm0
movsd 0xd9408(%rip), %xmm4    # 0xf1260
subsd %xmm0, %xmm4
leal (%rsi,%r8), %ecx
movslq %ecx, %rcx
addl %eax, %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, %esi
addl %r9d, %eax
cltq
mulsd (%rbx,%rax,8), %xmm4
movslq %esi, %rax
mulsd (%rbx,%rax,8), %xmm3
addsd %xmm4, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
divsd 0xda7a7(%rip), %xmm3    # 0xf2670
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