// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../external/HyRec2020/hydrogen.c
// Function: solve_real_virt
void solve_real_virt(double xr[2], double xv[NVIRT], double Trr[2][2], double *Trv[2], double *Tvr[2], double *Tvv[3],
                     double sr[2], double sv[NVIRT], int *error, char error_message[SIZE_ErrorM]){

  double *Tvv_inv_Tvr[2];
  double *Tvv_inv_sv;
  double Trr_new[2][2];
  double sr_new[2];
  unsigned i, j, b;
  double det;

  unsigned NSUBDIFF;
  NSUBDIFF = NSUBLYA - NDIFF/2;     /* lowest bin of the diffusion region */

  /** Allocate memory **/
  for (i = 0; i < 2; i++) Tvv_inv_Tvr[i] = create_1D_array(NVIRT, error, error_message);
  Tvv_inv_sv = create_1D_array(NVIRT, error, error_message);

  /*** Computing Tvv^{-1}.Tvr ***/

  for (i = 0; i < 2; i++) {
    for (b = 0; b < NSUBDIFF; b++)               Tvv_inv_Tvr[i][b] = Tvr[i][b]/Tvv[0][b];
    for (b = NSUBLYA + NDIFF/2; b < NVIRT; b++)  Tvv_inv_Tvr[i][b] = Tvr[i][b]/Tvv[0][b];
    solveTXeqB(Tvv[0]+NSUBDIFF, Tvv[2]+NSUBDIFF, Tvv[1]+NSUBDIFF, Tvv_inv_Tvr[i]+NSUBDIFF, Tvr[i]+NSUBDIFF, NDIFF, error, error_message);
  }

  /*** Trr_new = Trr - Trv.Tvv^{-1}.Tvr ***/
  for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) {
    Trr_new[i][j] = Trr[i][j];
    for (b = 0; b < NVIRT; b++) Trr_new[i][j] -= Trv[i][b]*Tvv_inv_Tvr[j][b];
  }

  /*** Computing Tvv^{-1}.sv ***/
  for (b = 0; b < NSUBDIFF; b++)               Tvv_inv_sv[b] = sv[b]/Tvv[0][b];
  for (b = NSUBLYA + NDIFF/2; b < NVIRT; b++)  Tvv_inv_sv[b] = sv[b]/Tvv[0][b];
  solveTXeqB(Tvv[0]+NSUBDIFF, Tvv[2]+NSUBDIFF, Tvv[1]+NSUBDIFF, Tvv_inv_sv+NSUBDIFF, sv+NSUBDIFF, NDIFF, error, error_message);

  /*** sr_new = sr - Trv.Tvv^{-1}sv ***/
  for (i = 0; i < 2; i++) {
    sr_new[i] = sr[i];
    for (b = 0; b < NVIRT; b++) sr_new[i] -= Trv[i][b]*Tvv_inv_sv[b];
  }

  /*** Solve 2 by 2 system Trr_new.xr = sr_new ***/
  det = Trr_new[0][0] * Trr_new[1][1] - Trr_new[0][1] * Trr_new[1][0];
  xr[0] = (Trr_new[1][1] * sr_new[0] - Trr_new[0][1] * sr_new[1])/det;
  xr[1] = (Trr_new[0][0] * sr_new[1] - Trr_new[1][0] * sr_new[0])/det;

  /*** xv = Tvv^{-1}(sv - Tvr.xr) ***/
  for (b = 0; b < NVIRT; b++) xv[b] = Tvv_inv_sv[b] - Tvv_inv_Tvr[0][b]*xr[0] - Tvv_inv_Tvr[1][b]*xr[1];

  /** Free memory **/
  for (i = 0; i < 2; i++) free(Tvv_inv_Tvr[i]);
  free(Tvv_inv_sv);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r14
