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

  int i;
  double h;

  if ((index_start_spline<0) || (index_start_spline>=n_lines)) {
    class_sprintf(errmsg,"%s(L:%d) index_start_spline outside of range",__func__,__LINE__);
    return _FAILURE_;
  }

  *result = 0;

  /* trapezoidal integration till given index */

  for (i=0; i < index_start_spline; i++) {

    h = (array[(i+1)*n_columns+index_x]-array[i*n_columns+index_x]);

    *result +=
      (array[i*n_columns+index_y]+array[(i+1)*n_columns+index_y])*h/2.;

  }

  /* then, spline integration */

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

    h = (array[(i+1)*n_columns+index_x]-array[i*n_columns+index_x]);

    // the second line ended with an incorrect + sign until v3.2 included (Credits: C. Radermacher)
    *result +=
      (array[i*n_columns+index_y]+array[(i+1)*n_columns+index_y])*h/2. -
      (array[i*n_columns+index_ddy]+array[(i+1)*n_columns+index_ddy])*h*h*h/24.;

  }

  return _SUCCESS_;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
testl %ecx, %ecx
sets %al
cmpl %edx, %ecx
setge %r10b
orb %al, %r10b
jne 0x1767c
movq 0x28(%rsp), %r10
movq $0x0, (%r10)
movslq %esi, %rsi
movslq %r8d, %r8
movslq %r9d, %r11
movl %ecx, %r9d
testl %ecx, %ecx
jle 0x175c9
leaq (%rdi,%r8,8), %r15
leaq (%rdi,%r11,8), %rax
leaq (,%rsi,8), %rbx
xorpd %xmm0, %xmm0
movsd 0xda73a(%rip), %xmm1    # 0xf1cd0
movq %r9, %r14
movsd (%r15,%rbx), %xmm2
subsd (%r15), %xmm2
movsd (%rax), %xmm3
addsd (%rax,%rbx), %xmm3
addq %rbx, %r15
addq %rbx, %rax
mulsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm3, %xmm0
movsd %xmm0, (%r10)
decq %r14
jne 0x17599
decl %edx
xorl %eax, %eax
cmpl %ecx, %edx
jle 0x176c6
movsd (%r10), %xmm0
movslq 0x20(%rsp), %r15
movslq %edx, %rcx
movq %rsi, %r14
imulq %r9, %r14
shlq $0x3, %r15
leaq (%r15,%r14,8), %rdx
shlq $0x3, %r11
leaq (%r11,%r14,8), %rbx
shlq $0x3, %r8
leaq (%r8,%r14,8), %r14
subq %r9, %rcx
incq %r9
imulq %rsi, %r9
shlq $0x3, %rsi
leaq (%r15,%r9,8), %r15
leaq (%r11,%r9,8), %r11
leaq (%r8,%r9,8), %r8
movsd 0xda6ad(%rip), %xmm1    # 0xf1cd0
movsd 0xdb04d(%rip), %xmm2    # 0xf2678
movsd (%rdi,%r8), %xmm3
movsd (%rdi,%rbx), %xmm4
subsd (%rdi,%r14), %xmm3
addsd (%rdi,%r11), %xmm4
movsd (%rdi,%rdx), %xmm5
mulsd %xmm3, %xmm4
addsd (%rdi,%r15), %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm1, %xmm4
mulsd %xmm3, %xmm5
mulsd %xmm3, %xmm5
divsd %xmm2, %xmm5
addsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movsd %xmm0, (%r10)
addq %rsi, %rdi
decq %rcx
jne 0x1762b
jmp 0x176c6
movq 0x30(%rsp), %rbx
leaq 0xdb9c6(%rip), %r14     # 0xf304e
leaq 0xdb9ec(%rip), %r15     # 0xf307b
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x5fe, %r8d            # imm = 0x5FE
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x5fe, %r8d            # imm = 0x5FE
xorl %eax, %eax
callq 0x8550
movl $0x1, %eax
popq %rbx
popq %r14
popq %r15
retq