// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/seqres.c
// Function: Read_seqres
int Read_seqres(char **seqres, int *N_seqres, int NCHAIN,
		char *file_pdb, char *chain_to_read)
{
  /* Open file */
  int Compression;
  FILE *file_in=Open_compressed_file(file_pdb, &Compression);
  if(file_in==NULL)return(0);

  int nchain=0, read=0, L=0, n=0;
  char string[200], chain_old='-', *seq=NULL;
  while(fgets(string, sizeof(string), file_in)!=NULL){
    if(strncmp(string,"ATOM", 4)==0)break;
    if(strncmp(string,"SEQRES", 6)==0){
      char chain=string[11];
      if(chain!=chain_old){
	if(n){
	  printf("%d residues read %d expected for chain %d\n",
		 n, L, nchain); n=0;
	}
	chain_old=chain; int ic=0;
	while((chain_to_read[ic]!='\0')&&(chain!=chain_to_read[ic]))ic++;
	if(chain_to_read[ic]!=chain){read=0; continue;}
	read=1; sscanf(string+12, "%d", &L);
	printf("Reading chain %d %c %d residues\n", nchain, chain, L);
	seqres[nchain]=malloc(L*sizeof(char)); seq=seqres[nchain];
	N_seqres[nchain]=L;
	nchain++;
      }
      if(read==0)continue;
      char amm[3], aa3[4], *str=string+19;
      for(int k=0; k<13; k++){
	sscanf(str, "%s", aa3); str+=4;
	int exo=0; Get_amm(amm, &exo, aa3, 0, 0);
	*seq=amm[1]; seq++; n++; if(n==L)break;
      }
    }
  }
  if(n){
    printf("%d residues read %d expected for chain %d\n",
	   n, L, nchain); n=0;
  }
  if(nchain!=NCHAIN){
    printf("WARNING in SEQRES, %d chains expected (%s), %d found\n",
	   NCHAIN, chain_to_read, nchain);
    if(nchain==0){printf("Getting residues from atoms\n"); return(-1);}
    else{printf("Exiting\n"); exit(8);}
  }
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r8, 0x30(%rsp)
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x48(%rsp), %rsi
movq %rcx, %rdi
callq 0xd804
testq %rax, %rax
je 0xf7dc
movq %rax, %r13
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movl %ebx, 0x28(%rsp)
movq %rsp, %rax
andl $0x0, (%rax)
movb $0x2d, %bl
leaq 0x50(%rsp), %r15
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movl %ebx, %r14d
movq %r15, %rdi
movl $0xc8, %esi
movq %r13, %rdx
callq 0x2170
testq %rax, %rax
je 0xf788
cmpl $0x4d4f5441, 0x50(%rsp) # imm = 0x4D4F5441
je 0xf788
movq %r15, %rdi
leaq 0x409a3(%rip), %rsi     # 0x4ff92
pushq $0x6
popq %rdx
callq 0x2200
testl %eax, %eax
jne 0xf6a9
movb 0x5b(%rsp), %bl
cmpb %r14b, %bl
jne 0xf6b1
testl %r12d, %r12d
movl $0x0, %r12d
je 0xf5be
movl %r14d, %ebx
movq 0x8(%rsp), %rax
addl $0xd, %eax
movl %eax, 0x24(%rsp)
pushq $0x1
popq %rax
movl %eax, %r14d
leaq 0x63(%rsp), %r12
cmpl $0xe, %r14d
je 0xf766
movq %r13, %rbp
movq %r15, %r13
movq %r12, %rdi
leaq 0x41b31(%rip), %rsi     # 0x5117c
leaq 0x4c(%rsp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x21f0
andl $0x0, 0x2c(%rsp)
leaq 0x15(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xe553
movb 0x16(%rsp), %al
movq 0x18(%rsp), %rcx
movb %al, (%rcx)
movq 0x8(%rsp), %rax
addl %r14d, %eax
cmpl (%rsp), %eax
je 0xf76c
incq %rcx
movq %rcx, 0x18(%rsp)
addq $0x4, %r12
incl %r14d
movq %r13, %r15
movq %rbp, %r13
jmp 0xf631
movl %r14d, %ebx
jmp 0xf5bb
movq 0x8(%rsp), %rsi
testl %esi, %esi
je 0xf6cf
movl (%rsp), %edx
leaq 0x408d5(%rip), %rdi     # 0x4ff99
movl 0x4(%rsp), %ecx
xorl %eax, %eax
callq 0x20f0
movsbl %bl, %ebp
movq 0x30(%rsp), %rcx
movb (%rcx), %al
testb %al, %al
je 0xf6e4
incq %rcx
cmpb %al, %bl
jne 0xf6d7
xorl %r12d, %r12d
movl $0x0, %ecx
movq %rcx, 0x8(%rsp)
cmpb %al, %bl
jne 0xf5bb
movq $0x0, 0x8(%rsp)
leaq 0x5c(%rsp), %rdi
leaq 0x47b1d(%rip), %rsi     # 0x5722b
movq %rsp, %rdx
xorl %eax, %eax
callq 0x21f0
movl (%rsp), %ecx
leaq 0x408a2(%rip), %rdi     # 0x4ffc4
movl 0x4(%rsp), %r14d
movl %r14d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
movslq (%rsp), %r12
movq %r12, %rdi
callq 0x21d0
movslq %r14d, %rsi
movq 0x38(%rsp), %rcx
movq %rax, 0x18(%rsp)
movq %rax, (%rcx,%rsi,8)
movq 0x40(%rsp), %rcx
movl %r12d, (%rcx,%rsi,4)
incl %r14d
movl %r14d, 0x4(%rsp)
jmp 0xf61a
movl 0x24(%rsp), %eax
jmp 0xf77a
incq %rcx
movq %rcx, 0x18(%rsp)
movq %r13, %r15
movq %rbp, %r13
pushq $0x1
popq %r12
movq %rax, 0x8(%rsp)
jmp 0xf5bb
movq 0x8(%rsp), %rsi
testl %esi, %esi
movl 0x4(%rsp), %ebx
je 0xf7a8
movl (%rsp), %edx
leaq 0x407fa(%rip), %rdi     # 0x4ff99
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
xorl %eax, %eax
movl 0x28(%rsp), %esi
cmpl %esi, %ebx
je 0xf7de
leaq 0x4082c(%rip), %rdi     # 0x4ffe5
movq 0x30(%rsp), %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
jne 0xf7f0
leaq 0x40851(%rip), %rdi     # 0x50023
callq 0x2090
pushq $-0x1
popq %rax
jmp 0xf7de
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40824(%rip), %rdi     # 0x5001b
callq 0x2090
pushq $0x8
popq %rdi
callq 0x2270