// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/site_dynamics.c
// Function: Read_sites_file
int Read_sites_file(int **site_res, char **chain_res,
		    int *nres_site, char **description,
		    char *file, char *chain, struct residue *seq,
		    int Nres, int NMAX, int SMAX)
{
  printf("Reading sites in file %s, chain %s %d residues\n",file, chain, Nres);
  FILE *file_in=fopen(file, "r");
  if(file_in==NULL){
    printf("WARNING, active site file %s not found\n", file); return(0);
  }
  int nsite=-1, sres=0, i, res; 
  char string[1000], resnum[6]="\0", resnam[5]="\0"; //, icode='\0';
  char snam[5], snam_old[5]="   ", ch[6]; i=-1;
  while(fgets(string, sizeof(string), file_in)!=NULL){
    if(string[0]=='#'){
      continue;
    }else if(strncmp(string, "SITE_DESCRIPTION", 10)==0){
      if(New_site(&nsite, &sres, nres_site, description, NMAX))break;
      strcpy(description[nsite], string+18);
      strcpy(snam_old, "   ");
    }else{
      sscanf(string, "%s%s%s%d", snam, resnam, ch, &res); //, &icode
      if(strcmp(snam, snam_old)!=0){
	if(strcmp(snam_old, "   ")!=0){
	  if(New_site(&nsite, &sres, nres_site, description, NMAX))break;
	  sprintf(description[nsite], "SITE_%s", snam);
	}
	strcpy(snam_old, snam);
      }
      //if(icode=='\n')icode='\0';
      //sprintf(resnum, "%d%c", res, icode);
      sprintf(resnum, "%d", res);
      i=Find_residue(resnum, ch[0], seq, Nres, i+1);
      if(i<0){
	printf("Residue %s_%s_%c discarded, chain: %s L=%d\n",
	       resnam, resnum,ch[0],chain,Nres); continue;
      }
      if(seq[i].amm!=Code_3_1(resnam)){
	printf("WARNING, residue %d is %c while it is %s in site %s\n",
	       i, seq[i].amm, resnam, snam);
      }
      site_res[nsite][sres]=i;
      chain_res[nsite][sres]=ch[0];
      sres++;
      if(sres > SMAX){
	printf("ERROR, too many residues > %d\n", SMAX); goto end;
      }
    }
  }
 end:
  fclose(file_in);
  if(nsite>=0)nres_site[nsite]=sres;
  nsite++;
  int num=0, msites=0;
  for(i=0; i<nsite; i++){
    num+=nres_site[i];
    if(nres_site[i]>0)msites++;
  }
  printf("file %s, reading %d residues in %d binding sites out of %d\n",
	 file, num, msites, nsite);
  return(nsite);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %r9, %r12
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
movl 0x488(%rsp), %ecx
leaq 0x14f1b(%rip), %rdi     # 0x57cfe
xorl %r15d, %r15d
movq %r8, %rsi
movq %r9, %rdx
xorl %eax, %eax
callq 0x20f0
leaq 0x10fe4(%rip), %rsi     # 0x53dde
movq %rbx, %rdi
callq 0x2210
testq %rax, %rax
je 0x4307f
movq %rax, %rbp
movq %r12, 0x48(%rsp)
leaq 0xc(%rsp), %rax
orl $-0x1, (%rax)
leaq 0x8(%rsp), %rax
andl $0x0, (%rax)
leaq 0x2c(%rsp), %rax
andw $0x0, 0x4(%rax)
andl $0x0, (%rax)
xorl %eax, %eax
leaq 0x20(%rsp), %rcx
movb %al, 0x4(%rcx)
andl $0x0, (%rcx)
leaq 0x18(%rsp), %rcx
movb %al, 0x4(%rcx)
movl $0x202020, (%rcx)       # imm = 0x202020
pushq $-0x1
popq %r15
leaq 0x60(%rsp), %r12
movl %r15d, 0x10(%rsp)
movq %r12, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
movq %rbp, %rdx
callq 0x2170
testq %rax, %rax
je 0x43097
cmpb $0x23, 0x60(%rsp)
je 0x42e59
movq %r12, %rdi
leaq 0x14fbc(%rip), %rsi     # 0x57e3f
pushq $0xa
popq %rdx
callq 0x2200
testl %eax, %eax
jne 0x42ed2
leaq 0xc(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r14, %rdx
movq %r13, %rcx
movl 0x490(%rsp), %r8d
callq 0x43664
testl %eax, %eax
jne 0x43092
movslq 0xc(%rsp), %r15
movq (%r13,%r15,8), %rdi
leaq 0x72(%rsp), %rsi
callq 0x2080
movl $0x202020, 0x18(%rsp)   # imm = 0x202020
jmp 0x42e59
movq %r12, %rdi
leaq 0x14f74(%rip), %rsi     # 0x57e50
leaq 0x27(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x3a(%rsp), %r8
leaq 0x34(%rsp), %r9
xorl %eax, %eax
callq 0x21f0
leaq 0x27(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2180
testl %eax, %eax
je 0x42f65
cmpl $0x202020, 0x18(%rsp)   # imm = 0x202020
je 0x42f56
leaq 0xc(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r14, %rdx
movq %r13, %rcx
movl 0x490(%rsp), %r8d
callq 0x43664
testl %eax, %eax
jne 0x43092
movslq 0xc(%rsp), %r15
movq (%r13,%r15,8), %rdi
leaq 0x14f0f(%rip), %rsi     # 0x57e59
leaq 0x27(%rsp), %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x18(%rsp), %rdi
leaq 0x27(%rsp), %rsi
callq 0x2080
movl 0x34(%rsp), %edx
leaq 0x2c(%rsp), %rdi
leaq 0x142b6(%rip), %rsi     # 0x5722b
xorl %eax, %eax
callq 0x2260
movsbl 0x3a(%rsp), %esi
movl 0x10(%rsp), %r8d
incl %r8d
leaq 0x2c(%rsp), %rdi
movl %esi, 0x14(%rsp)
movq 0x480(%rsp), %rdx
movl 0x488(%rsp), %ecx
callq 0x435c2
testl %eax, %eax
movl %eax, 0x10(%rsp)
js 0x43051
movl %eax, %edx
shlq $0x5, %rdx
movq 0x480(%rsp), %rcx
movq %rdx, 0x40(%rsp)
movb 0x13(%rcx,%rdx), %cl
movb %cl, 0x14(%rsp)
leaq 0x20(%rsp), %rdi
callq 0xea8b
cmpb %al, 0x14(%rsp)
je 0x43010
movq 0x480(%rsp), %rax
movq 0x40(%rsp), %rcx
addq %rcx, %rax
addq $0x13, %rax
movsbl (%rax), %edx
leaq 0x14e92(%rip), %rdi     # 0x57e8d
movl 0x10(%rsp), %esi
leaq 0x20(%rsp), %rcx
leaq 0x27(%rsp), %r8
xorl %eax, %eax
callq 0x20f0
movslq %r15d, %rax
movq 0x50(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movslq 0x8(%rsp), %rdx
movl 0x10(%rsp), %esi
movl %esi, (%rcx,%rdx,4)
movb 0x3a(%rsp), %cl
movq 0x58(%rsp), %rsi
movq (%rsi,%rax,8), %rax
movb %cl, (%rax,%rdx)
leal 0x1(%rdx), %eax
movl %eax, 0x8(%rsp)
cmpl 0x498(%rsp), %edx
jl 0x42e59
jmp 0x43100
leaq 0x14e09(%rip), %rdi     # 0x57e61
leaq 0x20(%rsp), %rsi
leaq 0x2c(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq 0x48(%rsp), %r8
movl 0x488(%rsp), %r9d
xorl %eax, %eax
callq 0x20f0
jmp 0x42e59
leaq 0x14d91(%rip), %rdi     # 0x57e17
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x430eb
movl 0xc(%rsp), %r15d
movq %rbp, %rdi
callq 0x20c0
testl %r15d, %r15d
js 0x430af
movl 0x8(%rsp), %eax
movl %r15d, %ecx
movl %eax, (%r14,%rcx,4)
movslq %r15d, %rax
incl %r15d
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rax, %rsi
jg 0x430d7
movl (%r14,%rsi,4), %edi
addl %edi, %edx
xorl %r8d, %r8d
testl %edi, %edi
setg %r8b
addl %r8d, %ecx
incq %rsi
jmp 0x430bb
leaq 0x14de4(%rip), %rdi     # 0x57ec2
movq %rbx, %rsi
movl %r15d, %r8d
xorl %eax, %eax
callq 0x20f0
movl %r15d, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14cb6(%rip), %rdi     # 0x57dbd
movl 0x498(%rsp), %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x43097