// File: /workspace/github_c_makefile_star2_O1/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 0x32e47
cmpl $0x0, 0x32dbc(%rip)     # 0x7aa94
jne 0x47cec
movq %rax, %rdi
callq 0x5050c
movl $0x1, 0x32da8(%rip)     # 0x7aa94
movl 0x88(%rsp), %ebx
movl %r14d, %ebp
movl %r14d, 0xc(%rsp)
testl %r14d, %r14d
jle 0x47d15
leaq (,%rbp,4), %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x2110
testl %ebx, %ebx
jle 0x47e23
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)
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x50647
mulsd 0x38(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
cvttsd2si %xmm0, %r15d
leal -0x7(%r15), %eax
cmpl $-0xd, %eax
jb 0x47dae
incl %r13d
cmpl $0x28, %r13d
jne 0x47d7e
movl $0x28, %r13d
cmpl $0x28, %r13d
jne 0x47dca
xorl %r15d, %r15d
leaq 0x156cc(%rip), %rdi     # 0x5d48a
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 0x47e15
xorl %esi, %esi
movl (%r12,%rsi,4), %eax
cmpq %rax, %rbx
jne 0x47e0d
movl (%rcx,%rsi,4), %edx
addl %r15d, %edx
movl %edx, (%r13,%rsi,4)
cmpl (%r8,%r14,4), %edx
jl 0x47e4b
cmpl (%rdi,%r14,4), %edx
jg 0x47e4b
incq %rsi
cmpq %rsi, %rbp
jne 0x47ded
incq %rbx
cmpq 0x20(%rsp), %rbx
jne 0x47d3b
cmpl $0x0, 0xc(%rsp)
jle 0x47e3c
xorl %esi, %esi
cmpl $0x0, (%r13,%rsi,4)
js 0x47ea2
incq %rsi
cmpq %rsi, %rbp
jne 0x47e2c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
leaq 0x1566b(%rip), %rdi     # 0x5d4c0
xorl %eax, %eax
movq %r8, %r12
callq 0x20f0
leaq 0x15680(%rip), %rdi     # 0x5d4e6
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 0x15673(%rip), %rdi     # 0x5d504
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270
leaq 0x15687(%rip), %rdi     # 0x5d530
xorl %eax, %eax
callq 0x20f0
jmp 0x47e98