// File: /workspace/github_c_makefile_star2_O2/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, %r14d
movl %ecx, %r15d
movq 0x48(%rsp), %r12
cmpl %ecx, %r9d
setne %al
cmpl %r8d, %r9d
setne %cl
testb %cl, %al
jne 0x11935
leaq 0xd5461(%rip), %rbx     # 0xe6d44
leaq 0xd549f(%rip), %r13     # 0xe6d89
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r13, %rcx
movl $0x12d, %r8d            # imm = 0x12D
movl %ebp, %r9d
xorl %eax, %eax
pushq %r14
pushq %r15
callq 0x8580
addq $0x10, %rsp
incl %eax
movslq %eax, %rsi
movq %r12, %rdi
movq %rbx, %rdx
movq %r13, %rcx
movl $0x12d, %r8d            # imm = 0x12D
movl %ebp, %r9d
xorl %eax, %eax
pushq %r14
pushq %r15
callq 0x8580
popq %rcx
popq %rdx
jmp 0x11af7
movq %rdi, %rbx
movslq %esi, %rdi
leaq (%rbx,%rdi,8), %rax
movslq %r15d, %r13
movsd (%rax,%r13,8), %xmm1
subsd (%rbx,%r13,8), %xmm1
movslq %r14d, %r12
movsd (%rax,%r12,8), %xmm0
subsd (%rbx,%r12,8), %xmm0
leal -0x1(%rdx), %esi
movslq %ebp, %rax
movslq 0x40(%rsp), %rcx
addl $-0x2, %edx
movslq %esi, %rsi
leaq (,%rdi,8), %r8
leaq (,%rcx,8), %r9
leaq (%r9,%rdi,8), %r9
leaq (,%rax,8), %r10
leaq (%r10,%rdi,8), %r10
leaq (,%r12,8), %r11
leaq (%r11,%rdi,8), %r11
leaq (,%r13,8), %r14
leaq (%r14,%rdi,8), %r14
shlq $0x4, %rdi
leaq (%rdi,%rax,8), %r15
leaq (%rdi,%r12,8), %r12
leaq (%rdi,%r13,8), %r13
pushq $0x1
popq %rbp
xorpd %xmm2, %xmm2
movq %rbx, %rdi
cmpq %rsi, %rbp
jge 0x11ab1
movsd (%rdi,%r13), %xmm3
subsd (%rdi,%r14), %xmm3
movsd (%rdi,%r12), %xmm4
subsd (%rdi,%r11), %xmm4
ucomisd %xmm2, %xmm1
jne 0x119f5
jp 0x119f5
ucomisd %xmm2, %xmm3
jne 0x119f5
jnp 0x11ab5
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)
cmpq $0x1, %rbp
jne 0x11a75
addsd %xmm0, %xmm0
divsd %xmm1, %xmm0
subsd (%rdi,%r10), %xmm0
movsd %xmm0, (%rbx,%rax,8)
movsd (%rdi,%r9), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
cmpq %rbp, %rdx
jne 0x11a9e
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)
addq %r8, %rdi
incq %rbp
movapd %xmm4, %xmm0
movapd %xmm3, %xmm1
jmp 0x119c0
xorl %eax, %eax
jmp 0x11afa
leaq 0xd5238(%rip), %r14     # 0xe6cf4
leaq 0xd52c6(%rip), %r15     # 0xe6d89
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x13e, %r8d            # imm = 0x13E
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq 0x48(%rsp), %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x13e, %r8d            # imm = 0x13E
xorl %eax, %eax
callq 0x8580
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq