// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, 0x38(%rsp)
movq 0xd8(%rsp), %rbp
movq 0xd0(%rsp), %r13
movq 0xc8(%rsp), %rbx
movq 0xc0(%rsp), %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
movl $0x137, %edi            # imm = 0x137
movq %r13, %rsi
movq %rbp, %rdx
callq 0xcbe5a
movq %rax, %r15
cmpq $0x2, %r12
je 0xcfa38
movq %r15, (%rsp,%r12,8)
incq %r12
jmp 0xcfa16
movq %rbx, 0x20(%rsp)
movq %rbp, %rbx
movq %r13, %rbp
xorl %r12d, %r12d
movl $0x320, %r13d           # imm = 0x320
cmpq $0x2, %r12
je 0xcfada
movq 0x48(%rsp), %rax
movq (%rax,%r12,8), %r8
movq (%r14), %rdi
movq (%rsp,%r12,8), %rcx
xorl %eax, %eax
cmpq $0x64, %rax
je 0xcfa83
movsd (%r8,%rax,8), %xmm0
divsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0xcfa68
xorl %eax, %eax
cmpq $0x83, %rax
je 0xcfaae
movsd 0x5a0(%r8,%rax,8), %xmm0
divsd 0x5a0(%rdi,%rax,8), %xmm0
movsd %xmm0, 0x5a0(%rcx,%rax,8)
incq %rax
jmp 0xcfa85
addq %r13, %rdi
movq 0x10(%r14), %rsi
addq %r13, %rsi
movq 0x8(%r14), %rdx
addq %r13, %rdx
addq %r13, %rcx
addq %r13, %r8
pushq $0x50
popq %r9
pushq %rbx
pushq %rbp
callq 0xcf89c
popq %rax
popq %rcx
incq %r12
jmp 0xcfa4c
xorl %eax, %eax
movq 0x30(%rsp), %r12
movq %rbp, %r11
movq %rbx, %r13
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %rbp
cmpq $0x2, %rax
je 0xcfb51
movq (%r12,%rax,8), %rcx
movq %rax, %rsi
shlq $0x4, %rsi
leaq (%rsi,%rbp), %rdx
addq %rsp, %rsi
addq $0x60, %rsi
xorl %edi, %edi
cmpq $0x2, %rdi
je 0xcfb4c
movsd (%rdx,%rdi,8), %xmm0
leaq (%rsi,%rdi,8), %rbx
movq (%rsp,%rdi,8), %r9
xorl %r10d, %r10d
cmpq $0x137, %r10            # imm = 0x137
je 0xcfb43
movsd (%rcx,%r10,8), %xmm1
mulsd (%r9,%r10,8), %xmm1
subsd %xmm1, %xmm0
incq %r10
jmp 0xcfb25
movsd %xmm0, (%rbx)
incq %rdi
jmp 0xcfb0f
incq %rax
jmp 0xcfaf1
movq (%r14), %rdi
xorl %eax, %eax
cmpq $0x64, %rax
je 0xcfb72
movsd (%r8,%rax,8), %xmm0
divsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0xcfb56
movl $0xb4, %eax
cmpq $0x137, %rax            # imm = 0x137
je 0xcfb95
movsd (%r8,%rax,8), %xmm0
divsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0xcfb77
movl $0x320, %eax            # imm = 0x320
addq %rax, %rdi
movq 0x10(%r14), %rsi
addq %rax, %rsi
movq 0x8(%r14), %rdx
addq %rax, %rdx
movq %r15, %rcx
addq %rax, %rcx
addq %rax, %r8
pushq $0x50
popq %r9
pushq %r13
pushq %r11
callq 0xcf89c
popq %rax
popq %rcx
xorl %eax, %eax
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %r8
cmpq $0x2, %rax
je 0xcfc0e
movsd (%r8,%rax,8), %xmm0
movq (%r12,%rax,8), %rcx
xorl %edx, %edx
cmpq $0x137, %rdx            # imm = 0x137
je 0xcfc03
movsd (%rcx,%rdx,8), %xmm1
mulsd (%r15,%rdx,8), %xmm1
subsd %xmm1, %xmm0
incq %rdx
jmp 0xcfbe6
movsd %xmm0, 0x50(%rsp,%rax,8)
incq %rax
jmp 0xcfbd4
movsd 0x60(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
movupd 0x68(%rsp), %xmm2
movapd 0x15608(%rip), %xmm3    # 0xe5230
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)
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
cmpq $0x137, %rdx            # imm = 0x137
je 0xcfca6
movsd (%rax,%rdx,8), %xmm0
mulsd (%rdi), %xmm0
movsd (%r15,%rdx,8), %xmm1
movsd (%rcx,%rdx,8), %xmm2
mulsd 0x8(%rdi), %xmm2
subsd %xmm0, %xmm1
subsd %xmm2, %xmm1
movsd %xmm1, (%rsi,%rdx,8)
incq %rdx
jmp 0xcfc72
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0xcfcbc
movq (%rsp,%rbx,8), %rdi
callq 0x8430
incq %rbx
jmp 0xcfca8
movq %r15, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8430