// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/allostery.c
// Function: Test_pairs
int Test_pairs(struct site_results *res, int *atom_site,
	       float *profile, float **coupling, int Na,
	       int *coupled_site, int **coupled_site_ran, int numran,
	       int ni, int nij, int *atomres)
{

  int n_not=0;

  // Observed site
  double c_ave, c_dev;
  int n_notfound=0;
  c_ave=Pair_site(&c_dev, &n_notfound,
		  coupled_site, ni, nij, atomres, atom_site, coupling, Na);
  if(n_notfound){
    printf("WARNING in Test_pairs, %d reference atoms not found\n",
	   n_notfound);
  }
      
  // Sum over num random sites 
  double ran_pair1=0, ran_pair2=0;
  int num_c_gt=0;
  for(int kran=0; kran<numran; kran++){
    double ave_pair, sigpair;
    ave_pair=Pair_site(&sigpair, &n_notfound,
		       coupled_site_ran[kran], ni, nij,
		       atomres, NULL, coupling, Na);
    if(ave_pair > c_ave)num_c_gt++;
    ran_pair1+=ave_pair;
    ran_pair2+=ave_pair*ave_pair;
    n_not+=n_notfound;
  }
  if(n_not)
    printf("WARNING, %d atoms not found in %d random sites\n",
	   n_not, numran);
  
  Ave_St_dev(&ran_pair1, &ran_pair2, numran);
  float Z_c=(c_ave-ran_pair1);
  if(ran_pair2)Z_c/=ran_pair2;
  res->coup=c_ave; res->Z_c=Z_c; res->P_c= (float)num_c_gt/numran;
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rdx
movl %r8d, %r15d
movq %rcx, %r12
movq %rsi, %rax
movq %rdi, %r14
movq 0x90(%rsp), %r9
movl 0x88(%rsp), %r8d
movl 0x80(%rsp), %ecx
movl 0x78(%rsp), %r13d
leaq 0x1c(%rsp), %rbx
movl $0x0, (%rbx)
subq $0x8, %rsp
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
pushq %r15
pushq %r12
pushq %rax
callq 0x47b0e
addq $0x20, %rsp
movaps %xmm0, %xmm2
movl (%rbx), %esi
testl %esi, %esi
movss %xmm0, 0x4(%rsp)
je 0x47936
leaq 0x15b2c(%rip), %rdi     # 0x5d455
xorl %eax, %eax
callq 0x20f0
movss 0x4(%rsp), %xmm2
testl %r13d, %r13d
jle 0x479ee
movq %r14, 0x8(%rsp)
movl %r13d, %r14d
xorpd %xmm3, %xmm3
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %ebp, %ebp
xorpd %xmm4, %xmm4
movsd %xmm4, 0x10(%rsp)
movsd %xmm3, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq (%rax,%r13,8), %rdx
subq $0x8, %rsp
leaq 0x30(%rsp), %rdi
leaq 0x24(%rsp), %rsi
movl 0x88(%rsp), %ecx
movl 0x90(%rsp), %r8d
movq 0x98(%rsp), %r9
pushq %r15
pushq %r12
pushq $0x0
callq 0x47b0e
movsd 0x30(%rsp), %xmm4
movsd 0x40(%rsp), %xmm3
movss 0x24(%rsp), %xmm2
addq $0x20, %rsp
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
xorl %eax, %eax
ucomiss %xmm2, %xmm0
seta %al
addl %eax, %ebp
addsd %xmm1, %xmm4
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm3
addl 0x1c(%rsp), %ebx
incq %r13
cmpq %r13, %r14
jne 0x47956
cvtsi2ss %ebp, %xmm5
movq 0x8(%rsp), %r14
movl 0x78(%rsp), %r13d
jmp 0x479fb
xorl %ebx, %ebx
xorps %xmm5, %xmm5
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
testl %ebx, %ebx
je 0x47a3c
leaq 0x15a1f(%rip), %rdi     # 0x5d425
movl %ebx, %esi
movl %r13d, %edx
xorl %eax, %eax
movsd %xmm3, 0x20(%rsp)
movsd %xmm4, 0x10(%rsp)
movss %xmm5, 0x8(%rsp)
callq 0x20f0
movss 0x8(%rsp), %xmm5
movsd 0x10(%rsp), %xmm4
movsd 0x20(%rsp), %xmm3
movss 0x4(%rsp), %xmm2
testl %r13d, %r13d
jle 0x47aaf
cmpl $0x1, %r13d
jne 0x47a4d
xorpd %xmm3, %xmm3
jmp 0x47aaf
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
divsd %xmm0, %xmm4
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
subsd %xmm0, %xmm3
leal -0x1(%r13), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jb 0x47a84
sqrtsd %xmm3, %xmm3
jmp 0x47aaf
movapd %xmm3, %xmm0
movsd %xmm4, 0x10(%rsp)
movss %xmm5, 0x8(%rsp)
callq 0x2290
movss 0x8(%rsp), %xmm5
movsd 0x10(%rsp), %xmm4
movss 0x4(%rsp), %xmm2
movapd %xmm0, %xmm3
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
subsd %xmm4, %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
divsd %xmm3, %xmm0
cvtsd2ss %xmm0, %xmm0
jne 0x47adf
jp 0x47adf
movaps %xmm1, %xmm0
movss %xmm2, 0xc(%r14)
xorps %xmm1, %xmm1
cvtsi2ss %r13d, %xmm1
movss %xmm0, 0x14(%r14)
divss %xmm1, %xmm5
movss %xmm5, 0x10(%r14)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq