// File: /workspace/github_c_makefile_star2_O2/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 $0x8c8, %rsp            # imm = 0x8C8
movq %r9, %r14
movl %r8d, %r12d
movsd %xmm1, 0x68(%rsp)
movq %rdx, 0x90(%rsp)
movq %rsi, 0x70(%rsp)
movsd %xmm0, 0xa8(%rsp)
movq %rdi, %r13
andl $0x0, 0x64(%rsp)
movq 0x78(%rdi), %rax
movl %ecx, 0x60(%rsp)
movslq %ecx, %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
divsd (%rax), %xmm0
callq 0x82e0
divsd 0x6ec3c(%rip), %xmm0    # 0x109328
mulsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %ebx
leal 0x1(%rbx), %ebp
leal (%rbp,%rbp,2), %eax
movslq %eax, %r15
shlq $0x3, %r15
movq %r15, %rdi
callq 0x8490
testq %rax, %rax
je 0x9abfc
movq %rbp, 0x80(%rsp)
movq %r14, 0x78(%rsp)
movq %r13, 0xa0(%rsp)
leaq 0x192(%r13), %rcx
movq %rcx, 0x18(%rsp)
movslq %ebx, %rcx
movl %ebx, %edx
movq %rdx, 0x98(%rsp)
movq %rcx, 0xb0(%rsp)
imulq $0x18, %rcx, %r13
movq %rax, 0x58(%rsp)
addq %rax, %r13
xorl %ebp, %ebp
movq 0xb0(%rsp), %r14
subq %rbp, %r14
jl 0x9ab7f
movl %r12d, %ebx
movq 0xa0(%rsp), %r15
movq 0x78(%r15), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
cvtsi2sd %ebp, %xmm1
divsd 0x68(%rsp), %xmm1
movsd 0x4b05b(%rip), %xmm0    # 0xe57f0
callq 0x8650
mulsd 0x30(%rsp), %xmm0
movq 0x70(%rsp), %rcx
testq %rbp, %rbp
movsd %xmm0, 0x30(%rsp)
je 0x9a810
movq 0x80(%r15), %r15
movsd 0x30(%rsp), %xmm0
callq 0x82e0
subq $0x8, %rsp
movq %r15, %rdi
pushq $0x1
popq %r8
movq 0x20(%rsp), %r12
movl 0x68(%rsp), %esi
movq 0x78(%rsp), %rdx
movq 0x98(%rsp), %rcx
movl %r8d, 0x10(%rsp)
leaq 0x6c(%rsp), %r9
pushq %r12
pushq $0x1
leaq 0xd0(%rsp), %r15
pushq %r15
callq 0x1604b
addq $0x20, %rsp
movq %r15, %rcx
cmpl $0x1, %eax
je 0x9ac48
movsd (%rcx), %xmm0
callq 0x86a0
movapd %xmm0, %xmm2
movsd 0x30(%rsp), %xmm0
movapd %xmm0, %xmm3
mulsd 0x77989(%rip), %xmm3    # 0x1121b8
cmpq %rbp, 0x98(%rsp)
je 0x9a83d
movapd %xmm0, %xmm3
movapd %xmm3, %xmm4
mulsd 0xa8(%rsp), %xmm4
movl %ebx, %r12d
cmpl $0x2, %ebx
movsd 0x4aa08(%rip), %xmm1    # 0xe5260
je 0x9a8cb
addsd %xmm1, %xmm0
movapd %xmm1, %xmm5
divsd %xmm0, %xmm5
cmpl $0x1, %r12d
je 0x9a89c
testl %r12d, %r12d
jne 0x9ab73
movsd 0x4d703(%rip), %xmm0    # 0xe7f80
ucomisd %xmm4, %xmm0
jbe 0x9aac5
mulsd %xmm4, %xmm4
divsd 0x4dbd5(%rip), %xmm4    # 0xe8468
addsd %xmm1, %xmm4
jmp 0x9ab41
movsd 0x4d6dc(%rip), %xmm0    # 0xe7f80
ucomisd %xmm4, %xmm0
jbe 0x9a8f2
movapd %xmm4, %xmm6
mulsd %xmm4, %xmm6
divsd 0x4dbae(%rip), %xmm6    # 0xe8468
addsd %xmm1, %xmm6
mulsd 0x4a9ba(%rip), %xmm4    # 0xe5280
jmp 0x9a9f5
movsd 0x4d6ad(%rip), %xmm0    # 0xe7f80
ucomisd %xmm4, %xmm0
jbe 0x9aa35
mulsd %xmm4, %xmm4
divsd 0x4db7f(%rip), %xmm4    # 0xe8468
addsd %xmm1, %xmm4
jmp 0x9aa9d
movsd 0x4be4e(%rip), %xmm0    # 0xe6748
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x50(%rsp)
divsd %xmm4, %xmm0
movsd %xmm0, 0x48(%rsp)
movapd %xmm4, %xmm0
movapd %xmm2, 0x30(%rsp)
movsd %xmm3, 0x28(%rsp)
movsd %xmm4, 0x8(%rsp)
movsd %xmm5, 0x20(%rsp)
callq 0x80a0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x86d0
movsd 0x8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
mulsd 0x48(%rsp), %xmm2
movsd %xmm2, 0x10(%rsp)
movapd %xmm1, %xmm0
callq 0x80a0
movsd %xmm0, 0x48(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x80a0
movsd %xmm0, 0x88(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x86d0
movsd 0x10(%rsp), %xmm6
movsd 0x20(%rsp), %xmm5
movsd 0x28(%rsp), %xmm3
movapd 0x30(%rsp), %xmm2
movsd 0x4a8ae(%rip), %xmm1    # 0xe5260
movsd 0x8(%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x88(%rsp), %xmm7
subsd %xmm0, %xmm7
movsd 0x6e9ef(%rip), %xmm0    # 0x1093c0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
mulsd %xmm7, %xmm0
movsd 0x48(%rsp), %xmm4
mulsd 0x50(%rsp), %xmm4
addsd %xmm0, %xmm4
imulq $0x18, %r14, %rax
addq 0x58(%rsp), %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
mulsd %xmm4, %xmm0
subsd %xmm5, %xmm1
mulsd %xmm5, %xmm1
divsd %xmm1, %xmm0
jmp 0x9ab6e
movsd 0x4bd0b(%rip), %xmm0    # 0xe6748
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x20(%rsp)
movapd %xmm4, %xmm0
movapd %xmm2, 0x30(%rsp)
movsd %xmm3, 0x28(%rsp)
movsd %xmm4, 0x8(%rsp)
callq 0x80a0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x86d0
movsd 0x28(%rsp), %xmm3
movapd 0x30(%rsp), %xmm2
mulsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm4
subsd %xmm0, %xmm4
mulsd 0x20(%rsp), %xmm4
imulq $0x18, %r14, %rax
addq 0x58(%rsp), %rax
movsd %xmm3, (%r13)
xorpd 0x4a77c(%rip), %xmm2    # 0xe5230
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm2
movapd %xmm2, %xmm0
jmp 0x9ab6e
movsd 0x4bc7b(%rip), %xmm0    # 0xe6748
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x10(%rsp)
movapd %xmm4, %xmm0
movapd %xmm2, 0x30(%rsp)
movsd %xmm3, 0x28(%rsp)
movsd %xmm4, 0x8(%rsp)
movsd %xmm5, 0x20(%rsp)
callq 0x80a0
movsd %xmm0, 0x50(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x86d0
movsd 0x20(%rsp), %xmm5
movsd 0x28(%rsp), %xmm3
movapd 0x30(%rsp), %xmm2
movsd 0x4a735(%rip), %xmm1    # 0xe5260
mulsd 0x8(%rsp), %xmm0
movsd 0x50(%rsp), %xmm4
subsd %xmm0, %xmm4
mulsd 0x10(%rsp), %xmm4
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
movq %r13, %rax
movsd %xmm0, 0x8(%rax)
incq %rbp
addq $-0x18, %r13
jmp 0x9a759
pushq $0x3
popq %rsi
pushq $0x1
popq %r8
pushq $0x2
popq %r9
movq 0x58(%rsp), %r14
movq %r14, %rdi
movq 0x80(%rsp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
movl %r8d, 0x8(%rsp)
pushq 0x18(%rsp)
pushq $0x1
callq 0x11b09
popq %rcx
popq %rdx
cmpl $0x1, %eax
jne 0x9ac88
leaq 0x4a830(%rip), %rsi     # 0xe53f0
leaq 0x7a2fb(%rip), %rdx     # 0x114ec2
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4a44c(%rip), %rsi     # 0xe5034
leaq 0x7a24f(%rip), %rdx     # 0x114e3e
movq %r14, %rdi
movl $0xada, %ecx            # imm = 0xADA
jmp 0x9acfd
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
leaq 0x4a3fa(%rip), %rsi     # 0xe5004
leaq 0x7a21d(%rip), %rdx     # 0x114e2e
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x192, %r13            # imm = 0x192
leaq 0x4a400(%rip), %rsi     # 0xe5034
leaq 0x7a203(%rip), %rdx     # 0x114e3e
movq %r13, %rdi
movl $0xa8b, %ecx            # imm = 0xA8B
jmp 0x9acfd
leaq 0x4a7a1(%rip), %rsi     # 0xe53f0
leaq 0x7a1f7(%rip), %rdx     # 0x114e4d
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4a3bd(%rip), %rsi     # 0xe5034
leaq 0x7a1c0(%rip), %rdx     # 0x114e3e
movq %r14, %rdi
movl $0xaa3, %ecx            # imm = 0xAA3
jmp 0x9acfd
subq $0x8, %rsp
pushq $0x3
popq %rsi
pushq $0x1
popq %r9
movq %r14, %rdi
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %r9d, 0x10(%rsp)
pushq 0x20(%rsp)
movq 0x88(%rsp), %rbx
pushq %rbx
pushq $0x2
callq 0x1571e
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0x9ad1d
leaq 0x4a72a(%rip), %rsi     # 0xe53f0
leaq 0x7a262(%rip), %rdx     # 0x114f2f
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x4a346(%rip), %rsi     # 0xe5034
leaq 0x7a149(%rip), %rdx     # 0x114e3e
movq %r14, %rdi
movl $0xae8, %ecx            # imm = 0xAE8
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
movl 0x8(%rsp), %eax
addq $0x8c8, %rsp            # imm = 0x8C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r12d
je 0x9ad4a
cmpl $0x1, %r12d
je 0x9ad3c
testl %r12d, %r12d
jne 0x9ad6f
movsd (%rbx), %xmm0
divsd 0x7748e(%rip), %xmm0    # 0x1121c8
jmp 0x9ad56
movsd (%rbx), %xmm0
divsd 0x77480(%rip), %xmm0    # 0x1121c8
jmp 0x9ad6b
movsd (%rbx), %xmm0
divsd 0x7746a(%rip), %xmm0    # 0x1121c0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x9ad66
sqrtsd %xmm0, %xmm0
jmp 0x9ad6b
callq 0x82d0
movsd %xmm0, (%rbx)
movq %r14, %rdi
callq 0x8430
movl $0x0, 0x8(%rsp)
jmp 0x9ad07