// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/main_tnm.c
// Function: Compute_sigma2
int Compute_sigma2(int *N_disc_freq, int *N_disc_out,
		   struct Normal_Mode NM,
		   float *mass_sum_sqrt, int naxe1, int N_Cart,
		   float COLL_THR)
{
  int N_disc_coll=0; *N_disc_freq=0;

  for(int ia=0; ia<NM.N; ia++){

    NM.Max_dev[ia]=
      Compute_Max_dev(NM.Cart[ia], NM.omega2[ia], N_Cart, mass_sum_sqrt);
    NM.Tors_coll[ia]=Collectivity_norm2(NM.Tors[ia], naxe1)/naxe1;
    NM.MW_Tors_coll[ia]=Collectivity_norm2(NM.MW_Tors[ia],naxe1)/naxe1;
    NM.Cart_coll[ia]=Collectivity_norm2(NM.Cart[ia], N_Cart); //_Renyi
    if((NM.omega2[ia]<=E_THR)||(NM.Cart_coll[ia] < COLL_THR)){
      printf("WARNING, discarding mode %d ", ia);
      printf(" omega^2= %.3g Coll= %.0f RMSD= %.2g\n",
	     NM.omega2[ia], NM.Cart_coll[ia], NM.Max_dev[ia]);
      if(NM.Cart_coll[ia] < COLL_THR){N_disc_coll++;}
      else{(*N_disc_freq)++;}
      NM.select[ia]=0; NM.sigma2[ia]=0;
    }else{
      NM.select[ia]=1;
      NM.sigma2[ia]=1./NM.omega2[ia];
    }
    NM.Cart_coll[ia]/=N_Cart;
  }
  printf("%d modes selected\n", NM.N-(N_disc_coll+*N_disc_freq));
  printf("%d modes discarded for low collectivity ", N_disc_coll);
  printf("and %d for low frequency\n", *N_disc_freq);
  int amin=0; while(NM.omega2[amin]<0)amin++;
  printf("Smallest positive eigenvalue: %.2g a=%d ",NM.omega2[amin],amin);
  printf("Threshold for selection: %.2g*<omega^2>\n", E_MIN);

  // Ugo_mod 05/21
  /* float thr_outlier=2.5, thr_mode=0.5;
     printf("Remove modes that move > %.2f outlier dof (rmsf > %.1f)\n",
     thr_mode, thr_outlier);
     *N_disc_out=Filter_modes_outliers(NM, Ref_kin, thr_outlier, thr_mode);
     printf("%d modes removed because they mostly move outliers\n",
     *N_disc_out);*/

  return(N_disc_coll);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl (%rcx), %eax
jge 0xb7ce
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rdi
movq 0x20(%rax), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movl -0x20(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x3aef0
movq -0x38(%rbp), %rax
movq 0x80(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movss %xmm0, (%rcx,%rdx,4)
movq 0x40(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x1c(%rbp), %esi
callq 0x15dc0
movq -0x38(%rbp), %rax
cvtsi2ssl -0x1c(%rbp), %xmm1
divss %xmm1, %xmm0
movq 0x70(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movss %xmm0, (%rcx,%rdx,4)
movq 0x48(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x1c(%rbp), %esi
callq 0x15dc0
movq -0x38(%rbp), %rax
cvtsi2ssl -0x1c(%rbp), %xmm1
divss %xmm1, %xmm0
movq 0x78(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movss %xmm0, (%rcx,%rdx,4)
movq 0x38(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x20(%rbp), %esi
callq 0x15dc0
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movss %xmm0, (%rcx,%rdx,4)
movq 0x20(%rax), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x81752(%rip), %xmm0    # 0x8cdd8
ucomisd %xmm1, %xmm0
jae 0xb6ab
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0x24(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xb75d
movl -0x2c(%rbp), %esi
leaq 0x6f478(%rip), %rdi     # 0x7ab2d
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x68(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm1
cvtss2sd %xmm1, %xmm1
movq 0x80(%rax), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x6f44d(%rip), %rdi     # 0x7ab4a
movb $0x3, %al
callq 0x10d0
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0x24(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xb72a
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xb735
movq -0x8(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movl $0x0, (%rcx,%rdx,4)
movq 0x28(%rax), %rax
movslq -0x2c(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
jmp 0xb7a1
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq 0x20(%rax), %rcx
movslq -0x2c(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x6a8bc(%rip), %xmm0    # 0x76048
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x28(%rax), %rax
movslq -0x2c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
cvtsi2ssl -0x20(%rbp), %xmm1
movq 0x68(%rax), %rax
movslq -0x2c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb5a0
movq -0x38(%rbp), %rax
movl (%rax), %esi
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
addl (%rcx), %eax
subl %eax, %esi
leaq 0x6f38a(%rip), %rdi     # 0x7ab70
movb $0x0, %al
callq 0x10d0
movl -0x28(%rbp), %esi
leaq 0x6f38c(%rip), %rdi     # 0x7ab83
movb $0x0, %al
callq 0x10d0
movq -0x8(%rbp), %rax
movl (%rax), %esi
leaq 0x6f3a1(%rip), %rdi     # 0x7abac
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x30(%rbp), %rcx
xorps %xmm0, %xmm0
ucomiss (%rax,%rcx,4), %xmm0
jbe 0xb839
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb819
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movl -0x30(%rbp), %esi
leaq 0x6f36e(%rip), %rdi     # 0x7abc6
movb $0x1, %al
callq 0x10d0
movss 0x8084d(%rip), %xmm0    # 0x8c0b4
cvtss2sd %xmm0, %xmm0
leaq 0x6f37d(%rip), %rdi     # 0x7abef
movb $0x1, %al
callq 0x10d0
movl -0x28(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)