// File: /workspace/github_c_makefile_star2_O1/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, 0x28(%rsp)
movl %edx, %ebx
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
leaq 0x48(%rsp), %rsi
movq %rcx, %rdi
callq 0xe1e8
testq %rax, %rax
je 0x106d0
movq %rax, %r12
movl %ebx, 0x1c(%rsp)
movl $0x0, 0xc(%rsp)
leaq 0x50(%rsp), %rdi
movl $0xc8, %esi
movq %rax, %rdx
callq 0x2170
xorl %ebx, %ebx
testq %rax, %rax
je 0x106d4
cmpl $0x4d4f5441, 0x50(%rsp) # imm = 0x4D4F5441
movl $0x0, 0x8(%rsp)
je 0x106dc
movb $0x2d, %al
movl $0x52514553, %r14d      # imm = 0x52514553
leaq 0x4c(%rsp), %r15
xorl %r13d, %r13d
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movq %r12, 0x40(%rsp)
movl 0x50(%rsp), %ecx
xorl %r14d, %ecx
movzwl 0x54(%rsp), %edx
xorl $0x5345, %edx           # imm = 0x5345
orl %ecx, %edx
je 0x1053a
movl %eax, %ebp
jmp 0x106a7
movb 0x5b(%rsp), %bpl
cmpb %al, %bpl
jne 0x1054b
movl %eax, %ebp
jmp 0x1060d
movl 0x8(%rsp), %esi
testl %esi, %esi
je 0x10567
movl 0xc(%rsp), %edx
leaq 0x45adf(%rip), %rdi     # 0x5603d
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
movsbl %bpl, %ecx
movq 0x28(%rsp), %rax
movb (%rax), %r14b
testb %r14b, %r14b
je 0x10580
incq %rax
cmpb %r14b, %bpl
jne 0x10570
movl $0x0, 0x8(%rsp)
cmpb %r14b, %bpl
jne 0x105f6
leaq 0x5c(%rsp), %rdi
leaq 0x4cd52(%rip), %rsi     # 0x5d2eb
movl %ecx, %r13d
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x21f0
movl 0xc(%rsp), %ecx
leaq 0x45ab5(%rip), %rdi     # 0x56068
movl %ebx, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
movslq 0xc(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x21d0
movq %rax, %r13
movslq %ebx, %rax
movq 0x30(%rsp), %rcx
movq %r13, (%rcx,%rax,8)
movq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rdx
movl %edx, (%rcx,%rax,4)
incl %ebx
movl $0x1, 0x10(%rsp)
jmp 0x105fe
movl $0x0, 0x10(%rsp)
cmpb %r14b, %bpl
movl $0x52514553, %r14d      # imm = 0x52514553
jne 0x106a7
cmpl $0x0, 0x10(%rsp)
je 0x1069f
movl %ebx, 0x20(%rsp)
movl 0x8(%rsp), %ebx
xorl %r12d, %r12d
leaq 0x63(%rsp), %r14
movq %r14, %rdi
leaq 0x46c3a(%rip), %rsi     # 0x5726c
movq %r15, %rdx
xorl %eax, %eax
callq 0x21f0
movl $0x0, 0x24(%rsp)
leaq 0x19(%rsp), %rdi
leaq 0x24(%rsp), %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xef68
movb 0x1a(%rsp), %al
movb %al, (%r13,%r12)
movl %r12d, %eax
leal (%rbx,%rax), %ecx
incl %ecx
incq %r12
cmpl 0xc(%rsp), %ecx
je 0x1067e
addq $0x4, %r14
cmpl $0xc, %eax
jb 0x10628
addq %r12, %r13
addl %r12d, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movl 0x20(%rsp), %ebx
movq 0x40(%rsp), %r12
movl $0x52514553, %r14d      # imm = 0x52514553
jmp 0x106a7
movl $0x0, 0x10(%rsp)
leaq 0x50(%rsp), %rdi
movl $0xc8, %esi
movq %r12, %rdx
callq 0x2170
testq %rax, %rax
je 0x106dc
cmpl $0x4d4f5441, 0x50(%rsp) # imm = 0x4D4F5441
movl %ebp, %eax
jne 0x1051d
jmp 0x106dc
xorl %eax, %eax
jmp 0x1072c
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %esi
testl %esi, %esi
je 0x106f8
movl 0xc(%rsp), %edx
leaq 0x4594e(%rip), %rdi     # 0x5603d
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
xorl %eax, %eax
movl 0x1c(%rsp), %esi
cmpl %esi, %ebx
je 0x1072c
leaq 0x45980(%rip), %rdi     # 0x56089
movq 0x28(%rsp), %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
jne 0x1073e
leaq 0x459a5(%rip), %rdi     # 0x560c7
callq 0x2090
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4597a(%rip), %rdi     # 0x560bf
callq 0x2090
movl $0x8, %edi
callq 0x2270