// File: /workspace/github_c_makefile_star2_O1/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, 0x68(%rsp)
movq %rdx, 0x80(%rsp)
movq %rsi, %rbx
movsd %xmm0, 0x90(%rsp)
movq %rdi, %r14
movl $0x0, 0x54(%rsp)
movq 0x78(%rdi), %rax
movl %ecx, 0x50(%rsp)
movslq %ecx, %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
divsd (%rax), %xmm0
callq 0x82c0
divsd 0x72ec8(%rip), %xmm0    # 0x115448
mulsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %r12d
leal 0x1(%r12), %eax
movq %rax, 0x60(%rsp)
leal (%rax,%rax,2), %eax
movslq %eax, %r15
shlq $0x3, %r15
movq %r15, %rdi
callq 0x8460
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0xa2a5b
movq %r13, 0x70(%rsp)
testl %r12d, %r12d
js 0xa29d8
leaq 0x192(%r14), %rax
movq %rax, 0x58(%rsp)
movl %r12d, %eax
movq %rax, 0x88(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,8), %r13
xorl %r12d, %r12d
movq 0x78(%r14), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
divsd 0x68(%rsp), %xmm1
movsd 0x4f1e2(%rip), %xmm0    # 0xf17f0
callq 0x8620
mulsd 0x20(%rsp), %xmm0
movq %rbx, %rcx
testq %r12, %r12
movsd %xmm0, 0x20(%rsp)
je 0xa267f
movq 0x80(%r14), %r15
movsd 0x20(%rsp), %xmm0
callq 0x82c0
subq $0x8, %rsp
movq %r15, %rdi
movl 0x58(%rsp), %esi
movq %rbx, %rdx
movq 0x88(%rsp), %rcx
movl $0x1, %r8d
leaq 0x5c(%rsp), %r9
pushq 0x60(%rsp)
pushq $0x1
leaq 0xb0(%rsp), %r15
pushq %r15
callq 0x17ee6
addq $0x20, %rsp
movq %r15, %rcx
cmpl $0x1, %eax
je 0xa2b24
movsd (%rcx), %xmm0
callq 0x8670
movapd %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
movq 0x88(%rsp), %r15
movapd %xmm0, %xmm3
mulsd 0x7bc32(%rip), %xmm3    # 0x11e2d8
subq %r12, %r15
je 0xa26af
movapd %xmm0, %xmm3
movapd %xmm3, %xmm4
mulsd 0x90(%rsp), %xmm4
cmpl $0x2, %ebp
movsd 0x4eb99(%rip), %xmm1    # 0xf1260
je 0xa2738
addsd %xmm1, %xmm0
movapd %xmm1, %xmm5
divsd %xmm0, %xmm5
cmpl $0x1, %ebp
je 0xa2709
testl %ebp, %ebp
jne 0xa29c6
movsd 0x518c6(%rip), %xmm0    # 0xf3fb0
ucomisd %xmm4, %xmm0
jbe 0xa2911
mulsd %xmm4, %xmm4
divsd 0x51d98(%rip), %xmm4    # 0xf4498
addsd %xmm1, %xmm4
jmp 0xa298a
movsd 0x5189f(%rip), %xmm0    # 0xf3fb0
ucomisd %xmm4, %xmm0
jbe 0xa275f
movapd %xmm4, %xmm6
mulsd %xmm4, %xmm6
divsd 0x51d71(%rip), %xmm6    # 0xf4498
addsd %xmm1, %xmm6
mulsd 0x4eb4d(%rip), %xmm4    # 0xf1280
jmp 0xa2856
movsd 0x51870(%rip), %xmm0    # 0xf3fb0
ucomisd %xmm4, %xmm0
jbe 0xa288a
mulsd %xmm4, %xmm4
divsd 0x51d42(%rip), %xmm4    # 0xf4498
addsd %xmm1, %xmm4
jmp 0xa28ef
movsd 0x4ff19(%rip), %xmm0    # 0xf2680
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, 0x48(%rsp)
divsd %xmm4, %xmm0
movsd %xmm0, 0x40(%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 0x40(%rsp), %xmm2
movsd %xmm2, 0x8(%rsp)
movapd %xmm1, %xmm0
callq 0x80a0
movsd %xmm0, 0x40(%rsp)
movsd (%rsp), %xmm0
callq 0x80a0
movsd %xmm0, 0x78(%rsp)
movsd (%rsp), %xmm0
callq 0x86a0
movsd 0x8(%rsp), %xmm6
movsd 0x10(%rsp), %xmm5
movsd 0x18(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
movsd 0x4ea49(%rip), %xmm1    # 0xf1260
movsd (%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x78(%rsp), %xmm7
subsd %xmm0, %xmm7
movsd 0x72cae(%rip), %xmm0    # 0x1154e0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm0
mulsd %xmm7, %xmm0
movsd 0x40(%rsp), %xmm4
mulsd 0x48(%rsp), %xmm4
addsd %xmm0, %xmm4
leaq (%r15,%r15,2), %rax
movq 0x38(%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 0xa29b1
movsd 0x4fdee(%rip), %xmm0    # 0xf2680
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 0x4e933(%rip), %xmm2    # 0xf1230
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm2
movq %r13, %rax
movapd %xmm2, %xmm0
jmp 0xa29c1
movsd 0x4fd67(%rip), %xmm0    # 0xf2680
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, 0x48(%rsp)
movsd (%rsp), %xmm0
callq 0x86a0
movsd 0x10(%rsp), %xmm5
movsd 0x18(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
movsd 0x4e8eb(%rip), %xmm1    # 0xf1260
mulsd (%rsp), %xmm0
movsd 0x48(%rsp), %xmm4
subsd %xmm0, %xmm4
mulsd 0x8(%rsp), %xmm4
leaq (%r15,%r15,2), %rax
movq 0x38(%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 %r12
addq $-0x18, %r13
cmpq %r12, 0x60(%rsp)
jne 0xa25ea
addq $0x192, %r14            # imm = 0x192
movl $0x1, %ebx
movq 0x38(%rsp), %r12
movq %r12, %rdi
movl $0x3, %esi
movq 0x60(%rsp), %r15
movl %r15d, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movl $0x2, %r9d
pushq %r14
pushq $0x1
callq 0x136a5
addq $0x10, %rsp
cmpl $0x1, %eax
jne 0xa2aa0
leaq 0x4e9cc(%rip), %rsi     # 0xf13f0
leaq 0x7e5b7(%rip), %rdx     # 0x120fe2
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x4e5ed(%rip), %rsi     # 0xf1034
leaq 0x7e510(%rip), %rdx     # 0x120f5e
movq %r14, %rdi
movl $0xada, %ecx            # imm = 0xADA
jmp 0xa2b18
leaq 0x4e5a2(%rip), %rsi     # 0xf1004
leaq 0x7e4e5(%rip), %rdx     # 0x120f4e
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x192, %r14            # imm = 0x192
leaq 0x4e5a8(%rip), %rsi     # 0xf1034
leaq 0x7e4cb(%rip), %rdx     # 0x120f5e
movq %r14, %rdi
movl $0xa8b, %ecx            # imm = 0xA8B
jmp 0xa2b62
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 0x80(%rsp), %r15
pushq %r15
pushq $0x2
callq 0x17545
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0xa2b85
leaq 0x4e90a(%rip), %rsi     # 0xf13f0
leaq 0x7e562(%rip), %rdx     # 0x12104f
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x4e52b(%rip), %rsi     # 0xf1034
leaq 0x7e44e(%rip), %rdx     # 0x120f5e
movq %r14, %rdi
movl $0xae8, %ecx            # imm = 0xAE8
movq %r15, %r8
xorl %eax, %eax
callq 0x30c2c
jmp 0xa2b71
leaq 0x4e8c5(%rip), %rsi     # 0xf13f0
leaq 0x7e43b(%rip), %rdx     # 0x120f6d
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x58(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x4e4e1(%rip), %rsi     # 0xf1034
leaq 0x7e404(%rip), %rdx     # 0x120f5e
movq %r14, %rdi
movl $0xaa3, %ecx            # imm = 0xAA3
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
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 0xa2bb1
cmpl $0x1, %ebp
je 0xa2ba2
testl %ebp, %ebp
jne 0xa2bd8
movsd (%r15), %xmm0
divsd 0x7b748(%rip), %xmm0    # 0x11e2e8
jmp 0xa2bbe
movsd (%r15), %xmm0
divsd 0x7b739(%rip), %xmm0    # 0x11e2e8
jmp 0xa2bd3
movsd (%r15), %xmm0
divsd 0x7b722(%rip), %xmm0    # 0x11e2e0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xa2bce
sqrtsd %xmm0, %xmm0
jmp 0xa2bd3
callq 0x82b0
movsd %xmm0, (%r15)
movq %r12, %rdi
callq 0x8410
xorl %ebx, %ebx
jmp 0xa2b71