// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/Fit_B_factors.c
// Function: Filter_modes_outliers
int Filter_modes_outliers(struct Normal_Mode NM, struct Reference Ref_kin,
			  float t_out, float t_mode)
{
  int discard_tot=0;
  int i, N_ref=Ref_kin.N_ref;
  float B_TNM[N_ref];
  int outlier[N_ref]; 

  for(int iter=0; iter<10; iter++){
    for(i=0; i<N_ref; i++){
      B_TNM[i]=Compute_correlation(NM.Cart,NM.sigma2,NM.N,i,i);
    }
    for(i=0; i<N_ref; i++)outlier[i]=0;
    int nout=Find_outliers_mean(outlier, B_TNM, N_ref, t_out);
    printf("%d iter %d outliers with fluctuations > %.2f of the mean\n",
	   iter, nout, t_out);
    int discard=0;
    for(int k=0; k<NM.N; k++){
      if((NM.select[k]==0)||(NM.sigma2[k]==0))continue;
      double B_out=0, B_no_out=0;
      for(int j=0; j<3*N_ref; j++){
	float v2=NM.Cart[k][j]; v2*=v2; j++;
	i=j/3; if(outlier[i]){B_out+=v2;}else{B_no_out+=v2;}
      }
      if(B_out>t_mode*(B_out+B_no_out)){
	printf("Discard: mode %d, sigma2= %.3g Collectivity= %.3g ",
	       k, NM.sigma2[k], NM.Cart_coll[k]);
	printf("Outliers= %.3g No outliers= %.3g\n", B_out, B_no_out);
	NM.select[k]=0; NM.sigma2[k]=0; discard++;
      }
    }
    discard_tot+=discard;
    printf("%d iter %d modes discarded for outliers represent > %.2f motion\n",
	   iter, discard_tot, t_mode);
    if(discard==0)break;
  }
  return(discard_tot);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
leaq 0xe0(%rbp), %rax
leaq 0x10(%rbp), %rcx
movq %rcx, -0x70(%rbp)
movss %xmm0, -0x4(%rbp)
movss %xmm1, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0xa, -0x34(%rbp)
jge 0x3d026
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3cdd6
movq -0x70(%rbp), %rax
movq 0x38(%rax), %rdi
movq 0x28(%rax), %rsi
movl (%rax), %edx
movl -0x10(%rbp), %ecx
movl -0x10(%rbp), %r8d
callq 0x3bf80
movq -0x68(%rbp), %rax
movslq -0x10(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x3cd9c
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3cdff
movq -0x60(%rbp), %rax
movslq -0x10(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x3cddd
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdi
movl -0x14(%rbp), %edx
movss -0x4(%rbp), %xmm0
callq 0x3c940
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
movss -0x4(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x41c10(%rip), %rdi     # 0x7ea3d
movb $0x1, %al
callq 0x10d0
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x70(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl (%rcx), %eax
jge 0x3cfe8
movq -0x70(%rbp), %rax
movq 0xc0(%rax), %rax
movslq -0x40(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x3ce81
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3ce86
jp 0x3ce86
jmp 0x3cfda
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
imull $0x3, -0x14(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3cf38
movq -0x70(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
mulss -0x58(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, -0x10(%rbp)
movslq -0x10(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x3cf15
movss -0x58(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x3cf28
movss -0x58(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x3cf2a
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x3ce9d
movsd -0x48(%rbp), %xmm0
movss -0x8(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd -0x48(%rbp), %xmm2
addsd -0x50(%rbp), %xmm2
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3cfd8
movq -0x70(%rbp), %rax
movl -0x40(%rbp), %esi
movq 0x28(%rax), %rcx
movslq -0x40(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x68(%rax), %rax
movslq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x41aed(%rip), %rdi     # 0x7ea77
movb $0x2, %al
callq 0x10d0
movsd -0x48(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
leaq 0x41b08(%rip), %rdi     # 0x7eaaa
movb $0x2, %al
callq 0x10d0
movq -0x70(%rbp), %rax
movq 0xc0(%rax), %rcx
movslq -0x40(%rbp), %rdx
movl $0x0, (%rcx,%rdx,4)
movq 0x28(%rax), %rax
movslq -0x40(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3cfda
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3ce42
movl -0x3c(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x34(%rbp), %esi
movl -0xc(%rbp), %edx
movss -0x8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x41ac5(%rip), %rdi     # 0x7eacc
movb $0x1, %al
callq 0x10d0
cmpl $0x0, -0x3c(%rbp)
jne 0x3d016
jmp 0x3d026
jmp 0x3d018
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3cd8b
movl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
movq %rcx, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop