// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/allostery.c
// Function: Random_sites
void Random_sites(int *site_ran, int nres, int *site_res,
		  int *ichain, int *min_chain, int *max_chain,
		  int *all_chain, int nchain,
		  int *ini_chain, int *end_chain)
{
  int THR=6, RMAX=40, i, ic;
  //float RANFACTOR=pow(12.0,1/3.0);
  unsigned long iran=randomgenerator();
  if(ini_ran==0){
    InitRandom((RANDOMTYPE)iran); ini_ran=1;
  }
  for(i=0; i<nres; i++)site_ran[i]=-1;
  for(ic=0; ic<nchain; ic++){
    // Shift all chains independently
    int c=all_chain[ic];
    int shiftmin=ini_chain[c]-min_chain[ic];
    int shiftmax=end_chain[c]-max_chain[ic];
    int shift; i=0;
    while(i<RMAX){
      shift=RandomFloating()*(shiftmax-shiftmin)+shiftmin;
      if((shift>THR)||(shift<-THR))break;
      i++;
    }
    if(i==RMAX){
      printf("WARNING, no allowed random site found in %d attempts\n",
	     RMAX); shift=0;
    }
    for(i=0; i<nres; i++){
      if(ichain[i]==ic){
	site_ran[i]=site_res[i]+shift;
	// Check
	if((site_ran[i]<ini_chain[c])||(site_ran[i]>end_chain[c])){
	    printf("ERROR, incorrect random site %d = %d\n", i,site_ran[i]);
	    printf("Chain %d in site, %d in prot\n", ic, c);
	    printf("Site: ini %d end %d Protein: ini %d end %d\n",
		   min_chain[ic], max_chain[ic], ini_chain[c], end_chain[c]);
	    exit(8);
	}
      }
    }
  }
  for(i=0; i<nres; i++){
    if(site_ran[i]<0){
      printf("ERROR, residue %d not set\n", i); exit(8);
    }
  }
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, 0x30(%rsp)
movl %esi, %r14d
movq %rdi, %r13
callq 0x32a14
cmpl $0x0, 0x32d2e(%rip)     # 0x7aa84
jne 0x47d6a
movq %rax, %rdi
callq 0x503ac
movl $0x1, 0x32d1a(%rip)     # 0x7aa84
movl 0x88(%rsp), %ebx
movl %r14d, %ebp
movl %r14d, 0xc(%rsp)
testl %r14d, %r14d
jle 0x47d93
leaq (,%rbp,4), %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x2110
testl %ebx, %ebx
jle 0x47e94
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %r8
movl %ebx, %eax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movq %r13, 0x28(%rsp)
movq 0x80(%rsp), %rax
movslq (%rax,%rbx,4), %r14
movl (%r8,%r14,4), %eax
movq 0x10(%rsp), %rcx
subl (%rcx,%rbx,4), %eax
movl (%rdi,%r14,4), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x18(%rsp), %rdx
addl (%rdx,%rbx,4), %eax
subl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x28, %r13d
xorl %eax, %eax
callq 0x504e7
mulsd 0x38(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
cvttsd2si %xmm0, %r15d
leal -0x7(%r15), %eax
cmpl $-0xd, %eax
jb 0x47e3b
decl %r13d
jne 0x47dff
xorl %r15d, %r15d
leaq 0x1562b(%rip), %rdi     # 0x5d45a
movl $0x28, %esi
xorl %eax, %eax
callq 0x20f0
cmpl $0x0, 0xc(%rsp)
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %rcx
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %r8
jle 0x47e86
xorl %esi, %esi
movl (%r12,%rsi,4), %eax
cmpq %rax, %rbx
jne 0x47e7e
movl (%rcx,%rsi,4), %edx
addl %r15d, %edx
movl %edx, (%r13,%rsi,4)
cmpl (%r8,%r14,4), %edx
jl 0x47ebc
cmpl (%rdi,%r14,4), %edx
jg 0x47ebc
incq %rsi
cmpq %rsi, %rbp
jne 0x47e5e
incq %rbx
cmpq 0x20(%rsp), %rbx
jne 0x47db9
cmpl $0x0, 0xc(%rsp)
jle 0x47ead
xorl %esi, %esi
cmpl $0x0, (%r13,%rsi,4)
js 0x47f13
incq %rsi
cmpq %rsi, %rbp
jne 0x47e9d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
leaq 0x155ca(%rip), %rdi     # 0x5d490
xorl %eax, %eax
movq %r8, %r12
callq 0x20f0
leaq 0x155df(%rip), %rdi     # 0x5d4b6
movl %ebx, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x20f0
movq 0x10(%rsp), %rax
movl (%rax,%rbx,4), %esi
movq 0x18(%rsp), %rax
movl (%rax,%rbx,4), %edx
movl (%r12,%r14,4), %ecx
movl (%r15,%r14,4), %r8d
leaq 0x155d2(%rip), %rdi     # 0x5d4d4
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280
leaq 0x155e6(%rip), %rdi     # 0x5d500
xorl %eax, %eax
callq 0x20f0
jmp 0x47f09