// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/allostery.c
// Function: Test_site
int Test_site(struct site_results *res, int *atom_site,
	      float *profile, float **coupling, int Na,
	      int *site_res, int **site_res_ran, int numran,
	      int nr, int *atomres)
{

  int n_not=0;

  // Observed site
  double p_ave, p_dev, c_ave, c_dev;
  int n_notfound=0;
  p_ave=Ave_site(&p_dev, &c_ave, &c_dev, &n_notfound,
		 site_res, atomres, nr, atom_site,
		 profile, coupling, Na);
  if(n_notfound){
    printf("WARNING, %d reference atoms of binding site not found\n",
	   n_notfound);
  } 

  // Sum over num random sites 
  double ran_prof1=0, ran_prof2=0;
  double ran_pair1=0, ran_pair2=0;
  double ran_sig1=0,  ran_sig2=0;
  int num_p_gt=0, num_c_gt=0;
  for(int kran=0; kran<numran; kran++){
    double ave_prof, sigprof, ave_pair, sigpair;
    ave_prof=Ave_site(&sigprof, &ave_pair, &sigpair, &n_notfound,
		      site_res_ran[kran], atomres, nr,
		      NULL, profile, coupling, Na);
    if(ave_prof > p_ave)num_p_gt++;
    if(ave_pair > c_ave)num_c_gt++;
    ran_prof1+=ave_prof;
    ran_prof2+=ave_prof*ave_prof;
    ran_sig1+=sigprof;
    ran_sig2+=sigprof*sigprof;
    ran_pair1+=ave_pair;
    ran_pair2+=ave_pair*ave_pair;
    n_not+=n_notfound;
  } 
  Ave_St_dev(&ran_prof1, &ran_prof2, numran);
  Ave_St_dev(&ran_pair1, &ran_pair2, numran);
  Ave_St_dev(&ran_sig1, &ran_sig2, numran);
  if(n_not)
    printf("WARNING, %d atoms not found in %d random sites\n", n_not, numran);
  
  float Z_p=(p_ave-ran_prof1)/(ran_prof2);
  float Z_c=(c_ave-ran_pair1);
  if(ran_pair2)Z_c/=ran_pair2;
  //float Z_sig= (p_dev - ran_sig1)/(ran_sig2);
  res->prof=p_ave; res->Z_p=Z_p; res->P_p= (float)num_p_gt/numran;
  res->coup=c_ave; res->Z_c=Z_c; res->P_c= (float)num_c_gt/numran;
  res->p_ran1=ran_prof1; res->p_ran2=ran_prof2;
  res->c_ran1=ran_pair1; res->c_ran2=ran_pair2;

  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xf0, %rsp
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movq %r9, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0x40(%rbp), %r8
movq 0x28(%rbp), %r9
movl 0x20(%rbp), %r14d
movq -0x20(%rbp), %rbx
movq -0x28(%rbp), %r11
movq -0x30(%rbp), %r10
movl -0x34(%rbp), %eax
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x6c(%rbp), %rcx
movl %r14d, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x666e0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x66369
movl -0x6c(%rbp), %esi
leaq 0x1c44f(%rip), %rdi     # 0x827b1
movb $0x0, %al
callq 0x10d0
xorps %xmm0, %xmm0
movsd %xmm0, -0x78(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0xac(%rbp)
movl -0xac(%rbp), %eax
cmpl 0x18(%rbp), %eax
jge 0x66547
movq 0x10(%rbp), %rax
movslq -0xac(%rbp), %rcx
movq (%rax,%rcx,8), %r8
movq 0x28(%rbp), %r9
movl 0x20(%rbp), %ebx
movq -0x28(%rbp), %r11
movq -0x30(%rbp), %r10
movl -0x34(%rbp), %eax
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
leaq -0x6c(%rbp), %rcx
xorl %r14d, %r14d
movl %ebx, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x666e0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
ucomisd -0x50(%rbp), %xmm0
jbe 0x66458
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
movsd -0xc8(%rbp), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x66476
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
movsd -0xb8(%rbp), %xmm0
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm2
movsd -0x80(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0xc0(%rbp), %xmm0
addsd -0x98(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm2
movsd -0xa0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xc8(%rbp), %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm2
movsd -0x90(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movl -0x6c(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x663c3
movl 0x18(%rbp), %edx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x66900
movl 0x18(%rbp), %edx
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x66900
movl 0x18(%rbp), %edx
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x66900
cmpl $0x0, -0x44(%rbp)
je 0x6659d
movl -0x44(%rbp), %esi
movl 0x18(%rbp), %edx
leaq 0x1c252(%rip), %rdi     # 0x827e8
movb $0x0, %al
callq 0x10d0
movsd -0x50(%rbp), %xmm0
subsd -0x78(%rbp), %xmm0
divsd -0x80(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xd4(%rbp)
movsd -0x60(%rbp), %xmm0
subsd -0x88(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xd8(%rbp)
movsd -0x90(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x665e6
jp 0x665e6
jmp 0x6660a
movsd -0x90(%rbp), %xmm1
movss -0xd8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xd8(%rbp)
movsd -0x50(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, (%rax)
movss -0xd4(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x8(%rax)
cvtsi2ssl -0xa4(%rbp), %xmm0
cvtsi2ssl 0x18(%rbp), %xmm1
divss %xmm1, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x4(%rax)
movsd -0x60(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0xc(%rax)
movss -0xd8(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x14(%rax)
cvtsi2ssl -0xa8(%rbp), %xmm0
cvtsi2ssl 0x18(%rbp), %xmm1
divss %xmm1, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x10(%rax)
movsd -0x78(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x18(%rax)
movsd -0x80(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x1c(%rax)
movsd -0x88(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x20(%rax)
movsd -0x90(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x24(%rax)
xorl %eax, %eax
addq $0xf0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop