// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r9, %rdx
movl %r8d, %r14d
movq %rcx, %r15
movq %rsi, %rax
movq %rdi, 0x28(%rsp)
movq 0xa0(%rsp), %r9
movl 0x98(%rsp), %r8d
movl 0x90(%rsp), %ecx
movl 0x88(%rsp), %ebp
leaq 0x1c(%rsp), %rbx
andl $0x0, (%rbx)
subq $0x8, %rsp
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
pushq %r14
pushq %r15
pushq %rax
callq 0x41dd3
addq $0x20, %rsp
movss %xmm0, 0xc(%rsp)
movl (%rbx), %esi
testl %esi, %esi
je 0x41c6f
leaq 0x1572d(%rip), %rdi     # 0x57395
xorl %eax, %eax
callq 0x20f0
xorl %r12d, %r12d
testl %ebp, %ebp
movl $0x0, %r13d
cmovgl %ebp, %r13d
xorps %xmm0, %xmm0
xorpd %xmm2, %xmm2
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpq %r12, %r13
je 0x41d1e
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %rdx
subq $0x8, %rsp
leaq 0x28(%rsp), %rdi
leaq 0x24(%rsp), %rsi
movl 0x98(%rsp), %ecx
movl 0xa0(%rsp), %r8d
movq 0xa8(%rsp), %r9
pushq %r14
pushq %r15
pushq $0x0
movsd %xmm0, 0x30(%rsp)
movsd %xmm2, 0x50(%rsp)
callq 0x41dd3
movsd 0x50(%rsp), %xmm2
addq $0x20, %rsp
xorl %eax, %eax
ucomiss 0xc(%rsp), %xmm0
seta %al
cvtss2sd %xmm0, %xmm0
addl %eax, %ebp
addsd %xmm0, %xmm2
mulsd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
addl 0x1c(%rsp), %ebx
incq %r12
jmp 0x41c89
movsd %xmm2, 0x20(%rsp)
movsd %xmm0, 0x38(%rsp)
testl %ebx, %ebx
movl 0x88(%rsp), %r15d
je 0x41d49
leaq 0x15628(%rip), %rdi     # 0x57365
movl %ebx, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x20f0
cvtss2sd 0xc(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %rbx
leaq 0x38(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x41ba0
movsd 0x10(%rsp), %xmm0
subsd (%rbx), %xmm0
cvtsd2ss %xmm0, %xmm1
movsd (%r14), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
cvtss2sd %xmm1, %xmm2
divsd %xmm0, %xmm2
cvtsd2ss %xmm2, %xmm0
jne 0x41d9b
jp 0x41d9b
movaps %xmm1, %xmm0
cvtsi2ss %ebp, %xmm1
movq 0x28(%rsp), %rax
movss 0xc(%rsp), %xmm2
movss %xmm2, 0xc(%rax)
cvtsi2ss %r15d, %xmm2
movss %xmm0, 0x14(%rax)
divss %xmm2, %xmm1
movss %xmm1, 0x10(%rax)
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq