// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rcx, 0x38(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
movq 0xd8(%rsp), %rbp
movq 0xd0(%rsp), %r13
movq 0xc8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %r15d, %r15d
movl $0x137, %edi            # imm = 0x137
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd6f5e
movq %rax, (%rsp,%r15,8)
incq %r15
cmpq $0x1, %r15
je 0xdae59
movl $0x137, %edi            # imm = 0x137
movq %r13, 0x18(%rsp)
movq %r13, %rsi
movq %rbp, %rbx
movq %rbp, %rdx
callq 0xd6f5e
movq %rax, %r15
xorl %r13d, %r13d
movl $0x320, %ebp            # imm = 0x320
movq (%r12,%r13,8), %rax
movq (%r14), %rcx
movq (%rsp,%r13,8), %rdx
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm0
divsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
cmpq $0x64, %rsi
jne 0xdaea6
movq (%r12,%r13,8), %rax
movq (%r14), %rcx
movq (%rsp,%r13,8), %rdx
xorl %esi, %esi
movsd 0x5a0(%rax,%rsi,8), %xmm0
divsd 0x5a0(%rcx,%rsi,8), %xmm0
movsd %xmm0, 0x5a0(%rdx,%rsi,8)
incq %rsi
cmpq $0x83, %rsi
jne 0xdaecb
movq (%r14), %rdi
addq %rbp, %rdi
movq 0x10(%r14), %rsi
addq %rbp, %rsi
movq 0x8(%r14), %rdx
addq %rbp, %rdx
movq (%rsp,%r13,8), %rcx
addq %rbp, %rcx
movq (%r12,%r13,8), %r8
addq %rbp, %r8
movl $0x50, %r9d
pushq %rbx
pushq 0x20(%rsp)
callq 0xdacc7
addq $0x10, %rsp
leaq 0x1(%r13), %rax
testq %r13, %r13
movq %rax, %r13
je 0xdae99
xorl %eax, %eax
movq 0x38(%rsp), %r12
movq 0x18(%rsp), %r11
movq 0x20(%rsp), %r13
movq (%r12,%rax,8), %rcx
movq %rax, %rsi
shlq $0x4, %rsi
leaq (%rsi,%r13), %rdx
addq %rsp, %rsi
addq $0x60, %rsi
xorl %edi, %edi
movsd (%rdx,%rdi,8), %xmm0
leaq (%rsi,%rdi,8), %r8
movsd %xmm0, (%r8)
movq (%rsp,%rdi,8), %r9
xorl %r10d, %r10d
movsd (%rcx,%r10,8), %xmm1
mulsd (%r9,%r10,8), %xmm1
subsd %xmm1, %xmm0
incq %r10
cmpq $0x137, %r10            # imm = 0x137
jne 0xdaf76
movsd %xmm0, (%r8)
leaq 0x1(%rdi), %r8
testq %rdi, %rdi
movq %r8, %rdi
je 0xdaf61
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0xdaf49
movq (%r14), %rax
xorl %ecx, %ecx
movq 0x28(%rsp), %r8
movsd (%r8,%rcx,8), %xmm0
divsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%r15,%rcx,8)
incq %rcx
cmpq $0x64, %rcx
jne 0xdafb9
movq (%r14), %rax
movl $0xb4, %ecx
movsd (%r8,%rcx,8), %xmm0
divsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%r15,%rcx,8)
incq %rcx
cmpq $0x137, %rcx            # imm = 0x137
jne 0xdafdb
movl $0x320, %eax            # imm = 0x320
movq (%r14), %rdi
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
movl $0x50, %r9d
pushq %rbx
pushq %r11
callq 0xdacc7
addq $0x10, %rsp
xorl %eax, %eax
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %r8
movsd (%r8,%rax,8), %xmm0
movsd %xmm0, 0x50(%rsp,%rax,8)
movq (%r12,%rax,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
mulsd (%r15,%rdx,8), %xmm1
subsd %xmm1, %xmm0
incq %rdx
cmpq $0x137, %rdx            # imm = 0x137
jne 0xdb04f
movsd %xmm0, 0x50(%rsp,%rax,8)
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0xdb03d
movsd 0x60(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
movupd 0x68(%rsp), %xmm2
movapd 0x1619a(%rip), %xmm3    # 0xf1230
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
movsd (%r15,%rdx,8), %xmm0
movsd (%rax,%rdx,8), %xmm1
mulsd (%rdi), %xmm1
subsd %xmm1, %xmm0
movsd (%rcx,%rdx,8), %xmm1
mulsd 0x8(%rdi), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
cmpq $0x137, %rdx            # imm = 0x137
jne 0xdb0e0
xorl %ebx, %ebx
movq (%rsp,%rbx,8), %rdi
callq 0x8410
incq %rbx
cmpq $0x1, %rbx
je 0xdb114
movq %r15, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8410