// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movq 0x1020(%rsp), %r9
movq 0x180(%r9), %rax
movslq 0x164(%r9), %r10
cmpl $0x0, (%rax,%r10,4)
je 0x94192
mulsd %xmm0, %xmm0
movl 0x83c(%rcx), %eax
cmpl $0x1, %eax
je 0x94332
testl %eax, %eax
jne 0x94500
movl 0x620(%rdi), %ecx
testl %ecx, %ecx
je 0x941fd
movq 0x40(%r9), %r10
movq 0x48(%r9), %r11
movslq 0xd4(%r11), %r11
movsd (%r8,%r11,8), %xmm2
mulsd 0x602ec(%rip), %xmm2    # 0xf4458
movsd %xmm2, 0xa8(%r9)
movslq 0x4(%r9), %r11
movsd (%r10,%r11,8), %xmm2
mulsd 0x5e4e9(%rip), %xmm2    # 0xf2670
movsd %xmm2, 0xb0(%r9)
jmp 0x9420a
addq $0x6c8a, %rcx           # imm = 0x6C8A
leaq 0x800(%rsp), %rbx
movq %rbx, %rdi
movq %rcx, %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x30c2c
leaq 0x5ceca(%rip), %rsi     # 0xf1082
leaq 0x86e6a(%rip), %rdx     # 0x11b029
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x86e82(%rip), %rdi     # 0x11b058
leaq 0x5ce57(%rip), %rsi     # 0xf1034
leaq 0x86eb6(%rip), %rdx     # 0x11b09a
movl $0x2cff, %ecx           # imm = 0x2CFF
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
jmp 0x945d2
xorpd %xmm2, %xmm2
movupd %xmm2, 0xa8(%r9)
cmpl $0x2, %ecx
jne 0x942cb
movsd 0x6023d(%rip), %xmm2    # 0xf4458
divsd %xmm0, %xmm2
movslq 0xe80(%rdx), %r11
movq 0x38(%r9), %r10
movq 0x48(%r9), %rbx
mulsd (%r10,%r11,8), %xmm2
movslq 0x2c(%rbx), %r14
mulsd (%r8,%r14,8), %xmm2
addsd 0xa8(%r9), %xmm2
movsd %xmm2, 0xa8(%r9)
movsd 0x5e428(%rip), %xmm2    # 0xf2680
divsd %xmm0, %xmm2
movsd (%r8,%r14,8), %xmm3
movslq 0xef0(%rdx), %r14
movsd (%r10,%r14,8), %xmm4
mulsd %xmm0, %xmm4
movslq 0x28(%rbx), %r14
mulsd (%r8,%r14,8), %xmm4
movapd %xmm1, %xmm5
mulsd %xmm3, %xmm5
subsd %xmm5, %xmm4
movslq 0xd4(%rbx), %rbx
movsd (%r8,%rbx,8), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm4, %xmm5
mulsd (%r10,%r11,8), %xmm5
movslq 0xe88(%rdx), %r11
mulsd (%r10,%r11,8), %xmm3
addsd %xmm5, %xmm3
mulsd %xmm2, %xmm3
addsd 0xb0(%r9), %xmm3
movsd %xmm3, 0xb0(%r9)
cmpw $0x1, 0x4c4(%rsi)
jne 0x94329
testl %ecx, %ecx
je 0x9431c
movq 0x40(%r9), %rcx
movq 0x48(%r9), %r10
movslq 0xd4(%r10), %r10
movsd (%r8,%r10,8), %xmm2
mulsd 0x60162(%rip), %xmm2    # 0xf4458
movsd %xmm2, 0xb8(%r9)
movslq 0x4(%r9), %r10
movsd (%rcx,%r10,8), %xmm2
mulsd 0x5e35f(%rip), %xmm2    # 0xf2670
movsd %xmm2, 0xc0(%r9)
jmp 0x94329
xorpd %xmm2, %xmm2
movupd %xmm2, 0xb8(%r9)
cmpl $0x1, %eax
jne 0x94500
movl 0x620(%rdi), %eax
testl %eax, %eax
je 0x94397
movsd 0x600e4(%rip), %xmm2    # 0xf4428
divsd %xmm0, %xmm2
movslq 0x8(%r9), %rcx
movq 0x40(%r9), %rdi
movq 0x48(%r9), %r10
movslq 0xd0(%r10), %r10
movsd (%r8,%r10,8), %xmm3
mulsd %xmm0, %xmm3
movsd (%rdi,%rcx,8), %xmm4
mulsd %xmm1, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm2, %xmm4
movsd %xmm4, 0xa8(%r9)
movsd (%rdi,%rcx,8), %xmm2
mulsd 0x600dc(%rip), %xmm2    # 0xf4468
movsd %xmm2, 0xb0(%r9)
jmp 0x943a4
xorpd %xmm2, %xmm2
movupd %xmm2, 0xa8(%r9)
cmpl $0x2, %eax
jne 0x94492
movsd 0x600a3(%rip), %xmm3    # 0xf4458
divsd %xmm0, %xmm3
movslq 0xe80(%rdx), %rdi
movq 0x38(%r9), %rcx
movq 0x40(%r9), %r11
mulsd (%rcx,%rdi,8), %xmm3
movq 0x48(%r9), %r10
movslq 0x2c(%r10), %rbx
movslq 0x8(%r9), %r14
movsd 0x5d8ef(%rip), %xmm2    # 0xf1cd0
movsd (%r11,%r14,8), %xmm4
mulsd %xmm2, %xmm4
addsd (%r8,%rbx,8), %xmm4
mulsd %xmm3, %xmm4
addsd 0xa8(%r9), %xmm4
movsd %xmm4, 0xa8(%r9)
movsd 0x5e271(%rip), %xmm3    # 0xf2680
divsd %xmm0, %xmm3
movsd (%r8,%rbx,8), %xmm4
movsd (%r11,%r14,8), %xmm5
mulsd %xmm5, %xmm2
addsd %xmm4, %xmm2
movslq 0xef0(%rdx), %r11
movsd (%rcx,%r11,8), %xmm6
mulsd %xmm0, %xmm6
movslq 0x28(%r10), %r11
mulsd (%r8,%r11,8), %xmm6
mulsd %xmm1, %xmm4
subsd %xmm4, %xmm6
mulsd %xmm1, %xmm5
subsd %xmm5, %xmm6
movslq 0xd0(%r10), %r10
movsd (%r8,%r10,8), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm6, %xmm4
mulsd (%rcx,%rdi,8), %xmm4
movslq 0xe88(%rdx), %rdx
mulsd (%rcx,%rdx,8), %xmm2
addsd %xmm4, %xmm2
mulsd %xmm3, %xmm2
addsd 0xb0(%r9), %xmm2
movsd %xmm2, 0xb0(%r9)
cmpw $0x1, 0x4c4(%rsi)
jne 0x94500
testl %eax, %eax
je 0x944f3
movsd 0x5ff80(%rip), %xmm2    # 0xf4428
divsd %xmm0, %xmm2
movslq 0x8(%r9), %rax
movq 0x40(%r9), %rcx
movq 0x48(%r9), %rdx
movslq 0xd0(%rdx), %rdx
mulsd (%r8,%rdx,8), %xmm0
mulsd (%rcx,%rax,8), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, 0xb8(%r9)
movsd (%rcx,%rax,8), %xmm0
mulsd 0x5ff80(%rip), %xmm0    # 0xf4468
movsd %xmm0, 0xc0(%r9)
jmp 0x94500
xorpd %xmm0, %xmm0
movupd %xmm0, 0xb8(%r9)
movq 0x30(%r9), %rcx
movslq 0x38c(%rsi), %rax
movsd 0xa8(%r9), %xmm1
movsd (%rcx,%rax,8), %xmm2
mulsd %xmm1, %xmm2
addsd 0x50(%r9), %xmm2
movsd %xmm2, 0x50(%r9)
movsd (%rcx,%rax,8), %xmm0
mulsd 0x5ff02(%rip), %xmm0    # 0xf4438
mulsd %xmm1, %xmm0
addsd 0x68(%r9), %xmm0
movsd %xmm0, 0x68(%r9)
movsd (%rcx,%rax,8), %xmm1
mulsd 0x5ff5d(%rip), %xmm1    # 0xf44b0
mulsd 0xb0(%r9), %xmm1
addsd 0x58(%r9), %xmm1
movsd %xmm1, 0x58(%r9)
xorl %eax, %eax
cmpw $0x1, 0x4c4(%rsi)
jne 0x945d2
movslq 0x3ac(%rsi), %rdx
movsd 0xb8(%r9), %xmm3
movsd (%rcx,%rdx,8), %xmm4
mulsd %xmm3, %xmm4
addsd %xmm2, %xmm4
movsd %xmm4, 0x50(%r9)
movsd (%rcx,%rdx,8), %xmm2
mulsd 0x5fe94(%rip), %xmm2    # 0xf4438
mulsd %xmm3, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, 0x68(%r9)
movsd (%rcx,%rdx,8), %xmm0
mulsd 0x5fef1(%rip), %xmm0    # 0xf44b0
mulsd 0xc0(%r9), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x58(%r9)
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r14
retq