// File: /workspace/github_c_makefile_star2_O1/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 $0x438, %rsp            # imm = 0x438
movq %r9, %r15
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
movl 0x478(%rsp), %ecx
leaq 0x1512b(%rip), %rdi     # 0x5ddbe
xorl %r13d, %r13d
movq %r8, %rsi
movq %r9, %rdx
xorl %eax, %eax
callq 0x20f0
leaq 0x11230(%rip), %rsi     # 0x59eda
movq %rbx, %rdi
callq 0x2210
testq %rax, %rax
je 0x48f2f
movq %rax, %rbp
movq %rsp, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x4(%rsp), %rax
movl %r13d, (%rax)
leaq 0x24(%rsp), %rax
movl %r13d, (%rax)
movw $0x0, 0x4(%rax)
leaq 0x18(%rsp), %rax
movb %r13b, 0x4(%rax)
movl %r13d, (%rax)
leaq 0x10(%rsp), %rax
movb %r13b, 0x4(%rax)
movl $0x202020, (%rax)       # imm = 0x202020
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
movq %rbp, %rdx
callq 0x2170
testq %rax, %rax
je 0x48f57
cmpb $0x23, 0x50(%rsp)
je 0x48d05
movq 0x50(%rsp), %rax
movabsq $0x5345445f45544953, %rcx # imm = 0x5345445F45544953
xorq %rcx, %rax
movzwl 0x58(%rsp), %ecx
xorq $0x5243, %rcx           # imm = 0x5243
orq %rax, %rcx
jne 0x48d8a
movq %rsp, %rdi
leaq 0x4(%rsp), %rsi
movq %r14, %rdx
movq %r12, %rcx
movl 0x480(%rsp), %r8d
callq 0x49579
testl %eax, %eax
jne 0x48f57
movslq (%rsp), %rax
movq (%r12,%rax,8), %rdi
leaq 0x62(%rsp), %rsi
callq 0x2080
movl $0x202020, 0x10(%rsp)   # imm = 0x202020
jmp 0x48d05
movq %r13, %rdi
leaq 0x1517c(%rip), %rsi     # 0x5df10
leaq 0x1f(%rsp), %rdx
leaq 0x18(%rsp), %rcx
leaq 0x32(%rsp), %r8
leaq 0x2c(%rsp), %r9
xorl %eax, %eax
callq 0x21f0
leaq 0x1f(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2180
testl %eax, %eax
je 0x48e19
cmpl $0x202020, 0x10(%rsp)   # imm = 0x202020
je 0x48e0a
movq %rsp, %rdi
leaq 0x4(%rsp), %rsi
movq %r14, %rdx
movq %r12, %rcx
movl 0x480(%rsp), %r8d
callq 0x49579
testl %eax, %eax
jne 0x48f57
movslq (%rsp), %rax
movq (%r12,%rax,8), %rdi
leaq 0x1511b(%rip), %rsi     # 0x5df19
leaq 0x1f(%rsp), %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x10(%rsp), %rdi
leaq 0x1f(%rsp), %rsi
callq 0x2080
movl 0x2c(%rsp), %edx
leaq 0x24(%rsp), %rdi
leaq 0x144c2(%rip), %rsi     # 0x5d2eb
xorl %eax, %eax
callq 0x2260
movsbl 0x32(%rsp), %esi
movl 0x8(%rsp), %r8d
incl %r8d
leaq 0x24(%rsp), %rdi
movl %esi, 0xc(%rsp)
movq 0x470(%rsp), %rdx
movl 0x478(%rsp), %ecx
callq 0x494ce
testl %eax, %eax
movl %eax, 0x8(%rsp)
js 0x48f03
movl %eax, %edx
shlq $0x5, %rdx
movq 0x470(%rsp), %rcx
movq %rdx, 0x38(%rsp)
movb 0x13(%rcx,%rdx), %cl
movb %cl, 0xc(%rsp)
leaq 0x18(%rsp), %rdi
callq 0xf6d3
cmpb %al, 0xc(%rsp)
je 0x48ec4
movq 0x470(%rsp), %rax
movq 0x38(%rsp), %rcx
addq %rcx, %rax
addq $0x13, %rax
movsbl (%rax), %edx
leaq 0x1509e(%rip), %rdi     # 0x5df4d
movl 0x8(%rsp), %esi
leaq 0x18(%rsp), %rcx
leaq 0x1f(%rsp), %r8
xorl %eax, %eax
callq 0x20f0
movslq (%rsp), %rax
movq 0x40(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movslq 0x4(%rsp), %rdx
movl 0x8(%rsp), %esi
movl %esi, (%rcx,%rdx,4)
movb 0x32(%rsp), %cl
movq 0x48(%rsp), %rsi
movq (%rsi,%rax,8), %rax
movb %cl, (%rax,%rdx)
leal 0x1(%rdx), %eax
movl %eax, 0x4(%rsp)
cmpl 0x488(%rsp), %edx
jl 0x48d05
jmp 0x48f42
leaq 0x15017(%rip), %rdi     # 0x5df21
leaq 0x18(%rsp), %rsi
leaq 0x24(%rsp), %rdx
movl 0xc(%rsp), %ecx
movq %r15, %r8
movl 0x478(%rsp), %r9d
xorl %eax, %eax
callq 0x20f0
jmp 0x48d05
leaq 0x14fa1(%rip), %rdi     # 0x5ded7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x48fb8
leaq 0x14f34(%rip), %rdi     # 0x5de7d
movl 0x488(%rsp), %esi
xorl %eax, %eax
callq 0x20f0
movq %rbp, %rdi
callq 0x20c0
movslq (%rsp), %rax
testq %rax, %rax
js 0x48f70
movl 0x4(%rsp), %ecx
movl %ecx, (%r14,%rax,4)
leal 0x1(%rax), %r13d
movl %r13d, (%rsp)
testl %eax, %eax
js 0x48fa0
incl %eax
xorl %esi, %esi
xorl %ecx, %ecx
xorl %edx, %edx
movl (%r14,%rsi,4), %edi
addl %edi, %edx
xorl %r8d, %r8d
testl %edi, %edi
setg %r8b
addl %r8d, %ecx
incq %rsi
cmpq %rsi, %rax
jne 0x48f84
jmp 0x48fa4
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x14fd7(%rip), %rdi     # 0x5df82
movq %rbx, %rsi
movl %r13d, %r8d
xorl %eax, %eax
callq 0x20f0
movl %r13d, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq