// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq 0x50(%rsp), %rax
movq 0x48(%rsp), %rax
movl 0x40(%rsp), %eax
movq %rdi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movl %edx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movl %r9d, 0x14(%rsp)
cmpl $0x0, 0x1c(%rsp)
jl 0x22eee
movl 0x1c(%rsp), %eax
cmpl 0x20(%rsp), %eax
jl 0x22f4d
jmp 0x22ef0
xorl %eax, %eax
movl %eax, %esi
leaq 0x1b114a(%rip), %rdx    # 0x1d4045
leaq 0x1b1170(%rip), %rcx    # 0x1d4072
movl $0x5fe, %r8d            # imm = 0x5FE
movq %rsi, %rdi
movb $0x0, %al
callq 0x8540
movl %eax, 0x4(%rsp)
movq 0x50(%rsp), %rdi
movl 0x4(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq 0x1b1119(%rip), %rdx    # 0x1d4045
leaq 0x1b113f(%rip), %rcx    # 0x1d4072
movl $0x5fe, %r8d            # imm = 0x5FE
movb $0x0, %al
callq 0x8540
movl $0x1, 0x34(%rsp)
jmp 0x23131
movq 0x48(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jge 0x23012
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
addl $0x1, %ecx
imull 0x24(%rsp), %ecx
addl 0x18(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
imull 0x24(%rsp), %ecx
addl 0x18(%rsp), %ecx
movslq %ecx, %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
imull 0x24(%rsp), %ecx
addl 0x14(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
addl $0x1, %ecx
imull 0x24(%rsp), %ecx
addl 0x14(%rsp), %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd 0x1afc8f(%rip), %xmm1   # 0x1d2c80
divsd %xmm1, %xmm0
movq 0x48(%rsp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x22f61
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl 0x20(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x23129
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
addl $0x1, %ecx
imull 0x24(%rsp), %ecx
addl 0x18(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
imull 0x24(%rsp), %ecx
addl 0x18(%rsp), %ecx
movslq %ecx, %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
imull 0x24(%rsp), %ecx
addl 0x14(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
addl $0x1, %ecx
imull 0x24(%rsp), %ecx
addl 0x14(%rsp), %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd 0x1afbd1(%rip), %xmm1   # 0x1d2c80
divsd %xmm1, %xmm0
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
imull 0x24(%rsp), %ecx
addl 0x40(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x28(%rsp), %rax
movl 0x10(%rsp), %ecx
addl $0x1, %ecx
imull 0x24(%rsp), %ecx
addl 0x40(%rsp), %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm1
mulsd 0x8(%rsp), %xmm1
mulsd 0x8(%rsp), %xmm1
mulsd 0x8(%rsp), %xmm1
movsd 0x1b058c(%rip), %xmm2   # 0x1d3690
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movq 0x48(%rsp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x2301a
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw (%rax,%rax)