// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/perturbations.c
// Function: perturbations_workspace_init
int perturbations_workspace_init(
                                 struct precision * ppr,
                                 struct background * pba,
                                 struct thermodynamics * pth,
                                 struct perturbations * ppt,
                                 int index_md,
                                 struct perturbations_workspace * ppw
                                 ) {

  /** Summary: */

  /** - define local variables */

  int index_mt=0;
  int index_ap;
  int l;

  /** - Compute maximum l_max for any multipole */;
  if (_scalars_) {
    ppw->max_l_max = MAX(ppr->l_max_g, ppr->l_max_pol_g);
    if (pba->has_ur == _TRUE_) ppw->max_l_max = MAX(ppw->max_l_max, ppr->l_max_ur);
    if ((pba->has_idr == _TRUE_) && (ppt->idr_nature == idr_free_streaming)) ppw->max_l_max = MAX(ppw->max_l_max, ppr->l_max_idr);
    if (pba->has_ncdm == _TRUE_) ppw->max_l_max = MAX(ppw->max_l_max, ppr->l_max_ncdm);
    if (pba->has_dr == _TRUE_) ppw->max_l_max = MAX(ppw->max_l_max, ppr->l_max_dr);
  }
  if (_tensors_) {
    ppw->max_l_max = MAX(ppr->l_max_g_ten, ppr->l_max_pol_g_ten);
    if (pba->has_ur == _TRUE_) ppw->max_l_max = MAX(ppw->max_l_max, ppr->l_max_ur);
    if (pba->has_ncdm == _TRUE_) ppw->max_l_max = MAX(ppw->max_l_max, ppr->l_max_ncdm);
  }

  /** - Allocate \f$ s_l\f$[ ] array for freestreaming of multipoles (see arXiv:1305.3261) and initialize
      to 1.0, which is the K=0 value. */
  class_alloc(ppw->s_l, sizeof(double)*(ppw->max_l_max+1),ppt->error_message);
  for (l=0; l<=ppw->max_l_max; l++){
    ppw->s_l[l] = 1.0;
  }

  /** - define indices of metric perturbations obeying constraint
      equations (this can be done once and for all, because the
      vector of metric perturbations is the same whatever the
      approximation scheme, unlike the vector of quantities to
      be integrated, which is allocated separately in
      perturbations_vector_init) */

  if (_scalars_) {

    /* newtonian gauge */

    if (ppt->gauge == newtonian) {
      class_define_index(ppw->index_mt_psi,_TRUE_,index_mt,1); /* psi */
      class_define_index(ppw->index_mt_phi_prime,_TRUE_,index_mt,1); /* phi' */
    }

    /* synchronous gauge (note that eta is counted in the vector of
       quantities to be integrated, while here we only consider
       quantities obeying to constraint equations) */

    if (ppt->gauge == synchronous) {
      class_define_index(ppw->index_mt_h_prime,_TRUE_,index_mt,1);       /* h' */
      class_define_index(ppw->index_mt_h_prime_prime,_TRUE_,index_mt,1); /* h'' */
      class_define_index(ppw->index_mt_eta_prime,_TRUE_,index_mt,1);     /* eta' */
      class_define_index(ppw->index_mt_alpha,_TRUE_,index_mt,1);         /* alpha = (h' + 6 tau') / (2 k**2) */
      class_define_index(ppw->index_mt_alpha_prime,_TRUE_,index_mt,1);   /* alpha' */

    }

  }

  if (_vectors_) {

    /* newtonian gauge */

    if (ppt->gauge == newtonian) {

      class_define_index(ppw->index_mt_V_prime,_TRUE_,index_mt,1);

    }

    if (ppt->gauge == synchronous) {

      class_define_index(ppw->index_mt_hv_prime_prime,_TRUE_,index_mt,1);

    }

  }

  if (_tensors_) {
    class_define_index(ppw->index_mt_gw_prime_prime,_TRUE_,index_mt,1);
  }

  ppw->mt_size = index_mt;

  /** - allocate some workspace in which we will store temporarily the
      values of background, thermodynamics, metric and source
      quantities at a given time */

  class_alloc(ppw->pvecback,pba->bg_size*sizeof(double),ppt->error_message);
  class_alloc(ppw->pvecthermo,pth->th_size*sizeof(double),ppt->error_message);
  class_alloc(ppw->pvecmetric,ppw->mt_size*sizeof(double),ppt->error_message);

  /** - count number of approximations, initialize their indices, and allocate their flags */
  index_ap=0;

  class_define_index(ppw->index_ap_tca,_TRUE_,index_ap,1);
  class_define_index(ppw->index_ap_rsa,_TRUE_,index_ap,1);

  if (_scalars_) {

    class_define_index(ppw->index_ap_ufa,pba->has_ur,index_ap,1);
    class_define_index(ppw->index_ap_ncdmfa,pba->has_ncdm,index_ap,1);
    class_define_index(ppw->index_ap_tca_idm_dr,pba->has_idr,index_ap,1);
    class_define_index(ppw->index_ap_rsa_idr,pba->has_idr,index_ap,1);
  }

  ppw->ap_size=index_ap;

  if (ppw->ap_size > 0)
    class_alloc(ppw->approx,ppw->ap_size*sizeof(int),ppt->error_message);

  /** - For definiteness, initialize approximation flags to arbitrary
      values (correct values are overwritten in
      pertub_find_approximation_switches) */

  if (_scalars_) {

    ppw->approx[ppw->index_ap_tca]=(int)tca_on;
    ppw->approx[ppw->index_ap_rsa]=(int)rsa_off;

    if (pba->has_idr == _TRUE_)
      ppw->approx[ppw->index_ap_rsa_idr]=(int)rsa_idr_off;
    if (pba->has_idr == _TRUE_)
      ppw->approx[ppw->index_ap_tca_idm_dr]=(int)tca_idm_dr_off;
    if (pth->has_idm_dr == _TRUE_)
      ppw->approx[ppw->index_ap_tca_idm_dr]=(int)tca_idm_dr_on;

    if (pba->has_ur == _TRUE_) {
      ppw->approx[ppw->index_ap_ufa]=(int)ufa_off;
    }
    if (pba->has_ncdm == _TRUE_) {
      ppw->approx[ppw->index_ap_ncdmfa]=(int)ncdmfa_off;
    }
  }

  if (_tensors_) {

    ppw->approx[ppw->index_ap_tca]=(int)tca_on;
    ppw->approx[ppw->index_ap_rsa]=(int)rsa_off;
  }

  /** - allocate fields where some of the perturbations are stored */

  if (_scalars_) {

    if ((ppt->has_density_transfers == _TRUE_) || (ppt->has_velocity_transfers == _TRUE_) || (ppt->has_source_delta_m == _TRUE_)) {

      class_alloc(ppw->delta_ncdm,pba->N_ncdm*sizeof(double),ppt->error_message);
      class_alloc(ppw->theta_ncdm,pba->N_ncdm*sizeof(double),ppt->error_message);
      class_alloc(ppw->shear_ncdm,pba->N_ncdm*sizeof(double),ppt->error_message);

    }

  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movq %r9, %r14
movq %rcx, %rbx
movq %rdx, 0x8(%rsp)
movq %rsi, %r15
movzwl 0xe(%rcx), %eax
movw %ax, 0x2(%rsp)
cmpw $0x1, %ax
jne 0x7c7fb
cmpl %r8d, 0x848(%rbx)
jne 0x7c7fb
movl 0x5b8(%rdi), %ecx
movl 0x5bc(%rdi), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4c4(%r15)
jne 0x7c786
movl 0x5c4(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
cmpw $0x1, 0x4c6(%r15)
jne 0x7c7b3
cmpl $0x0, 0x830(%rbx)
jne 0x7c7b3
movl 0x188(%r14), %eax
movl 0x5c8(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
cmpw $0x1, 0x4be(%r15)
jne 0x7c7d7
movl 0x188(%r14), %eax
movl 0x5cc(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
cmpw $0x1, 0x4ba(%r15)
jne 0x7c7fb
movl 0x188(%r14), %eax
movl 0x5c0(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
movzwl 0x12(%rbx), %ebp
cmpw $0x1, %bp
jne 0x7c867
cmpl %r8d, 0x84c(%rbx)
jne 0x7c867
movl 0x5d0(%rdi), %ecx
movl 0x5d4(%rdi), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4c4(%r15)
jne 0x7c843
movl 0x5c4(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
cmpw $0x1, 0x4be(%r15)
jne 0x7c867
movl 0x188(%r14), %eax
movl 0x5cc(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
movl %r8d, 0x4(%rsp)
movslq 0x188(%r14), %r12
leaq 0x8(,%r12,8), %rdi
callq 0x8460
movq %rax, 0x190(%r14)
testq %rax, %rax
je 0x7c99e
testl %r12d, %r12d
js 0x7c938
movq %r12, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %r12d
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
shlq $0x4, %r12
addq $0x10, %r12
movdqa 0x753c3(%rip), %xmm1    # 0xf1c80
xorl %ecx, %ecx
movdqa 0x753c9(%rip), %xmm2    # 0xf1c90
pxor %xmm2, %xmm0
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
pcmpeqd %xmm3, %xmm3
movdqa 0x75e9f(%rip), %xmm4    # 0xf2780
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %esi
notl %esi
testb $0x1, %sil
je 0x7c917
movq %rdx, (%rax,%rcx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x7c92b
movq %rdx, 0x8(%rax,%rcx)
paddq %xmm4, %xmm1
addq $0x10, %rcx
cmpq %rcx, %r12
jne 0x7c8e1
xorl %r13d, %r13d
cmpw $0x1, 0x2(%rsp)
jne 0x7c9e5
movl 0x4(%rsp), %edx
cmpl %edx, 0x848(%rbx)
jne 0x7c9e9
movl 0x83c(%rbx), %eax
xorl %r13d, %r13d
testl %eax, %eax
jne 0x7c977
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %rcx, (%r14)
movl $0x2, %r13d
cmpl $0x1, %eax
jne 0x7c9e9
movl %r13d, 0x8(%r14)
movd %r13d, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
paddd 0x911be(%rip), %xmm0    # 0x10db50
movdqu %xmm0, 0xc(%r14)
orl $0x5, %r13d
jmp 0x7c9e9
leal 0x8(,%r12,8), %ecx
leaq 0x74657(%rip), %rsi     # 0xf1004
leaq 0x9b873(%rip), %rdx     # 0x118227
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x74663(%rip), %rsi     # 0xf1034
leaq 0x9b858(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xae2, %ecx            # imm = 0xAE2
jmp 0x7ce00
movl 0x4(%rsp), %edx
cmpw $0x1, 0x10(%rbx)
jne 0x7ca15
cmpl %edx, 0x850(%rbx)
jne 0x7ca15
movl 0x83c(%rbx), %eax
testl %eax, %eax
jne 0x7ca09
movl %r13d, 0x20(%r14)
incl %r13d
cmpl $0x1, %eax
jne 0x7ca15
movl %r13d, 0x24(%r14)
incl %r13d
cmpw $0x1, %bp
jne 0x7ca2a
cmpl %edx, 0x84c(%rbx)
jne 0x7ca2a
movl %r13d, 0x1c(%r14)
incl %r13d
movl %r13d, 0x28(%r14)
movslq 0x43c(%r15), %r12
leaq (,%r12,8), %rdi
callq 0x8460
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x7cae8
movq 0x8(%rsp), %rax
movslq 0xf04(%rax), %r12
leaq (,%r12,8), %rdi
callq 0x8460
movq %rax, 0x38(%r14)
testq %rax, %rax
je 0x7cb2e
shll $0x3, %r13d
movq %r13, %rdi
callq 0x8460
movq %rax, 0x40(%r14)
testq %rax, %rax
je 0x7cb74
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x160(%r14)
movl $0x2, %r13d
cmpw $0x1, 0x2(%rsp)
jne 0x7cbb6
movl 0x4(%rsp), %r12d
cmpl %r12d, 0x848(%rbx)
jne 0x7cbfe
cmpw $0x0, 0x4c4(%r15)
je 0x7cbbd
movl $0x2, 0x170(%r14)
movl $0x3, %r13d
jmp 0x7cbc3
shll $0x3, %r12d
leaq 0x74511(%rip), %rsi     # 0xf1004
leaq 0x9b753(%rip), %rdx     # 0x11824d
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x7451a(%rip), %rsi     # 0xf1034
leaq 0x9b70f(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xb22, %ecx            # imm = 0xB22
jmp 0x7ce00
shll $0x3, %r12d
leaq 0x744cb(%rip), %rsi     # 0xf1004
leaq 0x9b71b(%rip), %rdx     # 0x11825b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x744d4(%rip), %rsi     # 0xf1034
leaq 0x9b6c9(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xb23, %ecx            # imm = 0xB23
jmp 0x7ce00
leaq 0x74489(%rip), %rsi     # 0xf1004
leaq 0x9b6e9(%rip), %rdx     # 0x11826b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x74492(%rip), %rsi     # 0xf1034
leaq 0x9b687(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xb24, %ecx            # imm = 0xB24
jmp 0x7ce00
movl 0x4(%rsp), %r12d
jmp 0x7cbfe
movl $0x2, %r13d
cmpw $0x0, 0x4be(%r15)
je 0x7cbd8
movl %r13d, 0x174(%r14)
incl %r13d
movzwl 0x4c6(%r15), %eax
testw %ax, %ax
je 0x7cbef
movl %r13d, 0x168(%r14)
incl %r13d
testw %ax, %ax
je 0x7cbfe
movl %r13d, 0x16c(%r14)
incl %r13d
movl %r13d, 0x178(%r14)
shll $0x2, %r13d
movq %r13, %rdi
callq 0x8460
movq %rax, 0x180(%r14)
testq %rax, %rax
je 0x7cdc3
cmpw $0x1, 0x2(%rsp)
jne 0x7ccc2
cmpl %r12d, 0x848(%rbx)
jne 0x7ccc2
movq 0x180(%r14), %rax
xorl %ecx, %ecx
movl %ecx, (%rax)
movslq 0x164(%r14), %rdx
movl %ecx, (%rax,%rdx,4)
cmpw $0x1, 0x4c6(%r15)
jne 0x7cc76
movslq 0x16c(%r14), %rcx
movl $0x0, (%rax,%rcx,4)
movslq 0x168(%r14), %rcx
movl $0x1, (%rax,%rcx,4)
movq 0x8(%rsp), %rcx
cmpw $0x1, 0x38(%rcx)
jne 0x7cc90
movslq 0x168(%r14), %rcx
movl $0x0, (%rax,%rcx,4)
cmpw $0x1, 0x4c4(%r15)
jne 0x7cca9
movslq 0x170(%r14), %rcx
movl $0x0, (%rax,%rcx,4)
cmpw $0x1, 0x4be(%r15)
jne 0x7ccc2
movslq 0x174(%r14), %rcx
movl $0x0, (%rax,%rcx,4)
cmpw $0x1, %bp
jne 0x7ccee
cmpl %r12d, 0x84c(%rbx)
jne 0x7ccee
movq 0x180(%r14), %rax
movslq 0x160(%r14), %rcx
xorl %edx, %edx
movl %edx, (%rax,%rcx,4)
movslq 0x164(%r14), %rcx
movl %edx, (%rax,%rcx,4)
xorl %r12d, %r12d
cmpw $0x1, 0x2(%rsp)
jne 0x7ce10
movl 0x4(%rsp), %eax
cmpl %eax, 0x848(%rbx)
jne 0x7ce10
cmpw $0x1, 0x34(%rbx)
je 0x7cd29
cmpw $0x1, 0x36(%rbx)
je 0x7cd29
cmpw $0x1, 0x87c(%rbx)
jne 0x7ce10
movslq 0x248(%r15), %r13
movq %r13, %r15
shlq $0x3, %r15
movq %r15, %rdi
callq 0x8460
movq %rax, 0xe8(%r14)
testq %rax, %rax
je 0x7ce25
movq %r15, %rdi
callq 0x8460
movq %rax, 0xf0(%r14)
testq %rax, %rax
je 0x7ce69
movq %r15, %rdi
callq 0x8460
movq %rax, 0xf8(%r14)
testq %rax, %rax
jne 0x7ce10
leal (,%r13,8), %ecx
leaq 0x74276(%rip), %rsi     # 0xf1004
leaq 0x9b512(%rip), %rdx     # 0x1182a7
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x74282(%rip), %rsi     # 0xf1034
leaq 0x9b477(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xb5f, %ecx            # imm = 0xB5F
jmp 0x7ce00
leaq 0x7423a(%rip), %rsi     # 0xf1004
leaq 0x9b4aa(%rip), %rdx     # 0x11827b
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x74243(%rip), %rsi     # 0xf1034
leaq 0x9b438(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xb37, %ecx            # imm = 0xB37
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %r12d
movl %r12d, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal (,%r13,8), %ecx
leaq 0x741d0(%rip), %rsi     # 0xf1004
leaq 0x9b44c(%rip), %rdx     # 0x118287
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x741dc(%rip), %rsi     # 0xf1034
leaq 0x9b3d1(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xb5d, %ecx            # imm = 0xB5D
jmp 0x7ce00
leal (,%r13,8), %ecx
leaq 0x7418c(%rip), %rsi     # 0xf1004
leaq 0x9b418(%rip), %rdx     # 0x118297
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x74198(%rip), %rsi     # 0xf1034
leaq 0x9b38d(%rip), %rdx     # 0x118230
movq %rbx, %rdi
movl $0xb5e, %ecx            # imm = 0xB5E
jmp 0x7ce00