movq %r8, 0x48(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, 0x38(%rsp)
movq 0xd8(%rsp), %r13
movq 0xd0(%rsp), %r15
movq 0xc8(%rsp), %rbx
movq 0xc0(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x137, %edi            # imm = 0x137
movq %r15, %rsi
movq %r13, %rdx
callq 0xd3766
movq %rax, 0x8(%rsp)
movl $0x137, %edi            # imm = 0x137
movq %r15, %rsi
movq %r13, %rdx
callq 0xd3766
movq %rax, %r12
movl $0x137, %edi            # imm = 0x137
movq %r15, 0x18(%rsp)
movq %r15, %rsi
movq %r13, 0x10(%rsp)
movq %r13, %rdx
callq 0xd3766
movq %rax, %r13
movb $0x1, %bpl
xorl %eax, %eax
movl $0x320, %r15d           # imm = 0x320
movq 0x8(%rsp), %rcx
movq 0x48(%rsp), %rdx
movq (%rdx,%rax,8), %r8
movq (%r14), %rdi
xorl %eax, %eax
movsd (%r8,%rax,8), %xmm0
divsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
cmpq $0x64, %rax
jne 0xd7702
xorl %eax, %eax
movsd 0x5a0(%r8,%rax,8), %xmm0
divsd 0x5a0(%rdi,%rax,8), %xmm0
movsd %xmm0, 0x5a0(%rcx,%rax,8)
incq %rax
cmpq $0x83, %rax
jne 0xd771d
addq %r15, %rdi
movq 0x10(%r14), %rsi
addq %r15, %rsi
movq 0x8(%r14), %rdx
addq %r15, %rdx
addq %r15, %rcx
addq %r15, %r8
movl $0x50, %r9d
pushq 0x10(%rsp)
pushq 0x20(%rsp)
callq 0xd7501
addq $0x10, %rsp
movl $0x1, %eax
movq %r12, %rcx
testb $0x1, %bpl
movl $0x0, %ebp
jne 0xd76f4
movb $0x1, %al
xorl %esi, %esi
movq 0x8(%rsp), %r15
movq 0x30(%rsp), %rbp
movq 0x20(%rsp), %r11
movq (%rbp,%rsi,8), %rcx
shlq $0x4, %rsi
leaq (%r11,%rsi), %rdx
addq %rsp, %rsi
addq $0x60, %rsi
movb $0x1, %dil
movq %r15, %r8
xorl %r9d, %r9d
movsd (%rdx,%r9,8), %xmm0
leaq (%rsi,%r9,8), %r9
xorl %r10d, %r10d
movsd (%rcx,%r10,8), %xmm1
mulsd (%r8,%r10,8), %xmm1
subsd %xmm1, %xmm0
incq %r10
cmpq $0x137, %r10            # imm = 0x137
jne 0xd77c6
movsd %xmm0, (%r9)
movl $0x1, %r9d
movq %r12, %r8
testb $0x1, %dil
movl $0x0, %edi
jne 0xd77b9
movl $0x1, %esi
testb $0x1, %al
movl $0x0, %eax
jne 0xd779c
movq (%r14), %rdi
xorl %eax, %eax
movsd (%rbx,%rax,8), %xmm0
divsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
cmpq $0x64, %rax
jne 0xd780e
movl $0xb4, %eax
movsd (%rbx,%rax,8), %xmm0
divsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
cmpq $0x137, %rax            # imm = 0x137
jne 0xd782d
movl $0x320, %eax            # imm = 0x320
addq %rax, %rdi
movq 0x10(%r14), %rsi
addq %rax, %rsi
movq 0x8(%r14), %rdx
addq %rax, %rdx
movq %r13, %rcx
addq %rax, %rcx
addq %rax, %rbx
movq %rbx, %r8
movl $0x50, %r9d
pushq 0x10(%rsp)
pushq 0x20(%rsp)
callq 0xd7501
addq $0x10, %rsp
leaq 0x50(%rsp), %rcx
movb $0x1, %al
xorl %edx, %edx
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %r8
leaq 0x58(%rsp), %r9
movsd (%r8,%rdx,8), %xmm0
movq (%rbp,%rdx,8), %rdx
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm1
mulsd (%r13,%rsi,8), %xmm1
subsd %xmm1, %xmm0
incq %rsi
cmpq $0x137, %rsi            # imm = 0x137
jne 0xd78a7
movsd %xmm0, (%rcx)
movl $0x1, %edx
movq %r9, %rcx
testb $0x1, %al
movl $0x0, %eax
jne 0xd789a
movsd 0x60(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
movupd 0x68(%rsp), %xmm2
movapd 0x1693e(%rip), %xmm3    # 0xee230
xorpd %xmm2, %xmm3
movapd %xmm1, %xmm4
mulsd %xmm0, %xmm4
movapd 0x50(%rsp), %xmm5
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd %xmm5, %xmm0
shufpd $0x1, %xmm5, %xmm5      # xmm5 = xmm5[1,0]
mulpd %xmm2, %xmm5
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
mulsd %xmm3, %xmm2
addsd %xmm2, %xmm4
subpd %xmm5, %xmm0
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
divpd %xmm4, %xmm0
movupd %xmm0, (%rdi)
xorl %eax, %eax
movq 0x40(%rsp), %rcx
movsd (%r13,%rax,8), %xmm0
movsd (%r15,%rax,8), %xmm1
mulsd (%rdi), %xmm1
subsd %xmm1, %xmm0
movsd (%r12,%rax,8), %xmm1
mulsd 0x8(%rdi), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
cmpq $0x137, %rax            # imm = 0x137
jne 0xd7938
movq %r15, %rdi
callq 0x8410
movq %r12, %rdi
callq 0x8410
movq %r13, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8410