// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/fourier.c
// Function: fourier_sigmas
int fourier_sigmas(
                   struct fourier * pfo,
                   double R,
                   double * lnpk_l,
                   double * ddlnpk_l,
                   int k_size,
                   double k_per_decade,
                   enum out_sigmas sigma_output,
                   double * result
                   ) {
  double pk, lnpk;

  double * array_for_sigma;
  int index_num;
  int index_x;
  int index_y;
  int index_ddy;
  int i=0;
  int integrand_size;
  int last_index=0;

  double k,W,W_prime,x,t;

  /** - allocate temporary array for an integral over y(x) */

  class_define_index(index_x,  _TRUE_,i,1); // index for x
  class_define_index(index_y,  _TRUE_,i,1); // index for integrand
  class_define_index(index_ddy,_TRUE_,i,1); // index for its second derivative (spline method)
  index_num=i;                              // number of columns in the array

  integrand_size=(int)(log(pfo->k[k_size-1]/pfo->k[0])/log(10.)*k_per_decade)+1;
  class_alloc(array_for_sigma,
              integrand_size*index_num*sizeof(double),
              pfo->error_message);

  /** - fill the array with values of k and of the integrand */

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

    k=pfo->k[0]*pow(10.,i/k_per_decade);

    if (i==0) {
      pk = exp(lnpk_l[0]);
    }
    else {
      class_call(array_interpolate_spline(
                                          pfo->ln_k,
                                          k_size,
                                          lnpk_l,
                                          ddlnpk_l,
                                          1,
                                          log(k),
                                          &last_index,
                                          &lnpk,
                                          1,
                                          pfo->error_message),
                 pfo->error_message,
                 pfo->error_message);

      pk = exp(lnpk);
    }

    t = 1./(1.+k);
    if (i == (integrand_size-1)) k *= 0.9999999; // to prevent rounding error leading to k being bigger than maximum value
    x=k*R;

    switch (sigma_output) {

    case out_sigma:
      if (x<0.01)
        W = 1.-x*x/10.;
      else
        W = 3./x/x/x*(sin(x)-x*cos(x));
      array_for_sigma[(integrand_size-1-i)*index_num+index_x] = t;
      array_for_sigma[(integrand_size-1-i)*index_num+index_y] = k*k*k*pk*W*W/(t*(1.-t));
      break;

    case out_sigma_prime:
      if (x<0.01) {
        W = 1.-x*x/10.;
        W_prime = -0.2*x;
      }
      else {
        W = 3./x/x/x*(sin(x)-x*cos(x));
        W_prime = 3./x/x*sin(x)-9./x/x/x/x*(sin(x)-x*cos(x));
      }
      array_for_sigma[(integrand_size-1-i)*index_num+index_x] = t;
      array_for_sigma[(integrand_size-1-i)*index_num+index_y] = k*k*k*pk*2.*k*W*W_prime/(t*(1.-t));
      break;

    case out_sigma_disp:
      if (x<0.01)
        W = 1.-x*x/10.;
      else
        W = 3./x/x/x*(sin(x)-x*cos(x));
      array_for_sigma[(integrand_size-1-i)*index_num+index_x] = k;
      array_for_sigma[(integrand_size-1-i)*index_num+index_y] = -pk*W*W;
      break;
    }
  }

  /** - spline the integrand */

  class_call(array_spline(array_for_sigma,
                          index_num,
                          integrand_size,
                          index_x,
                          index_y,
                          index_ddy,
                          _SPLINE_EST_DERIV_,
                          pfo->error_message),
             pfo->error_message,
             pfo->error_message);

  /** - integrate */

  class_call(array_integrate_all_trapzd_or_spline(array_for_sigma,
                                                  index_num,
                                                  integrand_size,
                                                  0, //integrand_size-1,
                                                  index_x,
                                                  index_y,
                                                  index_ddy,
                                                  result,
                                                  pfo->error_message),
             pfo->error_message,
             pfo->error_message);

  /** - preperly normalize the final result */

  switch (sigma_output) {

  case out_sigma:
    *result = sqrt(*result/(2.*_PI_*_PI_));
    break;

  case out_sigma_prime:
    *result = *result/(2.*_PI_*_PI_);
    break;

  case out_sigma_disp:
    *result = sqrt(*result/(2.*_PI_*_PI_*3.));
    break;
  }

  /** - free allocated array */

  free(array_for_sigma);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8a8, %rsp            # imm = 0x8A8
