// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/site_dynamics.c
// Function: Read_sites
int Read_sites(int **site_res, int *nres_site, char **chain_res,
	       char **description, char *file_site,
	       int NMAX, char *SITES, char *pdb, char *chain, int Nchain,
	       struct residue *seq, int Nres, int PRINT_SITE)
{
  int SMAX=400, N_sites=0, i;
  for(i=0; i<NMAX; i++){
    site_res[i]=malloc(SMAX*sizeof(int));
    chain_res[i]=malloc(SMAX*sizeof(char));
    description[i]=NULL;
  }
  if(SITES[0]!='\0'){
    N_sites=Read_sites_file(site_res, chain_res, nres_site, description,
			    SITES, chain, seq, Nres, NMAX, SMAX);
    if(N_sites)strcpy(file_site, SITES);
  }
  if(N_sites==0){
    N_sites=Read_sites_PDB(site_res, chain_res, nres_site, description,
			   pdb, chain, seq, Nres, NMAX, SMAX);
    if(N_sites)strcpy(file_site, pdb);
    // Print site
    if(PRINT_SITE && N_sites)
      Print_sites(site_res, nres_site, description, N_sites,
		  seq, pdb, chain);
  }
  if(N_sites==0)return(0);
  for(i=0; i<N_sites; i++){
    if(description[i]==NULL){
      description[i]=malloc(20*sizeof(char));
      sprintf(description[i], "site%d", i+1);
    }else{
      char *ptr=description[i];
      while(*ptr!='\0'){
	if(*ptr=='\n'){*ptr='\0'; break;} ptr++;
      } 
    }
  }

  // Eliminate sites that are not in the selected chains 
  int S=0;
  for(i=0; i<N_sites; i++){
    if(nres_site[i]<=0)continue;
    int n=0;
    for(int j=0; j<nres_site[i]; j++){
      char chj=chain_res[i][j]; int nc;
      for(nc=0; nc<Nchain; nc++){
	if(chj==chain[nc]){n++; break;}
      }
    }
    if(n==nres_site[i]){
      if(S!=i){
	nres_site[S]=nres_site[i];
	strcpy(description[S], description[i]);
	for(int j=0; j<nres_site[i]; j++){
	  site_res[S][j]=site_res[i][j];
	  chain_res[S][j]=chain_res[i][j];
	}
      }
      S++;
    }
  }
  return(S);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %ebp
movq %r8, 0x8(%rsp)
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, (%rsp)
movq %rdi, %r13
testl %r9d, %r9d
jle 0x48841
movl %ebp, %ebx
xorl %r15d, %r15d
movl $0x640, %edi            # imm = 0x640
callq 0x21e0
movq %rax, (%r13,%r15,8)
movl $0x190, %edi            # imm = 0x190
callq 0x21e0
movq %rax, (%r14,%r15,8)
movq $0x0, (%r12,%r15,8)
incq %r15
cmpq %r15, %rbx
jne 0x48814
movq %r13, 0x10(%rsp)
movl 0x88(%rsp), %r10d
movq 0x80(%rsp), %rbx
movq 0x70(%rsp), %r13
movq 0x60(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x488af
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq (%rsp), %rdx
movq %r12, %rcx
movq 0x60(%rsp), %r8
movq %r13, %r9
pushq $0x190                  # imm = 0x190
pushq %rbp
pushq %r10
pushq %rbx
movq %r10, %r15
callq 0x48cb9
movq %r15, %r10
movq 0x80(%rsp), %rsi
addq $0x20, %rsp
testl %eax, %eax
je 0x488af
movl %eax, %r15d
movq 0x8(%rsp), %rdi
callq 0x2080
jmp 0x48927
movq 0x68(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq (%rsp), %rdx
movq %r12, %rcx
movq %r13, %r9
pushq $0x190                  # imm = 0x190
pushq %rbp
pushq %r10
movq %rbx, %rbp
pushq %rbx
callq 0x49040
addq $0x20, %rsp
testl %eax, %eax
je 0x48a60
movl %eax, %r15d
movl 0x90(%rsp), %ebx
movq 0x8(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x2080
testl %ebx, %ebx
je 0x48927
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movl %r15d, %ecx
movq %rbp, %r8
movq 0x70(%rsp), %r9
pushq %r13
callq 0x4829a
addq $0x10, %rsp
testl %r15d, %r15d
jle 0x48a60
movl 0x78(%rsp), %ebp
movl %r15d, %r10d
xorl %ebx, %ebx
movq (%rsp), %r9
movq %r10, 0x8(%rsp)
movq (%r12,%rbx,8), %rax
testq %rax, %rax
je 0x4895c
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x4898c
cmpl $0xa, %ecx
je 0x48989
incq %rax
jmp 0x4894b
movl $0x14, %edi
callq 0x21e0
movq %rax, (%r12,%rbx,8)
leal 0x1(%rbx), %edx
movq %rax, %rdi
leaq 0x15410(%rip), %rsi     # 0x5dd87
xorl %eax, %eax
callq 0x2270
movq 0x8(%rsp), %r10
movq (%rsp), %r9
jmp 0x4898c
movb $0x0, (%rax)
incq %rbx
cmpq %r10, %rbx
jne 0x48942
testl %r15d, %r15d
jle 0x48a60
movl %ebp, %r15d
xorl %ebx, %ebx
xorl %eax, %eax
movq %r12, 0x20(%rsp)
movslq (%r9,%rbx,4), %r11
testq %r11, %r11
jle 0x48a52
movq (%r14,%rbx,8), %rcx
xorl %edx, %edx
xorl %esi, %esi
testl %ebp, %ebp
jle 0x489dc
movb (%rcx,%rdx), %dil
xorl %r8d, %r8d
cmpb (%r13,%r8), %dil
je 0x489da
incq %r8
cmpq %r8, %r15
jne 0x489c9
jmp 0x489dc
incl %esi
incq %rdx
cmpq %r11, %rdx
jne 0x489be
cmpl %r11d, %esi
jne 0x48a52
movl %eax, %ecx
cmpq %rcx, %rbx
je 0x48a50
movslq %eax, %r12
movl %r11d, (%r9,%r12,4)
movq 0x20(%rsp), %rcx
movq (%rcx,%r12,8), %rdi
movq (%rcx,%rbx,8), %rsi
movl %eax, 0x1c(%rsp)
callq 0x2080
movl 0x1c(%rsp), %eax
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rsi
movq (%rsp), %r9
cmpl $0x0, (%r9,%rbx,4)
jle 0x48a50
xorl %edi, %edi
movq (%rsi,%rbx,8), %rcx
movl (%rcx,%rdi,4), %ecx
movq (%rsi,%r12,8), %rdx
movl %ecx, (%rdx,%rdi,4)
movq (%r14,%rbx,8), %rcx
movb (%rcx,%rdi), %cl
movq (%r14,%r12,8), %rdx
movb %cl, (%rdx,%rdi)
incq %rdi
movslq (%r9,%rbx,4), %rcx
cmpq %rcx, %rdi
jl 0x48a28
incl %eax
incq %rbx
cmpq %r10, %rbx
jne 0x489a9
jmp 0x48a62
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq