// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/perturbations.c
// Function: perturbations_rsa_delta_and_theta
int perturbations_rsa_delta_and_theta(
                                      struct precision * ppr,
                                      struct background * pba,
                                      struct thermodynamics * pth,
                                      struct perturbations * ppt,
                                      double k,
                                      double * y,
                                      double a_prime_over_a,
                                      double * pvecthermo,
                                      struct perturbations_workspace * ppw,
                                      ErrorMsg error_message
                                      ) {
  /* - define local variables */

  double k2;

  k2 = k*k;

  class_test(ppw->approx[ppw->index_ap_rsa] == (int)rsa_off,
             "this function should not have been called now, bug was introduced",
             ppt->error_message,
             ppt->error_message);

  // formulas below TBC for curvaturema

  /* newtonian gauge */
  if (ppt->gauge == newtonian) {

    if (ppr->radiation_streaming_approximation == rsa_null) {
      ppw->rsa_delta_g = 0.;
      ppw->rsa_theta_g = 0.;
    }
    else {
      ppw->rsa_delta_g = -4.*y[ppw->pv->index_pt_phi];
      ppw->rsa_theta_g = 6.*ppw->pvecmetric[ppw->index_mt_phi_prime];
    }

    if (ppr->radiation_streaming_approximation == rsa_MD_with_reio) {

      ppw->rsa_delta_g +=
        -4./k2*ppw->pvecthermo[pth->index_th_dkappa]*y[ppw->pv->index_pt_theta_b];

      ppw->rsa_theta_g +=
        3./k2*(ppw->pvecthermo[pth->index_th_ddkappa]*y[ppw->pv->index_pt_theta_b]
               +ppw->pvecthermo[pth->index_th_dkappa]*
               (-a_prime_over_a*y[ppw->pv->index_pt_theta_b]
                +ppw->pvecthermo[pth->index_th_cb2]*k2*y[ppw->pv->index_pt_delta_b]
                +k2*y[ppw->pv->index_pt_phi]));
    }

    if (pba->has_ur == _TRUE_) {

      if (ppr->radiation_streaming_approximation == rsa_null) {
        ppw->rsa_delta_ur = 0.;
        ppw->rsa_theta_ur = 0.;
      }
      else {
        ppw->rsa_delta_ur = -4.*y[ppw->pv->index_pt_phi];
        ppw->rsa_theta_ur = 6.*ppw->pvecmetric[ppw->index_mt_phi_prime];
      }
    }
  }

  /* synchronous gauge */
  if (ppt->gauge == synchronous) {

    if (ppr->radiation_streaming_approximation == rsa_null) {
      ppw->rsa_delta_g = 0.;
      ppw->rsa_theta_g = 0.;
    }
    else {

      ppw->rsa_delta_g = 4./k2*(a_prime_over_a*ppw->pvecmetric[ppw->index_mt_h_prime]
                                -k2*y[ppw->pv->index_pt_eta]);
      ppw->rsa_theta_g = -0.5*ppw->pvecmetric[ppw->index_mt_h_prime];
    }

    if (ppr->radiation_streaming_approximation == rsa_MD_with_reio) {

      ppw->rsa_delta_g +=
        -4./k2*ppw->pvecthermo[pth->index_th_dkappa]*(y[ppw->pv->index_pt_theta_b]+0.5*ppw->pvecmetric[ppw->index_mt_h_prime]);

      ppw->rsa_theta_g +=
        3./k2*(ppw->pvecthermo[pth->index_th_ddkappa]*
               (y[ppw->pv->index_pt_theta_b]
                +0.5*ppw->pvecmetric[ppw->index_mt_h_prime])
               +ppw->pvecthermo[pth->index_th_dkappa]*
               (-a_prime_over_a*y[ppw->pv->index_pt_theta_b]
                + ppw->pvecthermo[pth->index_th_cb2]*k2*y[ppw->pv->index_pt_delta_b]
                -a_prime_over_a*ppw->pvecmetric[ppw->index_mt_h_prime]
                +k2*y[ppw->pv->index_pt_eta]));
    }

    if (pba->has_ur == _TRUE_) {

      if (ppr->radiation_streaming_approximation == rsa_null) {
        ppw->rsa_delta_ur = 0.;
        ppw->rsa_theta_ur = 0.;
      }
      else {
        ppw->rsa_delta_ur = 4./k2*(a_prime_over_a*ppw->pvecmetric[ppw->index_mt_h_prime]
                                   -k2*y[ppw->pv->index_pt_eta]);
        ppw->rsa_theta_ur = -0.5*ppw->pvecmetric[ppw->index_mt_h_prime];
      }
    }
  }

  /* update total delta and theta given rsa approximation results */

  ppw->delta_rho += ppw->pvecback[pba->index_bg_rho_g]*ppw->rsa_delta_g;
  ppw->delta_p += 1./3.*ppw->pvecback[pba->index_bg_rho_g]*ppw->rsa_delta_g;
  ppw->rho_plus_p_theta += 4./3.*ppw->pvecback[pba->index_bg_rho_g]*ppw->rsa_theta_g;

  if (pba->has_ur == _TRUE_) {
    ppw->delta_rho += ppw->pvecback[pba->index_bg_rho_ur]*ppw->rsa_delta_ur;
    ppw->delta_p += 1./3.*ppw->pvecback[pba->index_bg_rho_ur]*ppw->rsa_delta_ur;
    ppw->rho_plus_p_theta += 4./3.*ppw->pvecback[pba->index_bg_rho_ur]*ppw->rsa_theta_ur;
  }

  return _SUCCESS_;

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
movq 0x1020(%rsp), %r9
movq 0x180(%r9), %rax
movslq 0x164(%r9), %r10
cmpl $0x0, (%rax,%r10,4)
je 0x91769
mulsd %xmm0, %xmm0
movl 0x83c(%rcx), %eax
testl %eax, %eax
je 0x917d4
cmpl $0x1, %eax
jne 0x91904
movl 0x620(%rdi), %r11d
testl %r11d, %r11d
je 0x91923
movsd 0x5fe3e(%rip), %xmm4    # 0xf1438
divsd %xmm0, %xmm4
movq 0x40(%r9), %rax
movq 0x48(%r9), %r10
movslq 0x8(%r9), %rcx
movslq 0xd0(%r10), %rdi
movsd (%r8,%rdi,8), %xmm2
mulsd %xmm0, %xmm2
movsd (%rax,%rcx,8), %xmm3
mulsd %xmm1, %xmm3
subsd %xmm2, %xmm3
mulsd %xmm4, %xmm3
movsd %xmm3, 0xa8(%r9)
movsd (%rax,%rcx,8), %xmm2
mulsd 0x5fe36(%rip), %xmm2    # 0xf1478
movsd %xmm2, 0xb0(%r9)
cmpl $0x2, %r11d
jne 0x91725
movsd 0x5fe0b(%rip), %xmm6    # 0xf1468
divsd %xmm0, %xmm6
movq 0x38(%r9), %r11
movslq 0xe80(%rdx), %rbx
mulsd (%r11,%rbx,8), %xmm6
movslq 0x2c(%r10), %r15
movsd 0x5d652(%rip), %xmm5    # 0xeecd0
movsd (%rax,%rcx,8), %xmm7
mulsd %xmm5, %xmm7
addsd (%r8,%r15,8), %xmm7
mulsd %xmm6, %xmm7
addsd %xmm7, %xmm3
movsd %xmm3, 0xa8(%r9)
movsd 0x5dfda(%rip), %xmm6    # 0xef680
divsd %xmm0, %xmm6
movslq 0xe88(%rdx), %r14
movsd (%r8,%r15,8), %xmm7
movsd (%rax,%rcx,8), %xmm8
mulsd %xmm8, %xmm5
movslq 0xef0(%rdx), %rdx
movsd (%r11,%rdx,8), %xmm9
mulsd %xmm0, %xmm9
movslq 0x28(%r10), %rdx
mulsd (%r8,%rdx,8), %xmm9
addsd %xmm7, %xmm5
mulsd %xmm1, %xmm7
subsd %xmm7, %xmm9
mulsd %xmm1, %xmm8
subsd %xmm8, %xmm9
movsd (%r8,%rdi,8), %xmm7
mulsd %xmm0, %xmm7
addsd %xmm9, %xmm7
mulsd (%r11,%rbx,8), %xmm7
mulsd (%r11,%r14,8), %xmm5
addsd %xmm7, %xmm5
mulsd %xmm6, %xmm5
addsd %xmm5, %xmm2
movsd %xmm2, 0xb0(%r9)
cmpw $0x1, 0x4c4(%rsi)
jne 0x9194b
xorpd 0x5caf5(%rip), %xmm0    # 0xee230
mulsd (%r8,%rdi,8), %xmm0
mulsd (%rax,%rcx,8), %xmm1
addsd %xmm0, %xmm1
mulsd %xmm1, %xmm4
movsd %xmm4, 0xb8(%r9)
movsd (%rax,%rcx,8), %xmm0
mulsd 0x5fd14(%rip), %xmm0    # 0xf1478
jmp 0x918f7
addq $0x6c8a, %rcx           # imm = 0x6C8A
leaq 0x800(%rsp), %rbx
movq %rbx, %rdi
movq %rcx, %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x30af0
leaq 0x5c8f3(%rip), %rsi     # 0xee082
leaq 0x868d3(%rip), %rdx     # 0x118069
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x868eb(%rip), %rdi     # 0x118098
leaq 0x5c880(%rip), %rsi     # 0xee034
leaq 0x8691f(%rip), %rdx     # 0x1180da
movl $0x2cff, %ecx           # imm = 0x2CFF
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
jmp 0x91a13
movl 0x620(%rdi), %r11d
testl %r11d, %r11d
je 0x91923
movq 0x48(%r9), %r10
movslq 0xd4(%r10), %rax
movsd (%r8,%rax,8), %xmm3
mulsd 0x5fc6b(%rip), %xmm3    # 0xf1468
movq 0x40(%r9), %rcx
movsd %xmm3, 0xa8(%r9)
movslq 0x4(%r9), %rdi
movsd (%rcx,%rdi,8), %xmm2
mulsd 0x5de55(%rip), %xmm2    # 0xef670
movsd %xmm2, 0xb0(%r9)
cmpl $0x2, %r11d
jne 0x918c9
movsd 0x5fc32(%rip), %xmm4    # 0xf1468
divsd %xmm0, %xmm4
movq 0x38(%r9), %r11
movslq 0xe80(%rdx), %rbx
mulsd (%r11,%rbx,8), %xmm4
movslq 0x2c(%r10), %r14
mulsd (%r8,%r14,8), %xmm4
addsd %xmm4, %xmm3
movsd %xmm3, 0xa8(%r9)
movsd 0x5de16(%rip), %xmm4    # 0xef680
divsd %xmm0, %xmm4
movslq 0xe88(%rdx), %r15
movsd (%r8,%r14,8), %xmm5
movslq 0xef0(%rdx), %rdx
movsd (%r11,%rdx,8), %xmm6
mulsd %xmm0, %xmm6
movslq 0x28(%r10), %rdx
mulsd (%r8,%rdx,8), %xmm6
mulsd %xmm5, %xmm1
subsd %xmm1, %xmm6
mulsd (%r8,%rax,8), %xmm0
addsd %xmm6, %xmm0
mulsd (%r11,%rbx,8), %xmm0
mulsd (%r11,%r15,8), %xmm5
addsd %xmm0, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm2
movsd %xmm2, 0xb0(%r9)
cmpw $0x1, 0x4c4(%rsi)
jne 0x9194b
movsd (%r8,%rax,8), %xmm0
mulsd 0x5fb87(%rip), %xmm0    # 0xf1468
movsd %xmm0, 0xb8(%r9)
movsd (%rcx,%rdi,8), %xmm0
mulsd 0x5dd79(%rip), %xmm0    # 0xef670
movsd %xmm0, 0xc0(%r9)
movb $0x1, %cl
jmp 0x91955
movsd 0xa8(%r9), %xmm3
movsd 0xb0(%r9), %xmm2
cmpw $0x1, 0x4c4(%rsi)
sete %cl
jmp 0x91955
xorpd %xmm0, %xmm0
movupd %xmm0, 0xa8(%r9)
xorpd %xmm2, %xmm2
cmpw $0x1, 0x4c4(%rsi)
jne 0x9194f
movupd %xmm0, 0xb8(%r9)
movb $0x1, %cl
jmp 0x91951
xorl %ecx, %ecx
jmp 0x91955
xorl %ecx, %ecx
xorpd %xmm3, %xmm3
movq 0x30(%r9), %rdx
movslq 0x38c(%rsi), %rax
movsd (%rdx,%rax,8), %xmm4
mulsd %xmm3, %xmm4
addsd 0x50(%r9), %xmm4
movsd %xmm4, 0x50(%r9)
movsd (%rdx,%rax,8), %xmm0
mulsd 0x5fac6(%rip), %xmm0    # 0xf1448
mulsd %xmm3, %xmm0
addsd 0x68(%r9), %xmm0
movsd %xmm0, 0x68(%r9)
movsd (%rdx,%rax,8), %xmm1
mulsd 0x5fb21(%rip), %xmm1    # 0xf14c0
mulsd %xmm2, %xmm1
addsd 0x58(%r9), %xmm1
movsd %xmm1, 0x58(%r9)
xorl %eax, %eax
testb %cl, %cl
je 0x91a13
movslq 0x3ac(%rsi), %rcx
movsd 0xb8(%r9), %xmm2
movsd (%rdx,%rcx,8), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, 0x50(%r9)
movsd (%rdx,%rcx,8), %xmm3
mulsd 0x5fa63(%rip), %xmm3    # 0xf1448
mulsd %xmm2, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, 0x68(%r9)
movsd (%rdx,%rcx,8), %xmm0
mulsd 0x5fac0(%rip), %xmm0    # 0xf14c0
mulsd 0xc0(%r9), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x58(%r9)
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq