// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/read.c
// Function: Count_residues
int Count_residues(char *pdb_name, char *chain_to_read){
  int N_res=0, Compression;
  FILE *file_in=Open_compressed_file(pdb_name, &Compression);
  if(file_in==NULL)return(0);
  if(ini_modres==0)Ini_modres(); //modyves: parameters were global static variables

  char string[200];
  int hetatm=0;
  int i, res_num, res_num_old=10000;
  char  chain=' ', chain_old='\0';
  char res_type[5], res_type_old[5], icode=' ', icode_old='.';
  float x, y, z;
  int nchains=0, ic, ini_chain=0, readall=0, *rchain=NULL;
  char *xchain=NULL;//modyves: there were two things called "chain"

  char *chain_pdb=CHAIN_CODE;

  // Count chains to read
  if((chain_to_read[0]=='*')||
     ((chain_to_read[0]=='0')&&(chain_to_read[1]=='1'))){
    readall=1;
    printf("Counting residues in ALL chains\n");
  }else{
    i=0; while(chain_to_read[i]!='\0')i++;
    nchains=i;  if(nchains==0)nchains=1;
    rchain=(int *)malloc(nchains*sizeof(int));
    for(i=0; i<nchains; i++)rchain[i]=0;
    printf("Counting residues in %d chains %s\n",
	   nchains, chain_to_read);
  }

  strcpy(res_type_old,"xxx");
  while(fgets(string, sizeof(string), file_in)!=NULL){

    if(strncmp(string,"ATOM", 4)==0){
      /* Standard residue or DNA basis */
      hetatm=0; if(ini_chain==0)ini_chain=1;
    }else if(strncmp(string,"HETATM", 6)==0){
      if(ini_chain==0)continue;
      hetatm=1;
      /* Cofactor or exotic residue */
    }else if((strncmp(string,"TER",3)==0)&&(N_res>0)){
      chain_pdb++; ini_chain=0; continue;
    }else if(strncmp(string,"ENDMDL", 6)==0){
      break;                                    /* end model */
    }else{
      continue;
    }

    chain=string[21];
    if(chain==' ')chain=*chain_pdb;
    if(readall){
      if(chain!=chain_old){
	//chain_to_read[nchains]=chain;
	nchains++; chain_old=chain;
      }
    }else{
      if((chain_to_read[0]==' ')||(chain_to_read[0]=='\0')){
	chain_to_read[0]=chain; chain_to_read[1]='\0';
      }
      for(ic=0; ic<nchains; ic++){
	if(chain==chain_to_read[ic]){rchain[ic]=1; goto read;}
      }
      continue;
    }

  read:    /* Omit hydrogen if HYD=0 */
    if(HYD==0){
      if((string[13]=='H')||(string[12]=='H') ||
	 (string[13]=='D') ||(string[12]=='D'))continue;
    }

    /* Read residue; check if water molecule */
    res_type[0]=string[17]; res_type[1]=string[18]; res_type[2]=string[19];
    res_type[3]='\0';
    if((hetatm==1)&&((strncmp(res_type,"HOH",3)==0)||
		     (strncmp(res_type,"DOD",3)==0)))continue;
    icode=string[26]; string[26]=' ';
    sscanf(string+22,"%d %f %f %f", &res_num, &x, &y, &z);

    /* New residue */
    if((res_num!=res_num_old)||(icode!=icode_old)||
       (strncmp(res_type, res_type_old, 3)!=0)){
      N_res++;
      strcpy(res_type_old, res_type); icode_old=icode; res_num_old=res_num;
    }
  }
  //N_res++;
  fclose(file_in);
  if(Verbose)printf("%3d residues\n", N_res);
  if(Compression)Delete_tmp_file();
  if(readall==0){
    // Count how many chains have been read
    int nc=0;
    xchain=(char *)malloc(nchains*sizeof(char)); //modyves
    for(i=0; i<nchains; i++){
      if(rchain[i]){xchain[nc]=chain_to_read[i]; nc++;}//modyves
      else{printf("WARNING, chain %c not found\n", chain_to_read[i]);}
    }
    for(i=0; i<nc; i++)chain_to_read[i]=xchain[i];
    nchains=nc;//modyves
  }
  chain_to_read[nchains]='\0';
  printf("Counting %3d residues in %d chains: %s\n",N_res, nchains, chain_to_read);
  if(readall==0)//modyves
  	{free(xchain);xchain=NULL; 
   	 free(rchain);rchain=NULL;
  	}
  return(N_res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x117a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xf7de
movl $0x0, -0x4(%rbp)
jmp 0xfe7e
cmpl $0x0, 0x7d67b(%rip)     # 0x8ce60
jne 0xf7ec
callq 0x13420
movl $0x0, -0xf4(%rbp)
movl $0x2710, -0x100(%rbp)   # imm = 0x2710
movb $0x20, -0x101(%rbp)
movb $0x0, -0x102(%rbp)
movb $0x20, -0x10d(%rbp)
movb $0x2e, -0x10e(%rbp)
movl $0x0, -0x120(%rbp)
movl $0x0, -0x128(%rbp)
movl $0x0, -0x12c(%rbp)
movq $0x0, -0x138(%rbp)
movq $0x0, -0x140(%rbp)
leaq 0x7d619(%rip), %rax     # 0x8ce70
movq %rax, -0x148(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
je 0xf883
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0xf8a0
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x31, %eax
jne 0xf8a0
movl $0x1, -0x12c(%rbp)
leaq 0x6b46e(%rip), %rdi     # 0x7ad02
movb $0x0, %al
callq 0x10d0
jmp 0xf95b
movl $0x0, -0xf8(%rbp)
movq -0x18(%rbp), %rax
movslq -0xf8(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xf8cf
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0xf8aa
movl -0xf8(%rbp), %eax
movl %eax, -0x120(%rbp)
cmpl $0x0, -0x120(%rbp)
jne 0xf8ee
movl $0x1, -0x120(%rbp)
movslq -0x120(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x138(%rbp)
movl $0x0, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
cmpl -0x120(%rbp), %eax
jge 0xf943
movq -0x138(%rbp), %rax
movslq -0xf8(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0xf90f
movl -0x120(%rbp), %esi
movq -0x18(%rbp), %rdx
leaq 0x6b3cf(%rip), %rdi     # 0x7ad23
movb $0x0, %al
callq 0x10d0
leaq -0x10c(%rbp), %rdi
leaq 0x6b3dd(%rip), %rsi     # 0x7ad46
callq 0x1060
leaq -0xf0(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0xc8, %esi
callq 0x1130
cmpq $0x0, %rax
je 0xfcd5
leaq -0xf0(%rbp), %rdi
leaq 0x6b3af(%rip), %rsi     # 0x7ad4a
movl $0x4, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0xf9cc
movl $0x0, -0xf4(%rbp)
cmpl $0x0, -0x128(%rbp)
jne 0xf9c7
movl $0x1, -0x128(%rbp)
jmp 0xfa70
leaq -0xf0(%rbp), %rdi
leaq 0x6b375(%rip), %rsi     # 0x7ad4f
movl $0x6, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0xfa03
cmpl $0x0, -0x128(%rbp)
jne 0xf9f7
jmp 0xf96e
movl $0x1, -0xf4(%rbp)
jmp 0xfa6e
leaq -0xf0(%rbp), %rdi
leaq 0x6b345(%rip), %rsi     # 0x7ad56
movl $0x3, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0xfa47
cmpl $0x0, -0x1c(%rbp)
jle 0xfa47
movq -0x148(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x148(%rbp)
movl $0x0, -0x128(%rbp)
jmp 0xf96e
leaq -0xf0(%rbp), %rdi
leaq 0x6b305(%rip), %rsi     # 0x7ad5a
movl $0x6, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0xfa69
jmp 0xfcd5
jmp 0xf96e
jmp 0xfa70
movb -0xdb(%rbp), %al
movb %al, -0x101(%rbp)
movsbl -0x101(%rbp), %eax
cmpl $0x20, %eax
jne 0xfa97
movq -0x148(%rbp), %rax
movb (%rax), %al
movb %al, -0x101(%rbp)
cmpl $0x0, -0x12c(%rbp)
je 0xfad2
movsbl -0x101(%rbp), %eax
movsbl -0x102(%rbp), %ecx
cmpl %ecx, %eax
je 0xfacd
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
movb -0x101(%rbp), %al
movb %al, -0x102(%rbp)
jmp 0xfb5f
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0xfaea
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xfafe
movb -0x101(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x1(%rax)
movl $0x0, -0x124(%rbp)
movl -0x124(%rbp), %eax
cmpl -0x120(%rbp), %eax
jge 0xfb5a
movsbl -0x101(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x124(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0xfb47
movq -0x138(%rbp), %rax
movslq -0x124(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0xfb61
jmp 0xfb49
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0xfb08
jmp 0xf96e
jmp 0xfb61
leaq 0x7c4b8(%rip), %rax     # 0x8c020
cmpl $0x0, (%rax)
jne 0xfba4
movsbl -0xe3(%rbp), %eax
cmpl $0x48, %eax
je 0xfb9d
movsbl -0xe4(%rbp), %eax
cmpl $0x48, %eax
je 0xfb9d
movsbl -0xe3(%rbp), %eax
cmpl $0x44, %eax
je 0xfb9d
movsbl -0xe4(%rbp), %eax
cmpl $0x44, %eax
jne 0xfba2
jmp 0xf96e
jmp 0xfba4
movb -0xdf(%rbp), %al
movb %al, -0x107(%rbp)
movb -0xde(%rbp), %al
movb %al, -0x106(%rbp)
movb -0xdd(%rbp), %al
movb %al, -0x105(%rbp)
movb $0x0, -0x104(%rbp)
cmpl $0x1, -0xf4(%rbp)
jne 0xfc17
leaq -0x107(%rbp), %rdi
leaq 0x6b17b(%rip), %rsi     # 0x7ad61
movl $0x3, %edx
callq 0x1050
cmpl $0x0, %eax
je 0xfc12
leaq -0x107(%rbp), %rdi
leaq 0x6b162(%rip), %rsi     # 0x7ad65
movl $0x3, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0xfc17
jmp 0xf96e
movb -0xd6(%rbp), %al
movb %al, -0x10d(%rbp)
movb $0x20, -0xd6(%rbp)
leaq -0xf0(%rbp), %rdi
addq $0x16, %rdi
leaq 0x6b12d(%rip), %rsi     # 0x7ad69
leaq -0xfc(%rbp), %rdx
leaq -0x114(%rbp), %rcx
leaq -0x118(%rbp), %r8
leaq -0x11c(%rbp), %r9
movb $0x0, %al
callq 0x11a0
movl -0xfc(%rbp), %eax
cmpl -0x100(%rbp), %eax
jne 0xfc9c
movsbl -0x10d(%rbp), %eax
movsbl -0x10e(%rbp), %ecx
cmpl %ecx, %eax
jne 0xfc9c
leaq -0x107(%rbp), %rdi
leaq -0x10c(%rbp), %rsi
movl $0x3, %edx
callq 0x1050
cmpl $0x0, %eax
je 0xfcd0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
leaq -0x10c(%rbp), %rdi
leaq -0x107(%rbp), %rsi
callq 0x1060
movb -0x10d(%rbp), %al
movb %al, -0x10e(%rbp)
movl -0xfc(%rbp), %eax
movl %eax, -0x100(%rbp)
jmp 0xf96e
movq -0x28(%rbp), %rdi
callq 0x10a0
leaq 0x7c3d3(%rip), %rax     # 0x8c0b8
cmpl $0x0, (%rax)
je 0xfcfb
movl -0x1c(%rbp), %esi
leaq 0x6b081(%rip), %rdi     # 0x7ad75
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x20(%rbp)
je 0xfd06
callq 0x13090
cmpl $0x0, -0x12c(%rbp)
jne 0xfe17
movl $0x0, -0x14c(%rbp)
movslq -0x120(%rbp), %rdi
shlq $0x0, %rdi
callq 0x1180
movq %rax, -0x140(%rbp)
movl $0x0, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
cmpl -0x120(%rbp), %eax
jge 0xfdc3
movq -0x138(%rbp), %rax
movslq -0xf8(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0xfd90
movq -0x18(%rbp), %rax
movslq -0xf8(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x140(%rbp), %rax
movslq -0x14c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0xfdad
movq -0x18(%rbp), %rax
movslq -0xf8(%rbp), %rcx
movsbl (%rax,%rcx), %esi
leaq 0x6afdd(%rip), %rdi     # 0x7ad83
movb $0x0, %al
callq 0x10d0
jmp 0xfdaf
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0xfd3e
movl $0x0, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
cmpl -0x14c(%rbp), %eax
jge 0xfe0b
movq -0x140(%rbp), %rax
movslq -0xf8(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movslq -0xf8(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0xfdcd
movl -0x14c(%rbp), %eax
movl %eax, -0x120(%rbp)
movq -0x18(%rbp), %rax
movslq -0x120(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x1c(%rbp), %esi
movl -0x120(%rbp), %edx
movq -0x18(%rbp), %rcx
leaq 0x6af66(%rip), %rdi     # 0x7ada0
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x12c(%rbp)
jne 0xfe78
movq -0x140(%rbp), %rdi
callq 0x1040
movq $0x0, -0x140(%rbp)
movq -0x138(%rbp), %rdi
callq 0x1040
movq $0x0, -0x138(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw (%rax,%rax)