// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../tools/arrays.c
// Function: array_derive_two
int array_derive_two(
		     double * array,
		     int n_columns,
		     int n_lines,
		     int index_x,   /** from 0 to (n_columns-1) */
		     int index_y,
		     int index_dydx,
		     int index_ddydxdx,
		     ErrorMsg errmsg) {

  int i;

  double dx1,dx2,dy1,dy2,weight1,weight2;

  if ((index_dydx == index_x) || (index_dydx == index_y)) {
    class_sprintf(errmsg,"%s(L:%d) : Output column %d must differ from input columns %d and %d",__func__,__LINE__,index_dydx,index_x,index_y);
    return _FAILURE_;
  }

  dx2=*(array+1*n_columns+index_x)-*(array+0*n_columns+index_x);
  dy2=*(array+1*n_columns+index_y)-*(array+0*n_columns+index_y);

  for (i=1; i<n_lines-1; i++) {

    dx1 = dx2;
    dy1 = dy2;
    dx2 = *(array+(i+1)*n_columns+index_x)-*(array+i*n_columns+index_x);
    dy2 = *(array+(i+1)*n_columns+index_y)-*(array+i*n_columns+index_y);
    weight1 = dx2*dx2;
    weight2 = dx1*dx1;

    if ((dx1 == 0.) && (dx2 == 0.)) {
      class_sprintf(errmsg,"%s(L:%d) stop to avoid division by zero",__func__,__LINE__);
      return _FAILURE_;
    }

    *(array+i*n_columns+index_dydx) = (weight1*dy1+weight2*dy2) / (weight1*dx1+weight2*dx2);
    *(array+i*n_columns+index_ddydxdx) = (dx2*dy1-dx1*dy2) / (weight1*dx1+weight2*dx2);

    if (i == 1) {
      *(array+(i-1)*n_columns+index_dydx) = 2.*dy1/dx1 - *(array+i*n_columns+index_dydx);
      *(array+(i-1)*n_columns+index_ddydxdx) = *(array+i*n_columns+index_ddydxdx);
    }

    if (i == n_lines-2) {
      *(array+(i+1)*n_columns+index_dydx) = 2.*dy2/dx2 - *(array+i*n_columns+index_dydx);
      *(array+(i+1)*n_columns+index_dydx) = *(array+i*n_columns+index_ddydxdx);
    }
  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %ebp
movl %r8d, %r15d
movl %ecx, %r14d
movq %rdi, %rbx
movq 0x48(%rsp), %rdi
cmpl %ecx, %r9d
setne %al
cmpl %r8d, %r9d
setne %cl
testb %cl, %al
jne 0x134c0
leaq 0xdf90b(%rip), %r12     # 0xf2d74
leaq 0xdf949(%rip), %r13     # 0xf2db9
movq %rdi, %rbx
xorl %edi, %edi
xorl %esi, %esi
movq %r12, %rdx
movq %r13, %rcx
movl $0x12d, %r8d            # imm = 0x12D
movl %ebp, %r9d
xorl %eax, %eax
pushq %r15
pushq %r14
callq 0x8550
addq $0x10, %rsp
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r13, %rcx
movl $0x12d, %r8d            # imm = 0x12D
movl %ebp, %r9d
xorl %eax, %eax
pushq %r15
pushq %r14
callq 0x8550
addq $0x10, %rsp
jmp 0x13691
cmpl $0x3, %edx
jl 0x1364b
movslq %r14d, %rdi
movslq %r15d, %r12
leal -0x1(%rdx), %eax
movslq %esi, %r13
leaq (%rbx,%r13,8), %rcx
movsd (%rcx,%r12,8), %xmm0
subsd (%rbx,%r12,8), %xmm0
movsd (%rcx,%rdi,8), %xmm1
subsd (%rbx,%rdi,8), %xmm1
movslq %ebp, %rcx
movslq 0x40(%rsp), %rsi
addl $-0x2, %edx
decq %rdx
leaq (,%r13,8), %r8
leaq (,%rsi,8), %r9
leaq (%r9,%r13,8), %r9
leaq (,%rcx,8), %r10
leaq (%r10,%r13,8), %r10
leaq (,%r12,8), %r11
leaq (%r11,%r13,8), %r11
leaq (,%rdi,8), %r14
leaq (%r14,%r13,8), %r14
decq %rax
shlq $0x4, %r13
leaq (,%rcx,8), %r15
addq %r13, %r15
leaq (,%r12,8), %r12
addq %r13, %r12
leaq (%r13,%rdi,8), %r13
xorl %ebp, %ebp
xorpd %xmm2, %xmm2
movq %rbx, %rdi
movsd (%rdi,%r13), %xmm3
subsd (%rdi,%r14), %xmm3
movsd (%rdi,%r12), %xmm4
subsd (%rdi,%r11), %xmm4
ucomisd %xmm2, %xmm1
jne 0x1358c
jp 0x1358c
ucomisd %xmm2, %xmm3
jne 0x1358c
jnp 0x1364f
movapd %xmm1, %xmm5
mulsd %xmm1, %xmm5
movapd %xmm3, %xmm6
mulsd %xmm3, %xmm6
movapd %xmm5, %xmm7
mulsd %xmm4, %xmm7
movapd %xmm6, %xmm8
mulsd %xmm0, %xmm8
addsd %xmm7, %xmm8
mulsd %xmm3, %xmm5
mulsd %xmm1, %xmm6
addsd %xmm5, %xmm6
divsd %xmm6, %xmm8
movsd %xmm8, (%rdi,%r10)
movapd %xmm4, %xmm5
mulsd %xmm1, %xmm5
movapd %xmm3, %xmm7
mulsd %xmm0, %xmm7
subsd %xmm5, %xmm7
divsd %xmm6, %xmm7
movsd %xmm7, (%rdi,%r9)
testq %rbp, %rbp
jne 0x1360b
addsd %xmm0, %xmm0
divsd %xmm1, %xmm0
subsd (%rdi,%r10), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
movsd (%rdi,%r9), %xmm0
movsd %xmm0, (%rbx,%rsi,8)
cmpq %rbp, %rdx
jne 0x13634
movapd %xmm4, %xmm0
addsd %xmm4, %xmm0
divsd %xmm3, %xmm0
subsd (%rdi,%r10), %xmm0
movsd %xmm0, (%rdi,%r15)
movsd (%rdi,%r9), %xmm0
movsd %xmm0, (%rdi,%r15)
incq %rbp
addq %r8, %rdi
movapd %xmm3, %xmm1
movapd %xmm4, %xmm0
cmpq %rbp, %rax
jne 0x13560
xorl %eax, %eax
jmp 0x13696
leaq 0xdf6ce(%rip), %r14     # 0xf2d24
leaq 0xdf75c(%rip), %r15     # 0xf2db9
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x13e, %r8d            # imm = 0x13E
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq 0x48(%rsp), %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x13e, %r8d            # imm = 0x13E
xorl %eax, %eax
callq 0x8550
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq