// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rsi, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
movl 0x488(%rsp), %ecx
leaq 0x150a0(%rip), %rdi     # 0x5dd8e
xorl %r14d, %r14d
movq %r8, %rsi
movq %r9, %rdx
xorl %eax, %eax
callq 0x20f0
leaq 0x11179(%rip), %rsi     # 0x59e7e
movq %rbx, %rdi
callq 0x2220
testq %rax, %rax
je 0x48fa3
movq %rax, %rbp
movq %r12, 0x48(%rsp)
leaq 0xc(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %rax
movl %r14d, (%rax)
leaq 0x2c(%rsp), %rax
movl %r14d, (%rax)
movw $0x0, 0x4(%rax)
leaq 0x20(%rsp), %rax
movb %r14b, 0x4(%rax)
movl %r14d, (%rax)
leaq 0x18(%rsp), %rax
movb %r14b, 0x4(%rax)
movl $0x202020, (%rax)       # imm = 0x202020
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x60(%rsp), %r12
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movq %r12, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
movq %rbp, %rdx
callq 0x2170
testq %rax, %rax
je 0x48fbb
cmpb $0x23, 0x60(%rsp)
je 0x48d6d
movq 0x60(%rsp), %rax
movabsq $0x5345445f45544953, %rcx # imm = 0x5345445F45544953
xorq %rcx, %rax
movzwl 0x68(%rsp), %ecx
xorq $0x5243, %rcx           # imm = 0x5243
orq %rax, %rcx
jne 0x48df6
leaq 0xc(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
movl 0x490(%rsp), %r8d
callq 0x495e8
testl %eax, %eax
jne 0x48fb6
movslq 0xc(%rsp), %r14
movq (%r13,%r14,8), %rdi
leaq 0x72(%rsp), %rsi
callq 0x2080
movl $0x202020, 0x18(%rsp)   # imm = 0x202020
jmp 0x48d6d
movq %r12, %rdi
leaq 0x150e0(%rip), %rsi     # 0x5dee0
leaq 0x27(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x3a(%rsp), %r8
leaq 0x34(%rsp), %r9
xorl %eax, %eax
callq 0x2200
leaq 0x27(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2190
testl %eax, %eax
je 0x48e89
cmpl $0x202020, 0x18(%rsp)   # imm = 0x202020
je 0x48e7a
leaq 0xc(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
movl 0x490(%rsp), %r8d
callq 0x495e8
testl %eax, %eax
jne 0x48fb6
movslq 0xc(%rsp), %r14
movq (%r13,%r14,8), %rdi
leaq 0x1507b(%rip), %rsi     # 0x5dee9
leaq 0x27(%rsp), %rdx
xorl %eax, %eax
callq 0x2270
leaq 0x18(%rsp), %rdi
leaq 0x27(%rsp), %rsi
callq 0x2080
movl 0x34(%rsp), %edx
leaq 0x2c(%rsp), %rdi
leaq 0x14422(%rip), %rsi     # 0x5d2bb
xorl %eax, %eax
callq 0x2270
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 0x4953d
testl %eax, %eax
movl %eax, 0x10(%rsp)
js 0x48f75
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 0xf44b
cmpb %al, 0x14(%rsp)
je 0x48f34
movq 0x480(%rsp), %rax
movq 0x40(%rsp), %rcx
addq %rcx, %rax
addq $0x13, %rax
movsbl (%rax), %edx
leaq 0x14ffe(%rip), %rdi     # 0x5df1d
movl 0x10(%rsp), %esi
leaq 0x20(%rsp), %rcx
leaq 0x27(%rsp), %r8
xorl %eax, %eax
callq 0x20f0
movslq %r14d, %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 0x48d6d
jmp 0x49026
leaq 0x14f75(%rip), %rdi     # 0x5def1
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 0x48d6d
leaq 0x14efd(%rip), %rdi     # 0x5dea7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x49011
movl 0xc(%rsp), %r14d
movq %rbp, %rdi
callq 0x20c0
testl %r14d, %r14d
js 0x48ff6
movl 0x8(%rsp), %eax
movl %r14d, %ecx
movl %eax, (%r15,%rcx,4)
incl %r14d
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movl (%r15,%rax,4), %esi
addl %esi, %edx
xorl %edi, %edi
testl %esi, %esi
setg %dil
addl %edi, %ecx
incq %rax
cmpq %rax, %r14
jne 0x48fdc
jmp 0x48ffd
incl %r14d
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x14f4e(%rip), %rdi     # 0x5df52
movq %rbx, %rsi
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20f0
movl %r14d, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14e20(%rip), %rdi     # 0x5de4d
movl 0x498(%rsp), %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x48fbb