// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %r9, 0x8(%rsp)
movq %r8, (%rsp)
movq %rcx, %r13
movq %rdx, 0x10(%rsp)
movl %esi, %r15d
movq %rdi, %r12
callq 0x2f672
cmpl $0x0, 0x33b79(%rip)     # 0x75a94
jne 0x41f2f
movq %rax, %rdi
callq 0x49ebc
movl $0x1, 0x33b65(%rip)     # 0x75a94
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rcx
movl 0x78(%rsp), %edx
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
cmpq %rax, %r15
je 0x41f5b
orl $-0x1, (%r12,%rax,4)
incq %rax
jmp 0x41f4c
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %edx
movq %rdx, 0x20(%rsp)
xorl %ebx, %ebx
movq %r12, 0x18(%rsp)
cmpq 0x20(%rsp), %rbx
je 0x4203a
movq 0x70(%rsp), %rax
movslq (%rax,%rbx,4), %r14
movl (%rcx,%r14,4), %eax
movq (%rsp), %rcx
subl (%rcx,%rbx,4), %eax
movl (%rdi,%r14,4), %ecx
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x8(%rsp), %rdx
addl (%rdx,%rbx,4), %eax
subl %eax, %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x28(%rsp)
pushq $0x29
popq %r12
decl %r12d
je 0x41fd9
xorl %eax, %eax
callq 0x49ffd
mulsd 0x28(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %ebp
leal -0x7(%rbp), %eax
cmpl $-0xd, %eax
jae 0x41fb3
jmp 0x41fec
xorl %ebp, %ebp
leaq 0x153e8(%rip), %rdi     # 0x573ca
pushq $0x28
popq %rsi
xorl %eax, %eax
callq 0x20f0
xorl %esi, %esi
movq 0x18(%rsp), %r12
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rcx
movq 0x10(%rsp), %r8
cmpq %rsi, %r15
je 0x42032
movl (%r13,%rsi,4), %eax
cmpq %rax, %rbx
jne 0x4202d
movl (%r8,%rsi,4), %edx
addl %ebp, %edx
movl %edx, (%r12,%rsi,4)
cmpl (%rcx,%r14,4), %edx
jl 0x4205c
cmpl (%rdi,%r14,4), %edx
jg 0x4205c
incq %rsi
jmp 0x42008
incq %rbx
jmp 0x41f6e
xorl %esi, %esi
cmpq %rsi, %r15
je 0x4204d
cmpl $0x0, (%r12,%rsi,4)
js 0x420b0
incq %rsi
jmp 0x4203c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r15
leaq 0x1539a(%rip), %rdi     # 0x57400
xorl %eax, %eax
movq %rcx, %r12
callq 0x20f0
leaq 0x153af(%rip), %rdi     # 0x57426
movl %ebx, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x20f0
movq (%rsp), %rax
movl (%rax,%rbx,4), %esi
movq 0x8(%rsp), %rax
movl (%rax,%rbx,4), %edx
movl (%r12,%r14,4), %ecx
movl (%r15,%r14,4), %r8d
leaq 0x153a3(%rip), %rdi     # 0x57444
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270
leaq 0x153b9(%rip), %rdi     # 0x57470
xorl %eax, %eax
callq 0x20f0
jmp 0x420a8