// File: /workspace/github_c_makefile_star2_O2/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 $0x828, %rsp            # imm = 0x828
movq %r9, %r14
movq %rcx, %rbx
movq %rdx, 0x18(%rsp)
movq %rsi, %r15
movzwl 0xe(%rcx), %eax
movw %ax, 0xe(%rsp)
cmpw $0x1, %ax
jne 0x754ac
cmpl %r8d, 0x848(%rbx)
jne 0x754ac
movl 0x5b8(%rdi), %ecx
movl 0x5bc(%rdi), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4c4(%r15)
jne 0x7544c
movl 0x5c4(%rdi), %ecx
cmpl %ecx, %eax
cmovlel %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4c6(%r15)
jne 0x75472
cmpl $0x0, 0x830(%rbx)
jne 0x75472
movl 0x5c8(%rdi), %ecx
cmpl %ecx, %eax
cmovlel %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4be(%r15)
jne 0x7548f
movl 0x5cc(%rdi), %ecx
cmpl %ecx, %eax
cmovlel %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4ba(%r15)
jne 0x754ac
movl 0x5c0(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
movzwl 0x12(%rbx), %ebp
cmpw $0x1, %bp
jne 0x75511
cmpl %r8d, 0x84c(%rbx)
jne 0x75511
movl 0x5d0(%rdi), %ecx
movl 0x5d4(%rdi), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4c4(%r15)
jne 0x754f4
movl 0x5c4(%rdi), %ecx
cmpl %ecx, %eax
cmovlel %ecx, %eax
movl %eax, 0x188(%r14)
cmpw $0x1, 0x4be(%r15)
jne 0x75511
movl 0x5cc(%rdi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x188(%r14)
movl %r8d, 0x10(%rsp)
movslq 0x188(%r14), %r12
leaq 0x8(,%r12,8), %rdi
callq 0x8490
movq %rax, 0x190(%r14)
testq %rax, %rax
je 0x75587
xorl %ecx, %ecx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
cmpq %r12, %rcx
jg 0x75550
movq %rdx, (%rax,%rcx,8)
incq %rcx
jmp 0x75542
xorl %r13d, %r13d
movabsq $0x100000000, %rdx      # imm = 0x100000000
cmpw $0x1, 0xe(%rsp)
jne 0x755ce
movl 0x10(%rsp), %ecx
cmpl %ecx, 0x848(%rbx)
jne 0x755ec
movl 0x83c(%rbx), %eax
cmpl $0x1, %eax
je 0x755d4
testl %eax, %eax
jne 0x755ec
movq %rdx, (%r14)
pushq $0x2
jmp 0x755ea
leal 0x8(,%r12,8), %ecx
leaq 0x6fa6e(%rip), %rsi     # 0xe5004
leaq 0x96b6a(%rip), %rdx     # 0x10c107
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6fa7a(%rip), %rsi     # 0xe5034
leaq 0x96b4f(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xae2, %ecx            # imm = 0xAE2
jmp 0x759c4
movl 0x10(%rsp), %ecx
jmp 0x755ec
movaps 0x8c455(%rip), %xmm0    # 0x101a30
movups %xmm0, 0x8(%r14)
movl $0x4, 0x18(%r14)
pushq $0x5
popq %r13
cmpw $0x1, 0x10(%rbx)
jne 0x75617
cmpl %ecx, 0x850(%rbx)
jne 0x75617
movl 0x83c(%rbx), %eax
cmpl $0x1, %eax
je 0x75610
testl %eax, %eax
jne 0x75617
movl %r13d, 0x20(%r14)
jmp 0x75614
movl %r13d, 0x24(%r14)
incl %r13d
cmpw $0x1, %bp
movw %bp, 0x16(%rsp)
jne 0x75636
cmpl %ecx, 0x84c(%rbx)
jne 0x75636
movq %rdx, %rbp
movl %r13d, 0x1c(%r14)
incl %r13d
jmp 0x75639
movq %rdx, %rbp
movl %r13d, 0x28(%r14)
movslq 0x43c(%r15), %r12
leaq (,%r12,8), %rdi
callq 0x8490
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x756ec
movq 0x18(%rsp), %rax
movslq 0xf04(%rax), %r12
leaq (,%r12,8), %rdi
callq 0x8490
movq %rax, 0x38(%r14)
testq %rax, %rax
je 0x75732
shll $0x3, %r13d
movq %r13, %rdi
callq 0x8490
movq %rax, 0x40(%r14)
testq %rax, %rax
je 0x75778
pushq $0x2
popq %r13
movq %rbp, 0x160(%r14)
cmpw $0x1, 0xe(%rsp)
jne 0x757ba
movl 0x10(%rsp), %r12d
cmpl %r12d, 0x848(%rbx)
movzwl 0x16(%rsp), %ebp
jne 0x75800
cmpw $0x0, 0x4c4(%r15)
je 0x757c6
movl $0x2, 0x170(%r14)
pushq $0x3
jmp 0x757c8
shll $0x3, %r12d
leaq 0x6f90d(%rip), %rsi     # 0xe5004
leaq 0x96a2f(%rip), %rdx     # 0x10c12d
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6f916(%rip), %rsi     # 0xe5034
leaq 0x969eb(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xb22, %ecx            # imm = 0xB22
jmp 0x759c4
shll $0x3, %r12d
leaq 0x6f8c7(%rip), %rsi     # 0xe5004
leaq 0x969f7(%rip), %rdx     # 0x10c13b
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6f8d0(%rip), %rsi     # 0xe5034
leaq 0x969a5(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xb23, %ecx            # imm = 0xB23
jmp 0x759c4
leaq 0x6f885(%rip), %rsi     # 0xe5004
leaq 0x969c5(%rip), %rdx     # 0x10c14b
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6f88e(%rip), %rsi     # 0xe5034
leaq 0x96963(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xb24, %ecx            # imm = 0xB24
jmp 0x759c4
movl 0x10(%rsp), %r12d
movzwl 0x16(%rsp), %ebp
jmp 0x75800
pushq $0x2
popq %r13
cmpw $0x0, 0x4be(%r15)
je 0x757df
movl %r13d, 0x174(%r14)
incl %r13d
cmpw $0x0, 0x4c6(%r15)
je 0x75800
movl %r13d, 0x168(%r14)
leal 0x1(%r13), %eax
movl %eax, 0x16c(%r14)
addl $0x2, %r13d
movl %r13d, 0x178(%r14)
shll $0x2, %r13d
movq %r13, %rdi
callq 0x8490
movq %rax, 0x180(%r14)
testq %rax, %rax
je 0x75987
cmpw $0x1, 0xe(%rsp)
jne 0x7589f
cmpl %r12d, 0x848(%rbx)
jne 0x7589f
andq $0x0, (%rax)
cmpw $0x1, 0x4c6(%r15)
jne 0x7585c
movslq 0x16c(%r14), %rcx
andl $0x0, (%rax,%rcx,4)
movslq 0x168(%r14), %rcx
movl $0x1, (%rax,%rcx,4)
movq 0x18(%rsp), %rcx
cmpw $0x1, 0x38(%rcx)
jne 0x75873
movslq 0x168(%r14), %rcx
andl $0x0, (%rax,%rcx,4)
cmpw $0x1, 0x4c4(%r15)
jne 0x75889
movslq 0x170(%r14), %rcx
andl $0x0, (%rax,%rcx,4)
cmpw $0x1, 0x4be(%r15)
jne 0x7589f
movslq 0x174(%r14), %rcx
andl $0x0, (%rax,%rcx,4)
cmpw $0x1, %bp
jne 0x758b2
cmpl %r12d, 0x84c(%rbx)
jne 0x758b2
andq $0x0, (%rax)
xorl %r12d, %r12d
cmpw $0x1, 0xe(%rsp)
jne 0x759d2
movl 0x10(%rsp), %eax
cmpl %eax, 0x848(%rbx)
jne 0x759d2
cmpw $0x1, 0x34(%rbx)
je 0x758ed
cmpw $0x1, 0x36(%rbx)
je 0x758ed
cmpw $0x1, 0x87c(%rbx)
jne 0x759d2
movslq 0x248(%r15), %r13
movq %r13, %r15
shlq $0x3, %r15
movq %r15, %rdi
callq 0x8490
movq %rax, 0xe8(%r14)
testq %rax, %rax
je 0x759e7
movq %r15, %rdi
callq 0x8490
movq %rax, 0xf0(%r14)
testq %rax, %rax
je 0x75a2b
movq %r15, %rdi
callq 0x8490
movq %rax, 0xf8(%r14)
testq %rax, %rax
jne 0x759d2
leal (,%r13,8), %ecx
leaq 0x6f6b2(%rip), %rsi     # 0xe5004
leaq 0x9682e(%rip), %rdx     # 0x10c187
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6f6be(%rip), %rsi     # 0xe5034
leaq 0x96793(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xb5f, %ecx            # imm = 0xB5F
jmp 0x759c4
leaq 0x6f676(%rip), %rsi     # 0xe5004
leaq 0x967c6(%rip), %rdx     # 0x10c15b
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6f67f(%rip), %rsi     # 0xe5034
leaq 0x96754(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xb37, %ecx            # imm = 0xB37
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %r12
movl %r12d, %eax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal (,%r13,8), %ecx
leaq 0x6f60e(%rip), %rsi     # 0xe5004
leaq 0x9676a(%rip), %rdx     # 0x10c167
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6f61a(%rip), %rsi     # 0xe5034
leaq 0x966ef(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xb5d, %ecx            # imm = 0xB5D
jmp 0x759c4
leal (,%r13,8), %ecx
leaq 0x6f5ca(%rip), %rsi     # 0xe5004
leaq 0x96736(%rip), %rdx     # 0x10c177
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x6c8a, %rbx           # imm = 0x6C8A
leaq 0x6f5d6(%rip), %rsi     # 0xe5034
leaq 0x966ab(%rip), %rdx     # 0x10c110
movq %rbx, %rdi
movl $0xb5e, %ecx            # imm = 0xB5E
jmp 0x759c4