movq %r9, %r13
movl %r8d, %ebp
movsd %xmm1, 0x60(%rsp)
movq %rdx, 0x78(%rsp)
movq %rsi, %r12
movsd %xmm0, 0x90(%rsp)
movq %rdi, %r14
movl $0x0, 0x4c(%rsp)
movq 0x78(%rdi), %rax
movl %ecx, 0x48(%rsp)
movslq %ecx, %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
divsd (%rax), %xmm0
callq 0x82c0
divsd 0x72ddd(%rip), %xmm0    # 0x112488
mulsd 0x60(%rsp), %xmm0
cvttsd2si %xmm0, %r15d
leal 0x1(%r15), %eax
movq %rax, 0x50(%rsp)
leal (%rax,%rax,2), %eax
movslq %eax, %rbx
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x8460
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x9fb93
movq %r13, 0x68(%rsp)
testl %r15d, %r15d
js 0x9fb10
leaq 0x192(%r14), %rax
movq %rax, 0x58(%rsp)
movl %r15d, %eax
movl 0x50(%rsp), %ecx
movq %rcx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,8), %r13
xorl %r15d, %r15d
movq 0x78(%r14), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
divsd 0x60(%rsp), %xmm1
movsd 0x4f0ac(%rip), %xmm0    # 0xee7f0
callq 0x8620
mulsd 0x20(%rsp), %xmm0
movq %r12, %rcx
testq %r15, %r15
movsd %xmm0, 0x20(%rsp)
je 0x9f7b4
movq 0x80(%r14), %rbx
movsd 0x20(%rsp), %xmm0
callq 0x82c0
subq $0x8, %rsp
movq %rbx, %rdi
movl 0x50(%rsp), %esi
movq %r12, %rdx
movq 0x80(%rsp), %rcx
movl $0x1, %r8d
leaq 0x54(%rsp), %r9
pushq 0x60(%rsp)
pushq $0x1
leaq 0xb0(%rsp), %rbx
pushq %rbx
callq 0x18071
addq $0x20, %rsp
movq %rbx, %rcx
cmpl $0x1, %eax
je 0x9fc5b
movsd (%rcx), %xmm0
callq 0x8670
movapd %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
movq 0x88(%rsp), %rbx
movapd %xmm0, %xmm3
mulsd 0x7bb3d(%rip), %xmm3    # 0x11b318
subq %r15, %rbx
je 0x9f7e4
movapd %xmm0, %xmm3
movapd %xmm3, %xmm4
mulsd 0x90(%rsp), %xmm4
cmpl $0x2, %ebp
movsd 0x4ea64(%rip), %xmm1    # 0xee260
je 0x9f86d
addsd %xmm1, %xmm0
movapd %xmm1, %xmm5
divsd %xmm0, %xmm5
cmpl $0x1, %ebp
je 0x9f83e
testl %ebp, %ebp
jne 0x9fafb
movsd 0x517a1(%rip), %xmm0    # 0xf0fc0
ucomisd %xmm4, %xmm0
jbe 0x9fa46
mulsd %xmm4, %xmm4
divsd 0x51c73(%rip), %xmm4    # 0xf14a8
addsd %xmm1, %xmm4
jmp 0x9fabf
movsd 0x5177a(%rip), %xmm0    # 0xf0fc0
ucomisd %xmm4, %xmm0
jbe 0x9f894
movapd %xmm4, %xmm6
mulsd %xmm4, %xmm6
divsd 0x51c4c(%rip), %xmm6    # 0xf14a8
addsd %xmm1, %xmm6
mulsd 0x4ea18(%rip), %xmm4    # 0xee280
jmp 0x9f98b
movsd 0x5174b(%rip), %xmm0    # 0xf0fc0
ucomisd %xmm4, %xmm0
jbe 0x9f9bf
mulsd %xmm4, %xmm4
divsd 0x51c1d(%rip), %xmm4    # 0xf14a8
addsd %xmm1, %xmm4
jmp 0x9fa24
movsd 0x4fde4(%rip), %xmm0    # 0xef680
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x40(%rsp)
divsd %xmm4, %xmm0
movsd %xmm0, 0x38(%rsp)
movapd %xmm4, %xmm0
movapd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x18(%rsp)
movsd %xmm4, (%rsp)
movsd %xmm5, 0x10(%rsp)
callq 0x80a0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x86a0
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm2
subsd %xmm0, %xmm2
mulsd 0x38(%rsp), %xmm2
movsd %xmm2, 0x8(%rsp)
movapd %xmm1, %xmm0
callq 0x80a0
movsd %xmm0, 0x38(%rsp)
movsd (%rsp), %xmm0
callq 0x80a0
movsd %xmm0, 0x70(%rsp)
movsd (%rsp), %xmm0
callq 0x86a0
movsd 0x8(%rsp), %xmm6
movsd 0x10(%rsp), %xmm5
movsd 0x18(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
movsd 0x4e914(%rip), %xmm1    # 0xee260
movsd (%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x70(%rsp), %xmm7
subsd %xmm0, %xmm7
movsd 0x72bb9(%rip), %xmm0    # 0x112520
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
mulsd %xmm7, %xmm0
movsd 0x38(%rsp), %xmm4
mulsd 0x40(%rsp), %xmm4
addsd %xmm0, %xmm4
leaq (%rbx,%rbx,2), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movsd %xmm5, (%r13)
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm0, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm6, %xmm0
jmp 0x9fae6
movsd 0x4fcb9(%rip), %xmm0    # 0xef680
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x10(%rsp)
movapd %xmm4, %xmm0
movapd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x18(%rsp)
movsd %xmm4, (%rsp)
callq 0x80a0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x86a0
movsd 0x18(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
mulsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm4
subsd %xmm0, %xmm4
mulsd 0x10(%rsp), %xmm4
movsd %xmm3, (%r13)
xorpd 0x4e7fe(%rip), %xmm2    # 0xee230
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm2
movq %r13, %rax
movapd %xmm2, %xmm0
jmp 0x9faf6
movsd 0x4fc32(%rip), %xmm0    # 0xef680
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm4, %xmm0
movapd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x18(%rsp)
movsd %xmm4, (%rsp)
movsd %xmm5, 0x10(%rsp)
callq 0x80a0
movsd %xmm0, 0x40(%rsp)
movsd (%rsp), %xmm0
callq 0x86a0
movsd 0x10(%rsp), %xmm5
movsd 0x18(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
movsd 0x4e7b6(%rip), %xmm1    # 0xee260
mulsd (%rsp), %xmm0
movsd 0x40(%rsp), %xmm4
subsd %xmm0, %xmm4
mulsd 0x8(%rsp), %xmm4
leaq (%rbx,%rbx,2), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movsd %xmm5, (%r13)
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
subsd %xmm5, %xmm1
mulsd %xmm5, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rax)
incq %r15
addq $-0x18, %r13
cmpq %r15, 0x80(%rsp)
jne 0x9f720
addq $0x192, %r14            # imm = 0x192
movl $0x1, %ebx
movq 0x30(%rsp), %r12
movq %r12, %rdi
movl $0x3, %esi
movq 0x50(%rsp), %r15
movl %r15d, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movl $0x2, %r9d
pushq %r14
pushq $0x1
callq 0x1381e
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0x9fbda
leaq 0x4e894(%rip), %rsi     # 0xee3f0
leaq 0x7e4bf(%rip), %rdx     # 0x11e022
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x4e4b5(%rip), %rsi     # 0xee034
leaq 0x7e418(%rip), %rdx     # 0x11df9e
movq %r14, %rdi
movl $0xada, %ecx            # imm = 0xADA
jmp 0x9fc4f
leaq 0x4e46a(%rip), %rsi     # 0xee004
leaq 0x7e3ed(%rip), %rdx     # 0x11df8e
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0x192, %r14            # imm = 0x192
leaq 0x4e471(%rip), %rsi     # 0xee034
leaq 0x7e3d4(%rip), %rdx     # 0x11df9e
movq %r14, %rdi
movl $0xa8b, %ecx            # imm = 0xA8B
movq %r15, %r8
jmp 0x9fc9c
subq $0x8, %rsp
movl $0x1, %ebx
movq %r12, %rdi
movl $0x3, %esi
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
pushq %r14
movq 0x78(%rsp), %r15
pushq %r15
pushq $0x2
callq 0x176d4
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0x9fcbc
leaq 0x4e7d3(%rip), %rsi     # 0xee3f0
leaq 0x7e46b(%rip), %rdx     # 0x11e08f
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x4e3f4(%rip), %rsi     # 0xee034
leaq 0x7e357(%rip), %rdx     # 0x11df9e
movq %r14, %rdi
movl $0xae8, %ecx            # imm = 0xAE8
movq %r15, %r8
xorl %eax, %eax
callq 0x30af0
jmp 0x9fca8
leaq 0x4e78e(%rip), %rsi     # 0xee3f0
leaq 0x7e344(%rip), %rdx     # 0x11dfad
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x58(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x4e3aa(%rip), %rsi     # 0xee034
leaq 0x7e30d(%rip), %rdx     # 0x11df9e
movq %r14, %rdi
movl $0xaa3, %ecx            # imm = 0xAA3
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %ebx
movl %ebx, %eax
addq $0x8a8, %rsp            # imm = 0x8A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %ebp
je 0x9fce8
cmpl $0x1, %ebp
je 0x9fcd9
testl %ebp, %ebp
jne 0x9fd0f
movsd (%r15), %xmm0
divsd 0x7b651(%rip), %xmm0    # 0x11b328
jmp 0x9fcf5
movsd (%r15), %xmm0
divsd 0x7b642(%rip), %xmm0    # 0x11b328
jmp 0x9fd0a
movsd (%r15), %xmm0
divsd 0x7b62b(%rip), %xmm0    # 0x11b320
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x9fd05
sqrtsd %xmm0, %xmm0
jmp 0x9fd0a
callq 0x82b0
movsd %xmm0, (%r15)
movq %r12, %rdi
callq 0x8410
xorl %ebx, %ebx
jmp 0x9fca8