// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0x88, %rsp
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movl %r9d, -0x3c(%rbp)
movl $0x190, -0x40(%rbp)     # imm = 0x190
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x67eed
movslq -0x40(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0x40(%rbp), %rdi
shlq $0x0, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x28(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x67e92
movq 0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x67f4f
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %r8
movq 0x20(%rbp), %r9
movq 0x30(%rbp), %rbx
movl 0x38(%rbp), %r11d
movl -0x3c(%rbp), %r10d
movl -0x40(%rbp), %eax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x68630
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x67f4d
movq -0x38(%rbp), %rdi
movq 0x10(%rbp), %rsi
callq 0x1060
jmp 0x67f4f
cmpl $0x0, -0x44(%rbp)
jne 0x67fdf
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
movq 0x30(%rbp), %rbx
movl 0x38(%rbp), %r11d
movl -0x3c(%rbp), %r10d
movl -0x40(%rbp), %eax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x68a60
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x67fad
movq -0x38(%rbp), %rdi
movq 0x18(%rbp), %rsi
callq 0x1060
cmpl $0x0, 0x40(%rbp)
je 0x67fdd
cmpl $0x0, -0x44(%rbp)
je 0x67fdd
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl -0x44(%rbp), %ecx
movq 0x30(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x20(%rbp), %rax
movq %rax, (%rsp)
callq 0x67580
jmp 0x67fdf
cmpl $0x0, -0x44(%rbp)
jne 0x67ff1
movl $0x0, -0xc(%rbp)
jmp 0x6822a
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x6809f
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x6804e
movl $0x14, %edi
callq 0x1180
movq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x48(%rbp), %edx
addl $0x1, %edx
leaq 0x1b139(%rip), %rsi     # 0x8317e
movb $0x0, %al
callq 0x1200
jmp 0x6808f
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x6808d
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x6807f
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
jmp 0x6808d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x6805e
jmp 0x6808f
jmp 0x68091
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x67ff8
movl $0x0, -0x54(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x68224
movq -0x20(%rbp), %rax
movslq -0x48(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jg 0x680cc
jmp 0x68216
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x48(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x68148
movq -0x28(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x5c(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x5d(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl 0x28(%rbp), %eax
jge 0x6813b
movsbl -0x5d(%rbp), %eax
movq 0x20(%rbp), %rcx
movslq -0x64(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x6812e
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x6813b
jmp 0x68130
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x68107
jmp 0x6813d
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x680da
movl -0x58(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x48(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x68214
movl -0x54(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x6820b
movq -0x20(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1060
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x48(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x68209
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x68(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x68(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x68(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x68(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x681a2
jmp 0x6820b
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x68216
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x680ad
movl -0x54(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x88, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)