// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/site_dynamics.c
// Function: Read_sites_PDB
int Read_sites_PDB(int **site_res, char **chain_res,
		   int *nres_site, char **description,
		   char *pdb, char *chain, struct residue *seq,
		   int Nres, int NMAX, int SMAX)
{
  int Compression=0;
  printf("Reading sites in file %s, chain %s %d residues\n",pdb, chain, Nres);
  FILE *file_in=Open_compressed_file(pdb, &Compression);
  if(file_in==NULL){
    printf("WARNING, file %s not found\n", pdb); return(0);
  }
  int nsites=-1, dsite=0, sres=0, l, i;
  for(i=0; i<NMAX; i++)nres_site[i]=0;
  char string[1000], resnum[6], resnam[5];
  char snam[5], snam_old[5]="   ", ch; i=0;
  while(fgets(string, sizeof(string), file_in)!=NULL){
    if(strncmp(string, "SITE", 4)==0){
      sscanf(string+11, "%s", snam);
      if(strncmp(snam, snam_old, 3)!=0){
	if(nsites>=0)nres_site[nsites]=sres;
	strcpy(snam_old, snam); sres=0; nsites++;
	if(nsites >= NMAX){
	  printf("ERROR, too many sites > %d\n", NMAX); nsites--; break;
	}
      }
      for(l=18; l<60; l+=11){
	i=Read_site(resnum, resnam, &ch, string+l, chain);
	if(i==-2){break;}else if(i==-1){continue;}
	i=Find_residue(resnum, ch, seq, Nres, i);
	if(i<0){
	  printf("WARNING, residue %s_%c_%s not found\n",
		 resnum, ch, resnam); continue;
	}
	if(seq[i].amm!=Code_3_1(resnam)){
	  printf("WARNING, residue %d is %c while it is %s in site\n",
		 i, seq[i].amm, resnam);
	}
	site_res[nsites][sres]=i;
	chain_res[nsites][sres]=ch;
	sres++;
	if(sres > SMAX){
	  printf("ERROR, too many residues > %d\n", SMAX); goto end;
	}
      }
    }else if(strncmp(string+11, "SITE_DESCR", 10)==0){
      description[dsite]=malloc(100*sizeof(char));
      strcpy(description[dsite], string+28);
      dsite++;
    }else{
      if((nsites>=0)||(strncmp(string, "ATOM", 4)==0)){break;}
      else{continue;}
    }
  }
 end:
  fclose(file_in);
  if(Compression)Delete_tmp_file();
  if(nsites>=0)nres_site[nsites]=sres;
  nsites++;
  int num=0, msites=0;
  for(i=0; i<nsites; i++){
    num+=nres_site[i];
    if(nres_site[i]>0)msites++;
  }
  printf("%d residues read in %d binding sites out of %d\n",
	 num, msites, nsites);
  return(nsites);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movq %r8, %r13
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, 0x78(%rsp)
movq %rdi, 0x70(%rsp)
movl 0x4a8(%rsp), %ecx
leaq 0x44(%rsp), %r14
movl $0x0, (%r14)
leaq 0x14d10(%rip), %rdi     # 0x5dd8e
xorl %r12d, %r12d
movq %r8, %rsi
movq %r9, 0x28(%rsp)
movq %r9, %rdx
xorl %eax, %eax
callq 0x20f0
movq %r13, %rdi
movq %r14, %rsi
callq 0xe1e3
testq %rax, %rax
je 0x4939e
movq %rax, %r14
movq %r15, 0x60(%rsp)
movl 0x4b0(%rsp), %eax
testl %eax, %eax
jle 0x490ca
movl %eax, %edx
shlq $0x2, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2110
leaq 0x30(%rsp), %rax
movb $0x0, 0x4(%rax)
movl $0x202020, (%rax)       # imm = 0x202020
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0x80(%rsp), %rbp
movabsq $0x5345445f45544953, %r15 # imm = 0x5345445F45544953
movq $0x0, 0x50(%rsp)
movl $0x0, 0x10(%rsp)
movq %rbp, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
movq %r14, %rdx
callq 0x2170
testq %rax, %rax
je 0x493da
movl 0x80(%rsp), %eax
cmpl $0x45544953, %eax       # imm = 0x45544953
je 0x49161
movq 0x8b(%rsp), %rcx
xorq %r15, %rcx
movzwl 0x93(%rsp), %edx
xorq $0x5243, %rdx           # imm = 0x5243
orq %rcx, %rdx
je 0x491e0
testl %r12d, %r12d
jns 0x493da
cmpl $0x4d4f5441, %eax       # imm = 0x4D4F5441
jne 0x49102
jmp 0x493da
leaq 0x8b(%rsp), %rdi
leaq 0xe0bc(%rip), %rsi      # 0x5722c
leaq 0x4b(%rsp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x2200
movl $0x3, %edx
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x2070
testl %eax, %eax
movq %r14, 0x20(%rsp)
je 0x49218
testl %r12d, %r12d
js 0x491a9
movl %r12d, %eax
movl 0x10(%rsp), %ecx
movl %ecx, (%rbx,%rax,4)
leaq 0x30(%rsp), %rdi
leaq 0x4b(%rsp), %rsi
callq 0x2080
leal 0x1(%r12), %eax
movl $0x0, 0x10(%rsp)
cmpl 0x4b0(%rsp), %eax
movq 0x28(%rsp), %r14
movq 0x4a0(%rsp), %r13
jl 0x49228
jmp 0x4944e
movl $0x64, %edi
callq 0x21e0
movq 0x50(%rsp), %r13
movslq %r13d, %r13
movq 0x60(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %rax, %rdi
leaq 0x9c(%rsp), %rsi
callq 0x2080
incl %r13d
movq %r13, 0x50(%rsp)
jmp 0x49102
movl %r12d, %eax
movq 0x28(%rsp), %r14
movq 0x4a0(%rsp), %r13
movq %rbx, 0x38(%rsp)
movl %eax, 0x14(%rsp)
cltq
movq %rax, 0x68(%rsp)
movl $0x7, %r15d
leaq 0x92(%rsp), %r12
leaq 0x5a(%rsp), %rbx
movq %rbx, %rdi
leaq 0x1b(%rsp), %rsi
leaq 0xf(%rsp), %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0x49470
cmpl $-0x1, %eax
je 0x4936c
cmpl $-0x2, %eax
je 0x4937e
movb 0xf(%rsp), %cl
movb %cl, 0xe(%rsp)
movsbl %cl, %ebp
movq %rbx, %rdi
movl %ebp, %esi
movq %r13, %rdx
movl 0x4a8(%rsp), %ecx
movl %eax, %r8d
callq 0x4953d
movq %rbx, %r14
movq %r13, %rbx
testl %eax, %eax
js 0x49341
movl %eax, %r13d
movl %eax, %ebp
shlq $0x5, %rbp
movb 0x13(%rbx,%rbp), %r14b
leaq 0x1b(%rsp), %rdi
callq 0xf44b
cmpb %al, %r14b
je 0x492ea
movq 0x4a0(%rsp), %rax
addq %rbp, %rax
addq $0x13, %rax
movsbl (%rax), %edx
leaq 0x14b40(%rip), %rdi     # 0x5de1b
movl %r13d, %esi
leaq 0x1b(%rsp), %rcx
xorl %eax, %eax
callq 0x20f0
movq 0x70(%rsp), %rax
movq 0x68(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movslq 0x10(%rsp), %rcx
movl %r13d, (%rax,%rcx,4)
movq 0x78(%rsp), %rax
movq (%rax,%rdx,8), %rax
movb 0xe(%rsp), %dl
movb %dl, (%rax,%rcx)
leal 0x1(%rcx), %eax
movl %eax, 0x10(%rsp)
cmpl 0x4b8(%rsp), %ecx
movq 0x28(%rsp), %r14
leaq 0x5a(%rsp), %rbx
jge 0x493b4
movq 0x4a0(%rsp), %r13
leaq 0x80(%rsp), %rbp
jmp 0x4936c
leaq 0x14aae(%rip), %rdi     # 0x5ddf6
movq %r14, %rsi
movl %ebp, %edx
leaq 0x1b(%rsp), %rcx
xorl %eax, %eax
callq 0x20f0
movq %rbx, %r13
leaq 0x80(%rsp), %rbp
movq %r14, %rbx
movq 0x28(%rsp), %r14
addq $0xb, %r15
addq $0xb, %r12
cmpq $0x31, %r15
jb 0x4924b
movl 0x14(%rsp), %eax
movl %eax, %r12d
movq 0x38(%rsp), %rbx
movq 0x20(%rsp), %r14
movabsq $0x5345445f45544953, %r15 # imm = 0x5345445F45544953
jmp 0x49102
leaq 0x14a19(%rip), %rdi     # 0x5ddbe
movq %r13, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x49439
leaq 0x14a92(%rip), %rdi     # 0x5de4d
movl 0x4b8(%rsp), %esi
xorl %eax, %eax
callq 0x20f0
movl 0x14(%rsp), %eax
movl %eax, %r12d
movq 0x38(%rsp), %rbx
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x20c0
cmpl $0x0, 0x44(%rsp)
je 0x493f0
xorl %eax, %eax
callq 0xf417
testl %r12d, %r12d
js 0x49421
movl %r12d, %eax
movl 0x10(%rsp), %ecx
movl %ecx, (%rbx,%rax,4)
incl %r12d
xorl %eax, %eax
xorl %edx, %edx
xorl %esi, %esi
movl (%rbx,%rax,4), %ecx
addl %ecx, %esi
xorl %edi, %edi
testl %ecx, %ecx
setg %dil
addl %edi, %edx
incq %rax
cmpq %rax, %r12
jne 0x49408
jmp 0x49428
incl %r12d
xorl %esi, %esi
xorl %edx, %edx
leaq 0x14a48(%rip), %rdi     # 0x5de77
movl %r12d, %ecx
xorl %eax, %eax
callq 0x20f0
movl %r12d, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14985(%rip), %rdi     # 0x5ddda
movl $0x0, 0x10(%rsp)
movl 0x4b0(%rsp), %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x493d5