// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
pushq %rax
testl %ecx, %ecx
sets %al
cmpl %edx, %ecx
setge %r10b
orb %al, %r10b
jne 0x1583b
movq 0x38(%rsp), %rax
movl 0x30(%rsp), %r11d
movslq %esi, %r10
movslq %r8d, %r8
movslq %r9d, %r9
movl %ecx, %ecx
leaq (%rdi,%r8,8), %r15
leaq (%rdi,%r9,8), %rbx
leaq (,%r10,8), %rsi
xorpd %xmm0, %xmm0
movsd 0xd0545(%rip), %xmm1    # 0xe5cb0
movq %rcx, %r14
movsd %xmm0, (%rax)
subq $0x1, %r14
jb 0x157a0
movsd (%r15,%rsi), %xmm2
subsd (%r15), %xmm2
addq %rsi, %r15
movsd (%rbx), %xmm3
addsd (%rbx,%rsi), %xmm3
addq %rsi, %rbx
mulsd %xmm2, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm3, %xmm0
jmp 0x1576e
decl %edx
movslq %edx, %rdx
movslq %r11d, %r15
movq %r10, %r14
imulq %rcx, %r14
shlq $0x3, %r15
leaq (%r15,%r14,8), %r11
shlq $0x3, %r9
leaq (%r9,%r14,8), %rbx
shlq $0x3, %r8
leaq (%r8,%r14,8), %r14
leaq 0x1(%rcx), %r12
imulq %r10, %r12
leaq (%r15,%r12,8), %r10
leaq (%r9,%r12,8), %r9
leaq (%r8,%r12,8), %r8
movsd 0xd0e75(%rip), %xmm2    # 0xe6658
cmpq %rdx, %rcx
jge 0x15837
incq %rcx
movsd (%rdi,%r8), %xmm3
subsd (%rdi,%r14), %xmm3
movsd (%rdi,%rbx), %xmm4
addsd (%rdi,%r9), %xmm4
mulsd %xmm3, %xmm4
mulsd %xmm1, %xmm4
movsd (%rdi,%r11), %xmm5
addsd (%rdi,%r10), %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm3, %xmm5
divsd %xmm2, %xmm5
addsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movsd %xmm0, (%rax)
addq %rsi, %rdi
jmp 0x157e3
xorl %eax, %eax
jmp 0x15883
movq 0x40(%rsp), %rbx
leaq 0xd17d7(%rip), %r14     # 0xe701e
leaq 0xd17fd(%rip), %r15     # 0xe704b
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movl $0x5fe, %r8d            # imm = 0x5FE
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
movl $0x5fe, %r8d            # imm = 0x5FE
xorl %eax, %eax
callq 0x8580
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq