// File: /workspace/github_c_makefile_star2_O3/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 0x1775a
movq 0x28(%rsp), %r10
movq $0x0, (%r10)
movl %ecx, %r11d
movslq %esi, %rsi
movslq %r8d, %r8
movslq %r9d, %r9
testl %ecx, %ecx
je 0x177a9
leaq (%rdi,%r8,8), %r15
leaq (%rdi,%r9,8), %rax
leaq (,%rsi,8), %rbx
xorpd %xmm0, %xmm0
movsd 0xd75ab(%rip), %xmm1    # 0xeecd0
movq %r11, %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 0x17728
jmp 0x177ad
movq 0x30(%rsp), %rbx
leaq 0xd88f8(%rip), %r14     # 0xf005e
leaq 0xd891e(%rip), %r15     # 0xf008b
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
jmp 0x17859
xorpd %xmm0, %xmm0
decl %edx
xorl %eax, %eax
cmpl %ecx, %edx
jle 0x17859
movslq 0x20(%rsp), %r15
movslq %edx, %rcx
movq %rsi, %r14
imulq %r11, %r14
shlq $0x3, %r15
leaq (%r15,%r14,8), %rdx
shlq $0x3, %r9
leaq (%r9,%r14,8), %rbx
shlq $0x3, %r8
leaq (%r8,%r14,8), %r14
subq %r11, %rcx
incq %r11
imulq %rsi, %r11
shlq $0x3, %rsi
leaq (%r15,%r11,8), %r15
leaq (%r9,%r11,8), %r9
leaq (%r8,%r11,8), %r8
movsd 0xd74ce(%rip), %xmm1    # 0xeecd0
movsd 0xd7e6e(%rip), %xmm2    # 0xef678
movsd (%rdi,%r8), %xmm3
movsd (%rdi,%rbx), %xmm4
subsd (%rdi,%r14), %xmm3
addsd (%rdi,%r9), %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 0x1780a
popq %rbx
popq %r14
popq %r15
retq