// File: /workspace/github_c_makefile_star2_O3/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 0x47b93
addq $0x20, %rsp
movaps %xmm0, %xmm3
movl (%rbx), %esi
testl %esi, %esi
movss %xmm0, 0x4(%rsp)
je 0x479bc
leaq 0x15a76(%rip), %rdi     # 0x5d425
xorl %eax, %eax
callq 0x20f0
movss 0x4(%rsp), %xmm3
xorpd %xmm2, %xmm2
testl %r13d, %r13d
jle 0x47ac2
movq %r14, 0x20(%rsp)
movl %r13d, %r13d
xorpd %xmm1, %xmm1
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r14d, %r14d
xorpd %xmm4, %xmm4
movsd %xmm1, 0x8(%rsp)
movsd %xmm4, 0x10(%rsp)
movq 0x70(%rsp), %rax
movq (%rax,%rbp,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 0x47b93
movsd 0x30(%rsp), %xmm4
movss 0x24(%rsp), %xmm3
addq $0x20, %rsp
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
xorl %eax, %eax
ucomiss %xmm3, %xmm0
seta %al
addl %eax, %r14d
addsd %xmm1, %xmm4
mulsd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm1
addl 0x1c(%rsp), %ebx
incq %rbp
cmpq %rbp, %r13
jne 0x479e0
testl %ebx, %ebx
movl 0x78(%rsp), %r13d
je 0x47aa9
leaq 0x15970(%rip), %rdi     # 0x5d3f5
movl %ebx, %esi
movl %r13d, %edx
xorl %eax, %eax
movsd %xmm4, 0x10(%rsp)
callq 0x20f0
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm4
movss 0x4(%rsp), %xmm3
cvtsi2ss %r14d, %xmm5
xorps %xmm0, %xmm0
cmpl $0x1, %r13d
xorpd %xmm2, %xmm2
jne 0x47ace
movq 0x20(%rsp), %r14
jmp 0x47b38
xorps %xmm5, %xmm5
xorpd %xmm4, %xmm4
xorps %xmm0, %xmm0
jmp 0x47b38
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
divsd %xmm0, %xmm4
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
subsd %xmm0, %xmm1
leal -0x1(%r13), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movq 0x20(%rsp), %r14
jb 0x47b0d
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x47b38
movapd %xmm1, %xmm0
movsd %xmm4, 0x10(%rsp)
movss %xmm5, 0x8(%rsp)
callq 0x22a0
movss 0x8(%rsp), %xmm5
movsd 0x10(%rsp), %xmm4
xorpd %xmm2, %xmm2
movss 0x4(%rsp), %xmm3
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
subsd %xmm4, %xmm1
cvtsd2ss %xmm1, %xmm1
ucomisd %xmm2, %xmm0
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
divsd %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
jne 0x47b64
jp 0x47b64
movaps %xmm1, %xmm0
movss %xmm3, 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